[英]How to get all files and directories by user in Linux
I am trying to find all the directories and files owned by user with the following command. 我正在尝试使用以下命令查找用户拥有的所有目录和文件。
find / -type d -user greg | grep -v proc
it is working fine sometimes and hanging up sometimes. 有时工作正常,有时挂断。 Is there any performance issues associated with it or is there any better way to executing this.
是否存在与此相关的性能问题,或者是否有更好的方法来执行此操作。
To keep it from descending into /proc
, use -prune
. 要防止它下降到
/proc
,请使用-prune
。 It's better than filtering out entries with grep -v
as it'll avoid descending into /proc
at all. 这比使用
grep -v
过滤条目更好,因为它完全避免了降级为/proc
。
find / -path /proc -prune -o -type d -user greg -print
Read -o
as "or". 将
-o
读为“或”。 If the path is /proc
, prune it, ie don't go in there. 如果路径是
/proc
,请修剪它,即不要进入那里。 Otherwise, match directories owned by greg. 否则,匹配greg拥有的目录。 (If you want files too then get rid of the
-type d
test.) (如果您也想要文件,则摆脱
-type d
测试。)
When you use -prune
, you also have to use -print
to print matches. 使用
-prune
,还必须使用-print
来打印匹配项。 -print
's normally implied, but using -prune
changes that. -print
通常是隐含的,但是使用-prune
更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.