Linux-find Common instruction usage examples

Source: Internet
Author: User

The Linux Find command searches the directory structure for files and performs the specified actions. The Linux Find command provides quite a lot of search criteria and is powerful. Because find has a strong DA feature, it has a lot of options, and most of the options are worth taking the time to look at. Even if the system contains a network file system (NFS), the Find command works equally well in the file system, and you only have the appropriate permissions. When running a find command that consumes resources, many people tend to put it in the background because it can take a lot of time to traverse a large file system (this refers to a file system with more than 30G bytes).

1. Command format: Find Pathname-options [-print-exec-ok ...]

2. Command function: Used to locate files in the file tree and make corresponding processing (possibly accessing the disk)

3. Command arguments: The directory path that the Pathname:find command looks for. For example, use. To represent the current directory, with/to represent the system root directory.

The-print:find command outputs the matched file to 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 the parameter is executed in a more secure mode, prompting the user to determine whether to execute before executing each command.

4. Command options:
-name finds files by file name.

-perm to find files according to file permissions.

-prune Use this option to have the Find command not be found in the currently specified directory, and if you use the-depth option at the same time,-prune will be ignored by the Find command.
If you want to print files other than test.c in the current directory (/home/admin/code):

#按文件属主来查找

#按所属组来查找

-nogroup finds a file that does not have a valid owning group, that is, the group to which the file belongs does not exist in/etc/groups.

-nouser finds a file without a valid owner, that is, the owner of the file does not exist in the/etc/passwd.

-mtime-n +n The file changes 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, but they are all the same as the-m time option.
View files that have been changed in the last two days

-newer file1! File2 look for a file that changes time than the file File1 new but older than the file file2.

-type find a file of a certain type, such as:
B-block device files.

D-Directory.

C-character device file.

P-Pipeline file.

L-Symbolic link file.

F-Normal file.

-size N: [C] finds 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 catalog and then look it up in its next directory.

-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 this system.
-mount: Does not cross the file system mount point 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 the tape device.

1. In the/code directory, look for files that changed 5 days ago and delete them:

2. Linux using the Find command to find File size xx file method
For example: A file of 5556 bytes can be written like this
Find/root-size-5557c-size +5555c-exec ls-ld {} \;

Find/root-size-500k-size +50k-exec ls-ld {} \;





















Linux-find Common instruction usage examples

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.