Using Bash, how can I delete all the desktop.ini in my external drive folder tree?

2

1

I am using my external HDD to store my music, and now I've installed Linux on my PC.

I would like to erase all the desktop.ini files in the thousand nested folders on the HDD, how can I accomplish this using only bash?

Alfa Taurus

Posted 2014-05-13T13:13:29.953

Reputation: 163

Answers

6

It's probably possible to do with just bash, but there's actually quite possibly a better option to do it using find.

Assuming you have write permission to the directories in question, it would be as simple as:

find /media/external-music-store -iname desktop.ini -delete

To test it first (strongly recommended), try something like this:

find /media/external-music-store -iname desktop.ini -print | less

which will give you a scrollable list of all files it would delete. (To exit less, press q; to scroll up and down, use the arrow keys.)

I am pretty sure that find is included in the standard install with most Linux distributions, and certainly most desktop-oriented ones. Debian packages it as findutils which is an essential and required package.

Using -iname causes case insensitive matching on the file name, matching Windows' semantics. Its counterpart -name uses case sensitive matching (which is the normal mode of operation on Unix-like systems, including Linux).

a CVn

Posted 2014-05-13T13:13:29.953

Reputation: 26 553

Thank you, a very complete answer! i've used the same command to erase also all the AlbumArt* file in the tree, almost unuseful under a linux environement. – Alfa Taurus – 2014-05-13T13:34:14.517

@AlfaTaurus Glad I was able to help. Welcome to SuperUser and Stack Exchange. – a CVn – 2014-05-13T13:35:38.137