Find for basic Linux commands

Source: Internet
Author: User

The find command in Linux is very powerful. It can search for files or directories on Hard Disks Based on different parameters. The basic command format is as follows:

Find [path] [Option] [action]

I. Options

1. Time-related parameters

-Atime N: N is a number that indicates the files that have been accessed within one day before n days.

-Ctime N: N is a number that indicates a file that has been changed to the Z state within one day before n days.

-Mtime N: N is a number that indicates a File Modified (modification) within one day before n days.

-Mtime-N + N: N indicates a number, and-N indicates a File Modified within n days. + N indicates a File Modified before n days). Similarly, it applies to-ctime and-atime.

-Newer file: file is an existing file. If it is newer than the file, it will be listed.

2. parameters related to the user or user group name

-Uid n: N is a number. This number is the ID of the user account, that is, uid. This uid is recorded in/etc/passwd and corresponds to the account name.

-Gid N: N is a number, which is the ID of the user group, that is, Gid. This GID is recorded in/etc/group.

-User name: name indicates the user account name. For example, zhangzhiwi

-Group Name: name indicates the user group name. For example, users.

-Nouser: Search for files whose owner is not in/etc/passwd.

-Nogroup: searches for Files Owned by a user group that are not in the/etc/group. Some self-installed software may not have file owners and user groups.

3. parameters related to file permissions and names

-Name filename: searches for files with filename.

-Type typeid: Search for objects whose file type is typeid. Main types include

F common file type

Block B device file type

C-character device file type

D directory type

L connection file content

S socket type

P fifo, MPs queue, and other types.

-Size [+-] filesize: searches for files larger (+) or smaller (-) than filesize. Filesize must have rules. C Indicates byte, and K indicates 1024 bytes.

For example, to search for files larger than 50 K in the current directory: find.-size + 50 K

-Perm mode: searches for objects whose file attribute is "mode. For example,-Perm 755. The file whose property is rwxr-XR-X will be searched.

-Perm-mode: searches for files whose attributes contain all modes. For example, search-Perm-755. The file whose property is rwxrwxrwx (777) will also be searched.

-Perm + mode: searches for files whose attributes contain any mode. For example, search-Perm + 755. The file whose property is rwx ------ (700) will also be searched.

2. Additional operations.

After the find Command finds out files, it is often necessary to process these files, such as deleting or printing them out. In this case, exec or OK must be used with find for processing. The basic commands are as follows:

Find [path] [Option]-exec (-OK) command {}/;

-The difference between exec and-OK is that-exec reminds users that-OK Does not remind users. Followed by the command, followed by a pair of {}, followed by a space, followed by/and;

For example, find all directories named ". SVN" in the current directory and delete it:

Find.-Name. svn-type D-exec Rm-RF {}/;

3. Use xargs.

Xargs is a common command for UNIX and Unix-like operating systems. It is used to convert the parameter list into small segments and pass it to other commands to avoid the problem that the parameter list is too long. He used this command with the grep command to find a file that contains a string in a directory.

Find.-Type F | xargs grep 'mystring '.

 

For more specific usage of the find command, see: http://www.linuxsir.org/main/node/137

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.