Linux Find command detailed

Source: Internet
Author: User
Tags file permissions

The Linux Find command searches the directory structure for files and performs the specified actions. Linux Find command provides quite a lot of search conditions, powerful

Find common Command parameters
command options:-name   Find files by file name. -perm   to find files according to file permissions. -user   Search for files according to the owner of the file. -group  finds files according to the group to which the files belong. -mtime-n +n to find files according to the file change Time "-7 7 days +7 7 days ago"-nogroup finds a file that is not in the  genus Group, that is, the group to which the file belongs does not exist in/etc/groups. -nouser finds the invalid owner of the file, that is  , the owner of the file does not exist in the/etc/passwd. -newer file1! File2 look for a file that changes time than the file File1 new but older than the file file2. -type  Find files 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 file lengths of n blocks, with C for file lengths in bytes. -depth: When looking for a file, first find the file in the current directory, and then look in its subdirectories. -follow: If the find command encounters a symbolic link file, it tracks to the file that the link points to. In addition, the following three differences:-amin n    Find the last n minutes of access to the file in the system-atime N   find the last n*24 hour Access file in the system-cmin N Find the file    in the last n minutes of the system changed file status-ctime N   find the last n*24 hour in the system file status changed file-mmin n    find the last n minutes in the system file data changed file-mtime n   find the last n*24 hours in the system file data changed file
Common Command Display

Delete all files under directory

find/tmp/-type f-exec rm-rf {} \;find/tmp/-type F | Xargs RM-RF

View information for all files under the current path:

find/tmp/-type F! -name a |xargs rm–rffind./-type f-exec file {} \;

Find files that have been modified within a specified time

Find files by directory or file permissions

Find/opt-perm 777

Find files by size

Find/-size +10m  |sort "Finding files larger than 10M" Find/-size-10m  |sort "Finding files less than 10M" Find/-size 10M   |sort  "Find 10M Files"

Find all files in the test directory that are not within the TEST4 subdirectory

Find./test-path "Test/test4"-prune-o-print "You can use the-prune option to indicate which directories need to be ignored. Be careful when using the-prune option, because if you use the-depth option at the same time, the-prune option will be ignored by the Find command "

Find a new file than Yum.log but not more than hhh.txt

[[email protected] ftl]# Find/newer/var/log/yum.log! -newer./hhh.txt

Find the change time in a new file than the Log2012.log file

Find./-newer Log2012.log

Find files with file lengths greater than 1 m bytes in the current directory

Find./-size +1000000c–printfind./–size +1m-print

Look for files with a file length of exactly 100 bytes in the/home/apache directory :

Find/home/apache-size 100c-print

Find files that are longer than 10 blocks in the current directory

Find. -size 10-print
The exec/ok/of the Find command Print

The ls-l command is placed in the-exec option of the Find command

Find. -type f-exec ls-l {} \; "{}   curly braces represent the file name found in the previous find"

Find files in the directory that change time before n days and delete them

Find./-mtime +10-exec rm {} \;

Find files that change time before n days in the directory and delete them, giving hints before deleting them

Find/-mtime +1-a-name "*.log"-type f-ok cp {}/TMP/FTL \; "-ok is safe mode, root exec effect is the same as"

Using the grep command in-exec

Find/etc-name "passwd*"-exec grep "root" {} \; "Filter File Contents"

Find files move to the specified directory

Find. -name "*.log"-exec mv {}.. \;

Execute the CP command with the EXEC option

Find. -name "*.log"-exec cp {} test3 \;

Find commandofXargs

Linux xargs Command Detailed

Https://www.cnblogs.com/ftl1012/p/9250438.html

Linux Find command detailed

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.