How To: Remove all desktop.ini (or indeed any recurring) files in Linux

I spent a while going through my music hive today, just putting music I’d ripped and dumped into the New folder into the correct spot, placing all albums by the same band into a folder called the band name etc, and there’s a hella lot of desktop.ini and Thumbs.db files floating around. This might be useful for people running Windows, but I’m not (or at least not anymore, and not for a long, long time) – so lets be rid of them, shall we?

Blatantly Unnecessary Warning: Deleting files deletes files! Fo’ real, yo! So try out the “tester” script before unconditionally deleting things you might now want to! =D

Measure Twice, Cut Once

Before we delete files en masse – let’s check to see what files we’re opting to remove. To do this, and assuming we want to check what desktop.ini files we can remove, just enter something along the lines of the following into the bash:

find path-to-folder -name desktop.ini

For example, if my music is stored on my NAS at /mnt/Share/_Serva, then to check what files will be removed, I’ll enter:

find /mnt/Share/_Serva -name desktop.ini

After hitting return on the above, you should be given a list of instances of files called desktop.ini and we get to put our minds at ease that it’s not even thinking about adding any other files (such as mp3s or what-have-you) to the list.

Cease and Desist

Once we’re happy we’re going to remove only the files we want gone, to interactively delete all the desktop.ini files from a given folder and any subfolders (and by interactively, I mean it’ll ask you whether you want to delete each one), enter the following command into the bash:

find path-to-folder -name desktop.ini -exec rm -i {} \;

So in my instance, to interactively (i.e. I’d then have to confirm each delete) remove all instances of desktop.ini, I’d enter:

find /mnt/Share/_Serva -name desktop.ini -exec rm -i {} \;

If I wanted to automatically remove all copies of files named desktop.ini without confirming each deletion, then I can just strip off the -i switch, leaving:

find path-to-folder -name desktop.ini -exec rm {} \;

You can then do the same thing for Thumbs.db or any other filename just by substituting the appropriate details after the -name switch.

Done & done =D

P.S. Just for the record, removing the -i will make the deletion occur automatically unless the file is write-protected, but you can always sudo that away, just like the request for a sandwich.

Credits & thanks: MegaJim over on Ubuntu Forums.

5 thoughts on “How To: Remove all desktop.ini (or indeed any recurring) files in Linux”

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.