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

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

假设我们有一个目录路径/home/username。我们如何才能删除用户 dev-user 在此路径中 owned/created 的所有文件?当我尝试

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

但是它给出了一个错误并且它也从其他目录中删除了文件。

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

使用用户标志指定特定用户的文件所有者,并使用 -delete 删除文件。

将最大深度设置为 1 以仅在 /home/username 中搜索文件,而不是子目录。

使用此 find 命令:

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

+表示{}扩展为所有匹配文件的列表。