我正在尝试在UNIX上编写以下命令:
ls -l | sed 'p/^.rwx'
但我收到以下错误:
sed: -e expression #1, char 2: extra characters after command
我正在尝试打印用户具有所有许可(rwx)的文件/目录
您的p
rint命令需要放在末尾,并且您还希望默认情况下禁止打印:
ls -l | sed -n '/^.rwx/p'
如果您使用的是stat
命令系统,则有另一种解决问题的方法:
for f in *
do
stat -c "%a" "$f" | grep -q ^7 && printf "%s\n" "$f"
done
依靠的输出是危险的ls
。考虑有人创建了这样的文件:
touch $'foo\n-rwx some file'
...会在ls
输出中创建一个单独的行,该行(错误地)与正则表达式匹配。使用shell glob(*
)可以避免该问题。
还有一种方法是使用find
:
find . ! -name . -prune -perm -700 -ls
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句