我正在寻找所有setuid/setgid文件.当我不使用时-exec,它按预期工作:
# find /usr/bin -type f -perm -4000 -o -perm -2000
/usr/bin/wall
/usr/bin/ksu
/usr/bin/chage
/usr/bin/chfn
/usr/bin/chsh
/usr/bin/fusermount
/usr/bin/passwd
/usr/bin/write
/usr/bin/su
/usr/bin/umount
/usr/bin/gpasswd
/usr/bin/newgrp
/usr/bin/mount
/usr/bin/pkexec
/usr/bin/crontab
/usr/bin/cgclassify
/usr/bin/cgexec
/usr/bin/ssh-agent
/usr/bin/Xorg
/usr/bin/at
/usr/bin/sudo
/usr/bin/locate
/usr/bin/staprun
Run Code Online (Sandbox Code Playgroud)
当我使用时-exec,我只得到一部分结果:
# find /usr/bin -type f -perm -4000 -o -perm -2000 -exec ls -l {} \;
-r-xr-sr-x. 1 root tty 15344 Jan 27 2014 /usr/bin/wall
-rwxr-sr-x. 1 root tty 19536 Aug 21 2015 /usr/bin/write
-rwxr-sr-x. 1 root cgred 15624 Sep 21 2014 …Run Code Online (Sandbox Code Playgroud) 我可以在rsync数组中定义我的排除/选项,并在后续命令中使用这些数组,例如
rsync "${rsyncOptions[@]}" "${rsyncExclusions[@]}" src dest
我想使用该find命令实现相同的目标,但我找不到让它工作的方法:
findExclusions=(
"-not \( -name '#recycle' -prune \)"
"-not \( -name '#snapshot' -prune \)"
"-not \( -name '@eaDir' -prune \)"
"-not \( -name '.TemporaryItems' -prune \)"
)
LC_ALL=C /bin/find src -mindepth 1 "${findExclusions[@]}" -print
Run Code Online (Sandbox Code Playgroud)
无论我尝试以何种组合来定义数组(单引号与双引号,转义括号),我总是会遇到错误:
find: unknown predicate `-not \( -name '#recycle' -prune \)'
# or
find: paths must precede expression: ! \( -name '#recycle' -prune \)
Run Code Online (Sandbox Code Playgroud)
这样做的正确方法是什么?
我需要一个脚本来删除所有空文件并将已删除文件的列表写入文本文件。
删除文件有效。不幸的是,该列表不起作用。
find . -type f -empty -print -delete
Run Code Online (Sandbox Code Playgroud)
我尝试过这样的事情:
-print >> test.txt
Run Code Online (Sandbox Code Playgroud) 我遇到 bash 命令返回以下错误的问题:
/usr/bin/find: missing argument to `-exec'
Run Code Online (Sandbox Code Playgroud)
我正在运行的实际命令是:
/usr/bin/find /backup-directory/ -maxdepth 1 -type f -mtime +14 -printf "%f\n" -exec /usr/local/bin/aws s3 mv /backup-directory/{} s3://my-s3-bin/{}\;
Run Code Online (Sandbox Code Playgroud)
目标是每晚从 crontab 调用此命令来搜索目录并使用 aws cli 将任何超过 14 天的文件移动到 Amazon S3。
find 命令可以正常工作,直到 -exec 之前,输出如下:
/usr/bin/find /backup-directory/ -maxdepth 1 -type f -mtime +14 -printf "%f\n"
20161030002947.Pg
20161029002644.Pg
20161027002705.Pg
20161028002402.Pg
20161031002440.Pg
Run Code Online (Sandbox Code Playgroud)
只需使用要移动的显式文件名的 aws cli move 命令即可按预期工作:例如,以下命令会将 20161030002947.Pg 从本地备份目录移动到 s3 bin。
/usr/local/bin/aws s3 mv /backup-directory/20161030002947.Pg s3://my-s3-bin/20161030002947.Pg
Run Code Online (Sandbox Code Playgroud)
我不知道为什么当我将它们与 -exec 和 {} 参数放在一起时它会被破坏。
从完整路径调用所有内容的原因是为了确保从 crontab 调用命令时不会出现不可预见的问题,并且该特定服务器上的操作系统是 Debian 8。