In Linux find looks for command usage details

  • 2020-05-27 08:01:41
  • OfStack

There are two commands to find files under Linux, locate and find.

locate instructions and the file find to find similar, but locate is through update program will all the files and directories in the hard disk data to build an index database, when performing loacte directly find the index, query speed will be faster, 1 index database is managed by the operating system, but also can directly give update force system immediately modify the index database. Briefly describe its two options.

#locate

-i // is not case sensitive when looking for files such as: locate, i, passwd

-n // displays only the first N line of the search result, e.g. locate-n 5 passwd

Under Linux, the find command searches the directory structure for files and performs the specified action. The find command under Linux provides quite a number of lookup criteria, which are quite powerful. Because of its powerful capabilities, find has a wide range of options, most of which are worth taking the time to understand. Even if the system contains the network file system (NFS), the find command is still valid on that file system, and only if you have the appropriate permissions. When running a very resource-intensive find command, many people prefer to execute it in the background because it can take a long time to traverse a large file system (in this case, a file system of 30G bytes or more).

find: find [specify lookup directory] [lookup rules] [action executed after lookup]

find iterates through the entire system without specifying a lookup directory

find command details

Find files


find ./ -type f

Find the directory


find ./ -type d

Look for a file or directory with the name test


find ./ -name test

Look for files with names that match the regular expression, and note the '.*' in front (the found file has a directory)


find ./ -regex .*so.*\.gz

Find the directory and list the files in it (execute the ls command separately for each directory found, the first line of the file list will not display the directory name without the option -print)


find ./ -type d -print -exec ls {} \;

Find the directory and list the files in it (execute the ls command separately for each directory found, please confirm before executing the command)


find ./ -type d -ok ls {} \;

Find the directory and list the files in it (add the found directory to the ls command once, and if the parameter is too long, it will be executed more than once)


find ./ -type d -exec ls {} +

Look for a file name matching *.c


find ./ -name \*.c

After printing the test file name, print the contents of the test file


find ./ -name test -print -exec cat {} \;

Do not print the test file name, just the contents of the test file


find ./ -name test -exec cat {} \;

Look for files that were updated within 2 days of the present time


find ./ -type d
0

Look for files that are updated more than two days from the present time


find ./ -mtime +2

Look for files that are updated within 1 or 2 days from the present time


find ./ -mtime 2

Look for files that are updated within 2 minutes of the present time


find ./ -type d
3

Look for files that are updated at least 2 minutes from the present time


find ./ -type d
4

Look for files that have been updated within 1 minute or 2 minutes of the present time


find ./ -type d
5

Find the file update time for a new file than the content update time of file abc


find ./ -type d
6

Find a new file whose access time is newer than the content of file abc


find ./ -anewer abc

Find an empty file or directory


find ./ -empty

Find an empty file and delete it


find ./ -type d
9

Find files or directories with 644 permissions (full compliance)


find ./ -perm 664

Look for a file or directory where the user/group has read and write permissions and other users have read (other permissions are not limited)


find ./ -perm -664

Look for files or directories where users have write permissions or where group users have write permissions


find ./ -perm /220
find ./ -perm /u+w,g+w
find ./ -perm /u=w,g=w

Find a directory or file that has read rights for owner rights


find ./ -perm -u=r

Look for a directory or file where user group permissions have read permissions


find ./ -perm -g=r

Look for directories or files where other users have read permissions


find ./ -perm -o=r

Find the file or directory whose owner is lzj


find ./ -user lzj

Find a file or directory with the group name gname


find ./ -group gname

Find the file for the user ID that does not exist in the file


find ./ -nouser

Find a file that does not exist in the file group ID


find ./ -nogroup

Look for files that have execute permissions but no readable permissions


find ./ -executable \! -readable

Find a file or directory with file size less than 10 bytes


find ./ -size -10c

Find the file size equal to 10 bytes in a file or directory


find ./ -size 10c

Find a file or directory with size greater than 10 bytes


find ./ -size +10c

Look for files or directories where the file size is less than 10k


find ./ -size -10k

Find files or directories with files size less than 10M


find ./ -size -10M

Find files or directories with size less than 10G


find ./ -size -10G

Related articles: