Home >Operation and Maintenance >Linux Operation and Maintenance >What is the linux file query command?
The Linux file query command is the "find" command. This command is used to find files in the specified directory. Any string before the parameter will be regarded as the directory name to be found; if you use this command , without setting any parameters, the find command will search for subdirectories and files in the current directory, and display all found subdirectories and files.
#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.
What is the Linux file query command?
find.
The Linux find command is used to find files in the specified directory. Any string preceding the parameter will be treated as the name of the directory to be searched. If you use this command without setting any parameters, the find command will search for subdirectories and files in the current directory. And all found subdirectories and files will be displayed.
Syntax
find path -option [ -print ] [ -exec -ok command ] {} \;
Parameter description:
find determines path and expression according to the following rules. The first one on the command line - (), the part before ! is path. , followed by expression. If path is an empty string, the current path is used. If expression is an empty string, -print is used as the default expression. There are as many as twenty or thirty options that can be used in
expression. Only the most commonly used ones are introduced here.
-mount, -xdev : 只检查和指定目录在同一个文件系统下的文件,避免列出其它文件系统中的文件 -amin n : 在过去 n 分钟内被读取过 -anewer file : 比文件 file 更晚被读取过的文件 -atime n : 在过去 n 天内被读取过的文件 -cmin n : 在过去 n 分钟内被修改过 -cnewer file :比文件 file 更新的文件 -ctime n : 在过去 n 天内创建的文件 -mtime n : 在过去 n 天内修改过的文件 -empty : 空的文件-gid n or -group name : gid 是 n 或是 group 名称是 name -ipath p, -path p : 路径名称符合 p 的文件,ipath 会忽略大小写 -name name, -iname name : 文件名称符合 name 的文件。iname 会忽略大小写 -size n : 文件大小 是 n 单位,b 代表 512 位元组的区块,c 表示字元数,k 表示 kilo bytes,w 是二个位元组。 -type c : 文件类型是 c 的文件。 d: 目录 c: 字型装置文件 b: 区块装置文件 p: 具名贮列 f: 一般文件 l: 符号连结 s: socket -pid n : process id 是 n 的文件
You can use ( ) to separate expressions and use the following operations.
exp1 -and exp2 ! expr -not expr exp1 -or exp2 exp1, exp2
Example
List all files with .c suffix in the current directory and its subdirectories:
# find . -name "*.c"
List all files in the current directory and its subdirectories File list:
# find . -type f
List all files in the current directory and its subdirectories that have been updated in the last 20 days:
# find . -ctime 20
Find the change time in the /var/log directory 7 days ago Ordinary files and ask them before deleting:
# find /var/log -type f -mtime +7 -ok rm {} \;
Find files in the current directory for which the owner of the file has read and write permissions, and the user in the group to which the file belongs and other users have read permissions:
# find . -type f -perm 644 -exec ls -l {} \;
Find all ordinary files with a file length of 0 in the system and list their full paths:
# find / -type f -size 0 -exec ls -l {} \;
Recommended learning: "Linux Video Tutorial"
The above is the detailed content of What is the linux file query command?. For more information, please follow other related articles on the PHP Chinese website!