Bartłomiej Sobieszek Bartłomiej Sobieszek - 1 year ago 62
Linux Question

Remove files in subdirectories older than 1 day with Linux command

I am honestly nowhere near to be a decent bash scripter, but I made a little research and found a command that seems to be useful

find /path/to/files* -mtime +1 -exec rm {} \;

The question is if this line will remove directories? Because I want to only remove files that are images (actually in a *.jpeg format)

Answer Source

No, rm without the -r flag does not remove directories.

It looks like you want to add some more filters:

  • -type f to match only files
  • -name '*.jpeg' to match only files ending with .jpeg

Lastly, instead of -exec rm {} \;, you could use the much simpler -delete.

Putting it together, this looks more appropriate for you:

find /path/to/files* -mtime +1 -type f -name '*.jpeg' -delete
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download