Skip to content
Advertisement

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. How can we delete all the files only from this path which are owned/created by the 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.

Advertisement

Answer

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.

Set maxdepth 1 to search for files within /home/username only and not child directories.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement