Menu

Deleting files with the same name

Recently I replaced my old QNAP nas with a HP ProLiant MicroServer N54L. I then wanted to move everything I had from the QNAP nas to my new HP server, and it all went well, except for a lot of trash files I wanted to get rid of.

One of the problems was quite a lot of folders named “.@__thumb” which were in almost all folders that had one or more pictures in, or at one point had a picture in. Inside that folder I had expected there to be some kind of thumbnail, but there wasn’t, so not sure what that is all about. But anyways, I wanted to get rid of them, and being too lazy to do it one by one, I did a bit of searching, and ended up with this line.

find . -name .@__thumb -exec echo {} \;

This line does not remove anything, it just prints out everything it found. To delete actually remove the folders, this line is needed.

find . -name .@__thumb -exec rm -rf '{}' \;

But it is a good idea to use the echo first, and go over the list of entries it is going to remove, before blindly executing the one that will remove everything it found.

Next problem was all the “Thumbs.db” files from windows, after having accessed the folders too. The same commands could be used once again…

Share this:

One comment

I’m a big fan of adding a “-v” to the rm command (and never using -r if I intend to delete only files). The -v will print the names of the files being deleted, which is fairly convenient. As a sysadmin, I actually run “ls -rf /path/to/file” on Linux systems most of the time as my first command, so I can then just recall the command and type “rm”. Especially when I’m copy-paste’ing arguments, as I’ve had times where I accidentally selected two lines right before the paste, and seen (ok, “caused”) bad things happen. Using ls as my command and then using history + editing the command to rm prevents such accidents.

Also, if you’re on Linux or otherwise using GNU find (like on MacOS), you can use \+ instead of \; with find’s -exec switch, and it will add as many filenames as possible for the maximum command line length on your system, running way faster if there are a lot of files. Try running it with ls, for example, on the /etc/ filesystem. `time find /etc -type f -exec ls -d ‘{}’ \; | wc -l` and then do it again with `\+`. On my laptop, there are 2385 files in /etc. It takes about 2 seconds to run all the individual ls commands, v/s a very small fraction of a second (only about the time it takes to start a program) with the \+, since it runs ls only once. 🙂