简体   繁体   English

如何在Linux中按用户获取所有文件和目录

[英]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.

相关问题 [Golang] [Linux]-如何获取当前用户的所有打开文件 - [Golang][Linux] - How to get all open files by current user 在Linux脚本中,如何删除当前目录中的所有文件和目录? - In a Linux script, how to remove all files & directories but one, in current directory? 如何更改 linux 上包含特定字符串的所有目录/文件的名称 - how to change names of all directories / files containing a specific string on linux Linux:如何仅使用ls列出所有文件/目录 - Linux: How to list all files/directories, using only ls Linux:如何删除目录本身(不是子目录)内的所有文件(不是目录) - Linux: How to delete all of the files (not directories) inside a directory itself (not childs) 我想删除linux中的所有文件和目录 - I wanna to delete all files and directories in linux 在Linux中删除几乎所有目录和文件 - Removing almost all directories and files in linux 如何在linux上找到所有基本软链接或其他目录或文件的硬链接的文件? - How to find all files which are basically soft or hard links of other directories or files on linux? 如何使用 linux 中的 bash shell 脚本递归地重命名文件中的所有目录、文件和文本 - How to rename all directories , files and text in the files recursively using bash shell script in linux 在Unix / Linux目录/子目录中的任何位置获取与文件名中的模式匹配的所有文件 - Get all the files that match pattern in file name anywhere in unix/linux directories/subdirectories
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM