Find command, find

Source: Internet
Author: User

Find command, find
The find command is one of the most commonly used commands. Here are some common usage summaries.

1. Search by file name.
Search for all files ending with txt in the current directory. The second command uses the-exec parameter. You can execute an operation on all the files to be searched. Note the format, space, and;No fewer than one. -The name parameter can be a regular expression, for example, the second example.

find ./* -name "*.txt"find ./* -name "[ab]*.py"find ./* -name "*.pyc" -exec rm {} \; 

2. Search by modification time
Find the files modified on the current day in the current directory. -1 indicates the File Modified one day ago. -2 indicates the previous two days.find ./* -mtime nN indicates that the last modification to the file data is before n * 24 hours. + N refers to n days ago,-n refers to n days or less (-mmin refers to n minutes), and n indicates the nth day. Their meanings are different.

find ./* -mtime  60 -type f -print find ./* -mmin -60 -type f -printfind ./* -mmin +60 -type f -print

3. File status change
The basic principle is the same as that of the previous parameter, except that the File Permission is modified. The permission to modify the content is different from the permission to change the file. Here, the permission to change the inode data of the file, such as the File Permission and owner information. Cmin indicates that the permission has been changed in the last 60 minutes, and ctime indicates that the permission has been modified in the last few days.

find ./* -cmin +60 -type f -printfind ./* -ctime -60 -type f -print

4
Search by file group and user-userAnd-nouserThe Last Command finds all the files of the System user that has been deleted,- groupAnd- nogroup.

find ./* -user foxfind ./* -nouser 

5
Find avoids a directory and avoids multiple directories. Where-a indicates and, and-o indicates or.

find test -path "test/test4" -prune -o -printfind test \( -path test/test4 -o -path test/test3 \) -prune -o -print find . \( -path ./modules -o -path ./framework -o -path ./utils -o -path ./config \) -prune -o -name "Bigger.*" -print

6
-permOption indicates the object access permission.

find -perm 755 -print

7
Utility inode to find the file number. The inode number can be specified in the find command as shown below. Here, the find command renames a file with an inode number. You can also use rm to delete the special file.

ls -i1 test*16187429 test-file-name16187430 test-file-namefind -inum 16187430 -exec mv {} new-test-file-name \;

8
Find the maximum five files in the current directory

find . -type f -exec ls -s {} \; | sort -n -r | head -5

9
The following command deletes the *. zip file larger than MB.

find / -type f -name *.zip -size +100M -exec rm -i {} \;

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.