Latest web development tutorials

Linux find command

Linux find command

Linux command Daquan Linux command Daquan

Linux find command to find files in the specified directory. Any parameters located before the string will be treated as directory name you want to find. If you use this command does not set any parameters, the find command will find subdirectories and files in the current directory. And will look into all the subdirectories and files are displayed.

grammar

find   path   -option   [   -print ]   [ -exec   -ok   command ]   {} ;

Parameter Description:

Analyzing path and find expression in accordance with the following rules, the first in a command line -! (), before the part of the path, after the expression. If the path is an empty string is using the current path, if the expression is an empty string is used as the default -print expression.

Options expression can be used in as many as twenty or thirty, this only describes the most commonly used parts.

-mount, -xdev: only checks the file and specify a directory in a file system under the same, to avoid listing other documents in the file system

-amin n: n minutes in the past been read

-anewer file: file file is later than the read file.

-atime n: n in the past days by reading the file.

-cmin n: n minutes in the past been modified

-cnewer file: file than the file update file

-ctime n: n in the past days had modified files

-empty: Empty file -gid n or -group name: gid is a group name is the name or n

-ipath p, -path p: p file path name matches, ipath ignores case

-name name, -iname name: file name matches the name of the file. iname ignores case

-size n: n is the file size units, block 512 yuan b represents the group, c represents the number of characters, k represents kilo bytes, w is two bytes. -type c: file type is c file.

d: directory

c: means font file

b: block device file

p: named column reservoir

f: General documents

l: symbolic link

s: socket

-pid n: process id is n file

You can use () the expression separator, and use the following operation.

exp1 -and exp2

! Expr

-not expr

exp1 -or exp2

exp1, exp2

Examples

The current directory and its subdirectories for all file name extension is c files listed.

# find . -name "*.c"

The file lists all current general catalog under its subdirectories

# find . -ftype f

Will present all updated within 20 minutes of most recent files are listed under the directory and its subdirectories

# find . -ctime -20

Find / var / logs directory, change the time before the 7th ordinary files, and ask before deleting them:

$ find /var/logs -type f -mtime +7 -ok rm { } ;

Find the current directory the file owner has read and write permissions, and the file belongs to a user group, and other users have read access file:

$ find . -type f -perm 644 -exec ls -l { } ;

To find all the files in the system of regular file length of 0, and list their full path:

$ find / -type f -size 0 -exec ls -l { } ;

Find / var / logs directory, change the time before the 7th ordinary files, and ask before deleting them:

$ find /var/logs -type f -mtime +7 -ok rm { } ;

Linux command Daquan Linux command Daquan