Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Linux command find     - CentOS7 installation performance monitoring system (Server)

- Laravel 4.2 Laravel5 comprehensive upgrade Raiders (Server)

- ctop: monitor container performance Linux command line artifact (Linux)

- Web server security policy (Linux)

- OpenStack image production in the CentOS 6.2 (Linux)

- Install Firefox 28 on Ubuntu, Linux Mint (Linux)

- SHELL script to use anti SSH brute force and vsftpd (Linux)

- Use virt-manager to create and manage virtual machines (Linux)

- Java keyword final, static (Programming)

- Ubuntu 14.04 after the restart the default maximum screen brightness solutions (Linux)

- Python 2.7 installed on CentOS 6.5 (Linux)

- Java8 Lambda expressions and flow operations (Programming)

- Database start listening TNS-12537, TNS-12560 error (Database)

- Ubuntu install driver manager Mint Driver Manager and Device Driver Manager (Linux)

- CentOS6.3 build a Python 3.3 environment to access Oracle 11gR2 (Database)

- Linux loopback adapter Driven Design (Programming)

- How to contribute code on GitHub uploads (Linux)

- Linux (RHEL6 CENTOS6 OLE6) VNC-SERVER Installation and Configuration (Server)

- CentOS 7 How to install MySQL Server (Database)

- Magical Virtualbox under Ubuntu (Linux)

 
         
  Linux command find
     
  Add Date : 2018-11-21      
         
       
         
  Overview: When using a file system in Linux, there is often a need to find this file. So how in accordance with our needs to find the appropriate file. Here I recommend two commands, locate and find commands command. Cipian Bowen mainly to introduce the find command usage.

So why do not talk about the find and locate commands? Here, I need to explain the working mechanism of these two commands.

A, locate command mechanism

In linux system in advance to build a good database for file index to locate the query to meet the user needs to find files. This database is automatically maintained and updated by a Linux system. So this is not a real-time look, for example, when you use the process created a new document, and worked for a while you forget that this document specifically where lying, you want to find this file, then you need to find, if locate to find it, when the database is not updated in real time. Of course, you can also use the updatedb command to manually update the database system, but the cost of updating the database is relatively large, the system will increase consumption. At this point, we recommend to find another command --find command.

Two, find the command mechanism

find command is a Linux system in a real-time tool to find the file, which is specified by the user to traverse the path starting at the file system hierarchy to find the complete file, which you specify to find all files and subdirectories under the directory files.

Three operating characteristics, find command

1. Find a slightly slower.

2, precise search.

3, real-time search.

Four, find command usage

Using the format: find [OPTIONS] [Find Start Path] [search condition] [processing operation]

Find start path: Specify the starting destination specific search path; defaults to the current directory.

Search Terms: user-specified search criteria (expression), such as the file name of the file, size, type, slave

Relations, authority, etc; if not specified, to find all the files in the current directory.

Actions: to meet the search criteria to make operations such as delete and other processing operations; if not specified, the default is lost

Out to the standard output.

Search Terms specification:

Expression: options and test

1, the test: The result is Boolean ( "true", "false")

(1) based on the file name to find:

Options:

-name "pattern": pattern matching is based on the file name to find out.

-iname "pattern": pattern matching is based on the file name to find out. Ignore character large

lower case.

Note: This pattern (pattern) is based on the globbing style bash to find.

-regex "pattern": based on regular expression pattern to find the file, matching the entire path

Instead of a file name.

(2) to find files based on affiliation

Options:

-user USERNAME: Find files belonging to the specified user

-group GROUPNAME: Find files belonging to the specified user group

-uid UID: find the owner of all files specified UID

-gid GID: Find the specified GID is a group of all files

-nouser: Finding no owner files

-nogroup: Finding no document is set

Note: After being deleted for a particular user, the user's files belonging to the genus will become free

Lord, no is a group of files, the file belonging to the previous user ID and group ID for this user.

(3) according to the type of file to find.

Options:

-type TYPE:

f: regular file

d: directory file

l: symbolic link file

b: block device file

c: character device file

p: pipe file

s: socket file

(4) According to locate the file size

Options:

-size [+ | -] NUMBER default unit in bytes

[+ | -] NUMBER K

[+ | -] NUMBER M

[+ | -] NUMBER G

Note: + means greater than - less than represented, said no precise

Note: 1, precise means (NUMER-1, NUMBER] range, than it can not be too small, not larger than it.

2 - greater than the range [0, # - 1], ie, it is smaller than the size of 1 or less.

3, the range is greater than .

(5) based on timestamp Find:

Options:

In "day" as a unit, rewind to the last time.

-atime [+ | -] NUMBER: access time

NUMBER (exact time): [NUMBER, NUMBER-1]

-NUMBER (Recently NUMBER days): (NUMBER, 0)

+ NUMBER (more than NUMBER days): (oo, NUMBER-1)

-mtime [+ | -] NUMBER: Modified (file contents)

-ctime [+ | -] NUMBER: change the time (metadata)

In "minutes" for the unit: (and the similar)

-amin [+ | -] NUMBER

-mmin [+ | -] NUMBER

-cmin [+ | -] NUMBER

For example: Find / etc directory within the last week its contents modified files

~] # Find / etc / -mtime -7

(6) under the authority of Find

Options:

-perm [/ | -] mode

mode: Exact Match permissions:

-mode: All users (u, g, o) the permission of each and every (r, w,

x) that is qualified to meet the search criteria, the "and" between 9 permissions.

/ Mode: any of a class of users (u, g, o) the authority in any one of (r, w,

x) compliance with the conditions is met (9 have to comply with a) 9 authority is "or" relationship.

For example: 1, Find / etc / directory, for at least one class of user has permission to execute the file.

~] # Find / etc / -perm / 111

2. Find /etc/init.d directory, all users have execute permissions and other users

Write access to common files.

~] # Find /etc/init.d/ -perm -113 -type f

~] # Find /etc/init.d/ -perm -222 -a -perm 002 -type f

2. The composition test:

And (and): - a, default logical combination of a plurality of conditions

Or (or): - o

Non-: -not

For example: 1, Find / etc directory more than a week of its contents have been modified, and the file size does not exceed 5M.

~] # Find / etc / -mtime -7 -a -not -size -5M

2. Find / etc directory of all users do not have write access to common files.

Ideas: reverse lookup problem means there is at least one type of user has write access;

~] # Find / etc / -not -perm / 222 -type f

3, Find / etc directory there is at least one class of users do not have write access to common files.

Ideas: Reverse resolve problems means that all users have write access

~] # Find / etc / -not -perm -222 -type f

Actions:

-print: to standard output, the default action

-ls: details "ls -l" command, the output file is similar to the implementation of the lookup file

-delete: Delete files found

-file file path: Save the long form information to find all the files to the specified file;

-ok COMMAND {} \;: Run by the COMMAND represented on to find every file; each operation had

Confirmation by the user;

-exec COMMAND {} \;: to find every file Run by the COMMAND represented.

Note: find the file path passed to find the back of the commands transmitted to achieve find all the matching files path

Diameter, and a pass to the back of the command; but some commands can not accept long arguments, then the command will be executed

Failure; Another way to avoid this problem:

~] # Find | xargs COMMAND

Summary: Find a combination of numerous options and conditions find command can better serve the needs of users to find the file services, but depending on the size and scope of the time stamp component requires a deep understanding of file size, in order to find you meet you document demand. Also understand the permissions section is also very important, it is easy for beginners around the halo, it is recommended to view the file permissions related to the underlying content. Let you use the Linux find command to become a weapon.
     
         
       
         
  More:      
 
- Android will save the picture to see the album and timely (Programming)
- Linux script to copy the folder to all folders with the same name (Linux)
- Google open source TCP team repaired the Linux kernel TCP flaw (Linux)
- Linux Demo dd IO test (Linux)
- Oracle 11g statistics collection - collection of multi-column statistics (Database)
- The headers for the current running kernel were not found when VirtualBox installation enhancements (Linux)
- Teach you to diagnose problems with strace (Linux)
- Memcached distributed caching (Server)
- How x2go set up Remote Desktop on Linux (Linux)
- OpenSUSE GPG Comments (Linux)
- How to use jgit to manage Git submodule (Linux)
- Android using SVG vector graphics to create cool animation effects (Programming)
- The Linux role of each directory contents (Linux)
- About Hibernate cache, you want the latest data have trouble even session.clear (Database)
- Linux file permissions bit forced bits and adventure Comments (Linux)
- Linux system with a firewall to prevent the DOS attack (Linux)
- Example of use WebSocket (Programming)
- SSH mutual trust configuration (Server)
- Oracle RMAN repair logical bad blocks (Database)
- Oracle database online redo logs are several methods of recovery of deleted (Database)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.