Linux Blog

Auto Clean-up Downloaded Files

Filed under: Shell Script Sundays — TheLinuxBlog.com at 11:37 am on Sunday, January 4, 2015

This week I went through my downloads folder, cleaning up erroneous files. In light of that I’ll share a quick tip on how to clean up the multiple copies of files that inevitably pile up. The issue is, when you save a file from firefox or Chrome, the next time you download the file, it just makes another copy with (1) or (2). I have a number of these on multiple systems, so hit the jump for a quick snippet, and explanation.

find . -iname "*(?)*" | while read i; do rm "$i"; done;

That’s the command, however I wouldn’t run that blindly if there was any doubt about the files I’d be deleting, if you want to check what files are going to be deleted run the find command alone first. All the one liner does use a simple while loop to read over the output from find, and tells rm to remove that file.