8.8 "Learning Linux is not difficult" Linux common operation commands (8): find command to find qualified files
Use the find command to list the qualified files in the file system. You can specify a combination of different information such as file name, category, time, size, and permissions. Only the exactly matching files will be listed.
Command syntax:
find [ path ] [ options ]
The meaning of each option in the command is shown in the table.
Options |
Meaning of options |
-name < filename > |
Find files by file name |
-perm < permission > |
Find files by their permissions |
-user < username > |
Find files by their user owner |
-group < group name > |
Find files by their group owner |
-atime n |
Files that have been accessed ( atime ) in the past n days, where n is a number |
-amin |
Files that have been accessed ( atime ) in the past n minutes , where n is a number |
-ctime n |
Files that have been changed ( ctime ) in the past n days, where n is a number |
-cmin n |
Files that have been changed ( ctime ) in the past n minutes , where n is a number |
-mtime n |
Files that have been modified ( mtime ) in the past n days, where n is a number |
-mmin n |
Files that have been modified ( mtime ) in the past n minutes , where n is a number |
-size n[ckMG] |
Find files of size n , where n is number, c is bytes, k is KB , M is MB , G is GB |
-empty |
Find empty files, which can be normal files or directories |
-type < file type > |
Find files by file type |
-fstype < filesystem type > |
Find files by specified file system type |
-uid < user UID> |
Find a file by the UID of the file's user owner |
-gid < group GID> |
Find files by their group owner's GID |
-inum n |
Find a file by its inode number |
-writable |
match writable files |
Different file types can be defined when looking for files, as shown in the table.
character |
meaning |
b |
block device file |
d |
content |
c |
character device file |
p |
pipe file |
l |
symlink file |
f |
normal file |
s |
socket file |
Example: Find the boot menu configuration file grub.cfg in the /boot directory .
[root@rhel ~]# find /boot -name grub.cfg
Example: Find all files with the extension ".conf" in the "/" directory .
[root@rhel ~]# find / -name '*.conf'
Example: List all files in the current directory and its subdirectories that have been changed in the last 20 days.
[root@rhel ~]# find . -ctime -20
Example: Find files whose file type is directory in the /boot directory.
[root@rhel ~]# find /boot -type d
本文节选自《Linux学习并不难》教材,这是一本最实用的、理论实践并重的Linux入门教材。如需阅览整本书的内容请访问Linux运维者(www.linuxywz.com)网站。