find and use xargs

1. Introduction Parameters

pathname: find命令所查找的目录路径。例如用.来表示当前目录,用/来表示系统根目录。
-print: find命令将匹配的文件输出到标准输出。
-exec: find命令对匹配的文件执行该参数所给出的shell命令。相应命令的形式为'command' { } \;,注意{ }和\;之间的空格。
-ok: 和-exec的作用相同,只不过以一种更为安全的模式来执行该参数所给出的shell命令,在执行每一个命令之前,都会给出提示,让用户来确定是否执行。

#-print 将查找到的文件输出到标准输出
#-exec   command   {} \;      —–将查到的文件执行command操作,{} 和 \;之间有空格
#-ok 和-exec相同,只不过在操作前要询用户
-name   filename             #查找名为filename的文件
-perm                        #按执行权限来查找
-user    username             #按文件属主来查找
-group groupname            #按组来查找
-mtime   -n +n                #按文件更改时间来查找文件,-n指n天以内,+n指n天以前
-atime    -n +n               #按文件访问时间来查GIN: 0px">

-ctime    -n +n              #按文件创建时间来查找文件,-n指n天以内,+n指n天以前

-nogroup                     #查无有效属组的文件,即文件的属组在/etc/groups中不存在

-nouser                     #查无有效属主的文件,即文件的属主在/etc/passwd中不存
-newer   f1 !f2              找文件,-n指n天以内,+n指n天以前 
-ctime    -n +n               #按文件创建时间来查找文件,-n指n天以内,+n指n天以前 
-nogroup                     #查无有效属组的文件,即文件的属组在/etc/groups中不存在
-nouser                      #查无有效属主的文件,即文件的属主在/etc/passwd中不存
-newer   f1 !f2               #查更改时间比f1新但比f2旧的文件
-type    b/d/c/p/l/f         #查是块设备、目录、字符设备、管道、符号链接、普通文件
-size      n[c]               #查长度为n块[或n字节]的文件
-depth                       #使查找在进入子目录前先行查找完本目录
-fstype                     #查更改时间比f1新但比f2旧的文件
-type    b/d/c/p/l/f         #查是块设备、目录、字符设备、管道、符号链接、普通文件
-size      n[c]               #查长度为n块[或n字节]的文件
-depth                       #使查找在进入子目录前先行查找完本目录
-fstype                      #查位于某一类型文件系统中的文件,这些文件系统类型通常可 在/etc/fstab中找到
-mount                       #查文件时不跨越文件系统mount点
-follow                      #如果遇到符号链接文件,就跟踪链接所指的文件
-cpio                %;      #查位于某一类型文件系统中的文件,这些文件系统类型通常可 在/etc/fstab中找到
-mount                       #查文件时不跨越文件系统mount点
-follow                      #如果遇到符号链接文件,就跟踪链接所指的文件
-cpio                        #对匹配的文件使用cpio命令,将他们备份到磁带设备中
-prune                       #忽略某个目录
-amin      # 查找在系统中最后N分钟访问的文件
-mmin             # 查找在系统中最后N分钟里修改过的文件

2. Basic use

Find / -size + 10M | -l -H xargs LS
# identify the system files larger than 10M through the conduit back to the program processing xargs
Find -size -1k.
# identify the current directory, the file is less than 1k, Note that the directory can be considered
the find. the -type f -size -2k
# to find out the current directory, the file is less than 2K, but file
the find. -name " " the -type f -size 0c
# find empty file in the current directory, 0c represents 0 bytes
find -type -size -10K -exec F {cp} / root / 233 \;.
# to find out the current directory files smaller than 10K, copied to / root / 233 cp directory by running exec command format attention exec it is wonderful to be with \; the end of
the find -name. "
.txt" | xargs RM # to find out the current directory, txt file types, delete
find / home -links +2 # check hard links to directories or files larger than 2
find / home -perm 0700 # 700 check permissions for the file or directory

find / -nouser # Find belonging to void the user in the system file
find / -user fred # find FRED belong to the user's file system,
find / -empty # find empty in the system file or folder
find / -group cat # find files in the system belongs to groupcat

find / -type f -amin -10 # access system to find the last 10 minutes of the file
find / -type f -atime -2 # Find access the last 48 hours in a file system
find / -type f -empty # Find system empty file or folder
find / -type f -mmin -5 # Find the last five minutes of the modified file in the system
find / -type f -mtime -1 # search the last 24 hours in the modified system file.
find / home -type f -mtime -2 # checked altered in the last two days at the file / home
Find / home -type -1 # F -atime check under / home is accessed through within 1 day file
find / home -type f -mmin +60 # check under / home 60 minutes before the altered file
find / home -type f -amin +30 # check under / home recently accessed over 30 minutes before file
find. -type f -atime -7 -print # list all files in the current directory being visited in the last 7 days
find. -type f -atime 7 -print # list all files in the current directory happens to be visited before the seventh day
find. -type f -atime +7 -print # List all files in the current directory access for more than seven days
. find -type f -newer file.txt -print # to find out the current directory file.txt modification longer than all files, use -newer, you can refer to
(-atime is based on access time; -mtime is modified according to time; -ctime is a change in the time unit of the three parameters are the days).
(the access time is -amin; -mmin is a modification time;. -cmin is a time variation of these three parameters in minutes)

Advanced Usage

The -type f -name the Find "* .sh" |. xargs WC the -l
# .sh file to find out the current directory and displays the number of lines per file

echo ". 11: 22 is: 33 is: 44 is: 55: 66" | xargs -d: -N3
#xargs sort order: a delimiter, three in each row, -d: default means not separated by spaces

Guess you like

Origin blog.51cto.com/13620944/2456200