Common Linux commands (1): find, linuxfind
1. Command Format
Find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [expression]
2. command functions
Search for and process files at the file directory level
3. Command Options
-Name finename
Search for files by file name. Wildcards can be used for file names.
-Perm mode
Search for files by File Permission
-Type c
Search for files by file type. The file type is as follows:
B-block Device Files
C-character Device File
D-directory file
P-MPs queue File
F-Common File
L-Symbolic Link file
S-socket File
-Size [+/-] n [cwbkMG]
Query files by file size. + n indicates that the file size is greater than n, and-n indicates that the file size is smaller than n.
The file size unit is as follows:
'B' 512-byte Block
'C' byte Unit
Unit of 'W'
'K' KB (210 bytes)
'M' MB (220 bytes)
'G' GB (230 bytes)
-Gid n
Search for files by file group ID
-Group gname
Search for files by file group name or the file group ID
-Uid n
Search for files by file owner ID
-User uname
Search for the file by file owner name or the ID of the available file owner
-Amin n
Search for files accessed in the last n minutes
-Atime n
Search for objects that have been accessed in the last n * 24 hours
-Cmin n
Find the file whose status is changed in the last n minutes
-Ctime n
Find the file whose status is changed in the last n * 24 hours
-Mmin n
Find the file whose data has been modified in the last n minutes
-Mtime n
Find the file whose data has been modified in the last n * 24 hours
-Newer file
Search for files whose modification time is later than file
-Anewer file
Search for new files with a time ratio of file access to files
-Cnewer file
The time when the file status changes is found to be greater than the time when the file status changes.
The corresponding action after the file is found:
-Delete
Delete the found File
-Exec command {}\;
Run the specified command on the searched file. There must be a space between {} And \;, and '\' is an escape character
-OK command {}\;
The usage is the same as exec, but it will be confirmed before executing the command
-Print
Output files to standard output
-Printf format
Output The searched file to the standard output according to the format.
4. Instance
Instance 1: Find the specified file in the current directory
[martin@localhost perl]$ find . -name "*.pl"./ex3/ex3-1.pl./ex3/ex3-3.pl./ex3/ex3-2.pl./ex4/ex4-1.pl
Instance 2: find common files in the current directory
[martin@localhost perl]$ find . -type f./ex3/3-1.txt./ex3/3-3.txt./ex3/ex3-1.pl./ex3/ex3-3.pl./ex3/ex3-2.pl./ex3/3-2.txt
Instance 3: The file search permission is 775 and the file size exceeds bytes.
[martin@localhost change]$ find . -perm 775 -size +4000c ./dos2unix.pl./test.pl./space2tab.pl
Instance 4: backup the file found
[martin@localhost data]$ lltotal 8-rw-rw-r--. 1 martin martin 7514 Aug 16 23:58 in4_G_002_224001_12345667789.s[martin@localhost data]$ find . -name "*.s" -exec cp {} {}.old \;[martin@localhost data]$ lltotal 16-rw-rw-r--. 1 martin martin 7514 Aug 16 23:58 in4_G_002_224001_12345667789.s-rw-rw-r--. 1 martin martin 7514 Nov 12 15:48 in4_G_002_224001_12345667789.s.old
Instance 5: Confirm before deleting the found File
[martin@localhost data]$ find . -name "*.old" -ok rm {} \;< rm ... ./in4_G_002_224001_12345667789.s.old > ? y
Common Linux commands: directories