您的位置:首页 > 其它

find命令

2016-02-18 23:11 351 查看

find PATH -option [-print] [-exec|-ok cmd] {} \;

1. Time

-atime N

-ctime N

-mtime N

-newer FILE

-amin M

-mmin M

–5–4–3–2–1–0

find . -mtime +3

find . -mtime 3

find . -mtime -3

Before N days: find . -mtime +(N-1)

find . -mtime +31/366

# 10分钟内访问的文件
find . -amin -10

# 48小时内修改的文件
find . -mtime -2

# 60分钟前被修改的文件
find . -mmin +60


2. user & group

uid n

-gid n

-user name

-group name

-nouser

-nogroup

#uid大于等于1048
find /var -uid +1048


3. file

name FILENAME

-type TYPE (f,b,c,d,l,s,p)

-size SIZE

-empty

-inum n

-links NUM

-depth 先当前目录。后子目录

-maxdepth level

-mindepth level

-xdev

-mount 貌似不支持unix

-follow dereference symbolic links

-L

-fstype TYPE(ext3,proc)

-prune

-perm [-+] mode

-: 必须全部包含mode属性

+: 包含任意一个mode属性即可

: 必须等于mode属性

find . -maxdepth 1  当前目录
find . -maxdepth 2  第一第二级目录

find . -mindepth 4  从第三层目录开始

find . -maxdepth 3 -mindepth 2  第二层和第三层

find . -path /var/log -prune -o -print
find . \(-path /var/log -o -path /var/spool \) -prune -o -print

find . -size 1000  # 1000 blocks, 512bytes/block
find . -size +70M
find . -size 20c  # 20 bytes

find . -empty  # 空文件或空目录
find . -links +2  链接数超过2

find /mnt -name a.txt -fstype vfat
find / !-fstype proc '(' -name '.??*' -o -name '.[^.]' ')'

find / -perm 664 权限等于664
find / -perm -664 权限完全满足664,但可包含额外权限,655,777
find / -perm /664 权限部分满足664,例如660和600

find . -perm -007  others用户具有rwx权限
find . -perm -100 属主至少具有x权限

特殊权限SGID,SUID,SBIT
find . -perm +7000  至少具有一个特殊权限位
find . -perm -7000 具有全部特殊权位


xargs: build and execute command lines from standard input

find / -name "core" -print | xargs echo "" > core.log

find .  -perm -7 -print | xargs chmod o-x

find . -name \* -type f | xargs grep "abc"

# 拷贝整个目录
ls | xargs -i -t cp ./{}  /tmp/eli
-t, verbose, print command line on stderr before  executing
-i, replace all occurrences of {}, with the names read from stdin
{}, a placeholder for output text

ps ax | grep mysql | awk '{print $1}' | xargs -i kill     {}

# 压缩文件,每次一个
ls | xargs -p -l gzip
-p, prompt
-l, max argument length, default 1

-print \n
-print0 NULL

xargs默认以空格,TAB,换行符来分隔纪录
# 文件名含特殊字符
find . -type f -print0 |xargs -0 file

grep -lZ words.txt |xargs -0

# gzip every file,one at a time, prompting before each operation
ls | xargs -p -l gzip

# list files in 8 column
ls | xargs -n 8 echo

# to handle arguments containing whitespace or quotes
find / -type f -print0 | xargs -0 grep -liwZ GUI | xargs -0 rm -f

# -t: print command to stderr
# -n1: at most 1 argument per command line
# -P2: run up to 2 processes simultaneously
ls *.txt | xargs -t -n1 -P2 gzip

# -eEOF, set the end of file string to EOF
cut -d ":" -f 1 /etc/passwd | xargs -p -e"lp" finger
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: