大网数据广告活动
服务器运维问答

How do I find files and directories not owned by a given user?

· 52CE 我爱测

I have a set of files within a directory owned by 'alfred'. From a quick inspection, most of the files within are also owned by 'alfred'. I'd like to change ownership of the folder and everything owned by 'alfred' to be owned by …

问题原文

原帖链接 · Borea Deitz · CC BY-SA 4.0

I have a set of files within a directory owned by 'alfred'. From a quick inspection, most of the files within are also owned by 'alfred'.

I'd like to change ownership of the folder and everything owned by 'alfred' to be owned by 'betty'. However, it might be possible that 'alfred' has files within this directory that he's determined should be owned by a different user. For example, there might be a script that won't execute unless it's owned by 'root', or a directory that's symlinked to an area owned by 'chris', so that things inside need to be owned by 'chris'.

How can I find all files and folders with the top directory that are owned by a user other than 'alfred'?

This question is similar, but the answers given only cover the case of things not owned by the current user. I want to find things not owned by any specified user.

已采纳解答

原帖链接 · berndbausch · CC BY-SA 4.0

To find files owned by other accounts, find . \! -user alfred. The exclamation mark means "not", and it has to be escaped by a backslash or singe quotes to avoid interpretation by the shell.

Or, to change ownership of alfred's files, find . -user alfred -exec chown betty '{}' +.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-04-30)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。