Linux command locate, find search command

Source: Internet
Author: User

Linux command locate, find search command

The locate command is used to find files that are faster than the search command, and it has a database, which is a daily routine work (crontab) program that executes UpdateDB. Run: UpdateDB generate slocate.db Database under/var/lib/slocate/to find it quickly.

Example: Field copy/etc/grub2.cfg to/tmp/grub2.cfg, if you do not update the database, locate search Grub2.cfg is unable to search/tmp/under Grub2.cfg

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/8B/wKioL1XmkKOhD7vZAAEshp4kMqs468.jpg "title=" Figure 20.jpg "alt=" Wkiol1xmkkohd7vzaaeshp4kmqs468.jpg "/>

Find syntax: Find Pathname-options [-print-exec-ok ...]

Common parameter options:

The directory path that the Pathname:find command looks for. Use. To represent the current directory, with/to represent the system root directory

-regex "pattern": matches the entire file path string with pattern, not just the file name

The-print:find command outputs the matched file to the standard output

The-exec:find command executes the shell command given by the parameter to the matching file. The corresponding command is in the form of ' command ' {}; Note the space between {} and;

-ok: The same as-exec, except that the shell command given by this parameter is executed in a more secure mode, and before each command is executed, a prompt is given to let the user determine whether to execute

-name: Search by file name, support using globbing;-iname: Case insensitive, support for using globbing

-perm: Search by file permissions

-user: Search by file Owner

-group: Find by file group

-uid UserID: Find files for the owner-specified UID of a file

-gid GroupID: Find file of genus group specify GID files

-mtime:-n, +n, by file change time to find the file,-n means that the file change time is now less than n days, + n means that the file change time is now N days ago. The Find command also has the-atime and-ctime options

-nogroup: Finds the file for which the group is not valid, that is, the group to which the file belongs does not exist in/etc/groups.

-nouser: Finds invalid owner file, that is, the owner of the file does not exist in the/etc/passwd.

-newer:file1! FILE2, look for files that change time than files FILE1 new but older than files LIFE2.

-type: Find a file of a certain type, such as: B: Block device file; d: directory; C: Character device file; P: Pipeline file. L: Symbolic link file; F: normal file

-size N:[c] Find files with a file length of n blocks, with C indicating the length of the file in bytes

-depth: When looking for a file, first find the file in the current directory, and then look in its subdirectories

-fstype: Find files located in a file system of a certain type, these file system types can usually be found in the configuration file/etc/fstab, which contains information about the file system in the system

-mount: Do not cross file system mount points when locating files

-follow: If the find command encounters a symbolic link file, it tracks to the file that the link points to

-cpio: Use the cpio command for matching files to back up these files to a tape device

-amin N: Find the last n minutes of accessed files

-atime N: Find last n*24 hours of access to files

-cmin N: Find file with the last N minutes changed file status

-ctime N: Find file with last n*24 hour changed file status

-mmin N: Find file with the last n minutes changed file data

-mtime N: Find files that have changed file data for the last n*24 hours


This command supports finding compound conditions consisting of the conditional logical operator not, and, or. The meaning of the logical operator and, or, is:

And: Logic and, in the command with "-a" means, is the system default option, indicating that only when the given conditions are satisfied, the search condition is satisfied

Or: Logical OR, denoted by "-O" in the command. The operator means that if one of the given conditions is satisfied, the search condition satisfies

Not: Logical not, in command "! Said This operator indicates that a file is found that does not meet the given criteria

! A-o! B =! (A-a B)

! A-a! B =! (A-o B)

Example:

1, find the/var directory is the owner of the root, and belong to the group mail all files;

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/8B/wKioL1XmkIzSFG4oAAM332QF-hw811.jpg "title=" Figure 21.jpg "alt=" Wkiol1xmkizsfg4oaam332qf-hw811.jpg "/>

2. Find all files that are not root, bin or hadoop under the/usr directory;

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/8F/wKiom1XmjpfyfnsxAAEa6eSb7Mw516.jpg "title=" Figure 22.jpg "alt=" Wkiom1xmjpfyfnsxaaea6esb7mw516.jpg "/>

3. Find all files whose contents have been modified and are not root or Hadoop for the last week in/etc directory;

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/8B/wKioL1XmkMmzloLJAAMLffbKTt8687.jpg "title=" Figure 23.jpg "alt=" Wkiol1xmkmmzloljaamlffbktt8687.jpg "/>

4. Find all files on the current system that are not owned by the master or group, and have been visited in the last week;

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/8F/wKiom1XmjrrAE_A_AAHF8-wzkOw355.jpg "title=" Figure 24.jpg "alt=" Wkiom1xmjrrae_a_aahf8-wzkow355.jpg "/>

5. Find all files of more than 20k and type common in/etc directory;

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/8F/wKiom1Xmjs7z3GRcAAtGabsTnrE706.jpg "title=" Figure 25.jpg "alt=" Wkiom1xmjs7z3grcaatgabstnre706.jpg "/>

6, look for all the users in/etc directory do not have permission to write files;

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/8B/wKioL1XmkQLy1MfJAACTJem5epc539.jpg "title=" Figure 26.jpg "alt=" Wkiol1xmkqly1mfjaactjem5epc539.jpg "/>

7. Find at least one class of users who do not have permission to execute files in/etc directory;

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/8F/wKiom1XmjvWy0NHWAAVRxKq6Pyw220.jpg "title=" Figure 27.jpg "alt=" Wkiom1xmjvwy0nhwaavrxkq6pyw220.jpg "/>

8, find/etc/init.d directory, all users have execute permission, and other users have write permission files;

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/8B/wKioL1XmkSrykVZcAAbuE1lSww0758.jpg "title=" Figure 28.jpg "alt=" Wkiol1xmksrykvzcaabue1lsww0758.jpg "/>


This article is from the "10,000-hour Law" blog, be sure to keep this source http://daisywei.blog.51cto.com/7837970/1690782

Linux command locate, find search command

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.