简体   繁体   English

从特定用户拥有的特定目录中删除 Linux 中的文件的命令是什么?

[英]What is the command to remove files in Linux from a particular directory which are owned by a particular user?

Let's say we have a directory path /home/username .假设我们有一个目录路径/home/username How can we delete all the files only from this path which are owned/created by the user dev-user ?我们如何才能仅从该路径中删除由用户dev-user拥有/创建的所有文件? When I am trying当我尝试

find . -user c70945a -exec rm /home/dev-user/* {} \;

but it's giving an error and it's removing files from other directories as well.但它给出了一个错误,它也在从其他目录中删除文件。

find /home/username -maxdepth 1 -type f -user "dev-user" -delete

Use the user flag to specify files owner by a specific user and use -delete to remove the files.使用 user 标志指定特定用户的文件所有者并使用 -delete 删除文件。

Set maxdepth 1 to search for files within /home/username only and not child directories.将 maxdepth 设置为 1 以仅搜索 /home/username 中的文件,而不搜索子目录。

Use this find command:使用此find命令:

find /home/dev-user -user 'dev-user' -type f -exec rm {} +

+ at the end of -exec means that {} is expanded to the list of all matching files. -exec末尾的+表示{}扩展为所有匹配文件的列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 列出特定用户拥有的UNIX中的文件 - listing files in UNIX owned by a particular user 如何在Linux中将具有特定扩展名的文件从一个目录复制到另一个目录 - How to copy files with a particular extension from one directory to another in linux 删除linux中目录的所有子目录中的特定文件 - Delete particular files in all subdirectories of a directory in linux 限制用户访问linux / ubuntu中的特定目录 - Restrict user access to a particular directory in linux/ubuntu 如何在 Linux 上的指定目录中查找使用特定标头的所有文件? - How to find all the files that use a particular header in a specified directory on Linux? 通过使用LINUX中的C ++,显示文件包含在特定目录中 - Display files contain inside a particular directory by using C++ in LINUX 如何在linux中查找具有特定父目录的所有文件? - How to find all files with a particular parent directory in linux? 关于在Linux中特定目录的所有文件中搜索关键字 - Regarding searching a keyword in all files in particular directory in linux Linux:在目录下的文件列表中搜索特定词 - Linux : Search for a Particular word in a List of files under a directory 使用 curl 命令(Shell 脚本)将多个文件从 URL 下载到 linux 中的特定路径 - Download multiple files from URL to a particular path in linux using curl command (Shell Script)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM