I'm sure there has to be a way to do this, but I'm not sure if it is rm or not.
I keep my music on my Mac's hard drive, formatted HFS+. I'm about to go overseas, and I am not taking my Mac with me, so I copied all the music to an external drive, so that I can "loan" it to people who have computers or mp3 players. The directory tree of this drive is organized into folders by artist, then by album within the artist folder.
Sometimes, OSX will create what are probably indexing files throughout the directory tree. So if I have the file "O8 Firestarter.m4a", it might produce the file "._08_Firestarter.m4a". These files are always less than 1KB. OSX, as far as the user is concerned, ignores them completely. A Linux machine, for all intents and purposes, will ignore them too. But a Windows machine will see these files and try to add them to playlists, or some other nonsense. Deleting these files doesn't affect disk or file operations in Linux or OSX. So it would be best to delete them before needlessly confusing those unfortunate enough to be using Windows (they're already confused!).
So the question is, how can I recursively delete all these file via my Linux computer? Matching the pattern of "._*.m4a" is easy enough. But there doesn't seem to be a way for rm to cruise through each directory and delete the files. Probably a perl or shell script would do it, and I may just end up writing one. But is there a built-in command that will handle this? A one-liner that goes through and does the whole tree in one swoop would be ideal.
Bonus points to anyone who knows what album the track listed above is from.
enhance my delete skills
Change into the directory containing the subdirectories you want to remove the files and:
Or add the directory in:
Or:
Code: Select all
find -name '\._*\.m4a' -exec rm -f '{}' \;
Code: Select all
find /mymusicdirectory -name '\._*\.m4a' -exec rm -f '{}' \;
Code: Select all
find -name '\._*\.m4a' | xargs rm -f
What, you don't believe me? :) Yes, all of them will work recursively from the starting directory just as I said:
or:
or:
If you want to see what will be deleted without deleting it just do the find without the rm:
Code: Select all
$ cd /music
$ find -name '\._*\.m4a' -exec rm -f '{}' \;
Code: Select all
$ find /music -name '\._*\.m4a' -exec rm -f '{}' \;
Code: Select all
$ cd /music
$ find -name '\._*\.m4a' | xargs rm -f
Code: Select all
$ find /music -name '\._*\.m4a'
http://voidmain.is-a-geek.net/man?param ... d&mode=man
find is an extremely powerful command, especially when combined with other commands. It's definitely worth learning it's capabilities if you are not familiar with it. It is definitely on the short list of must have *NIX administration tools. Just read over the man page and at least look at some of the examples in it....
find is an extremely powerful command, especially when combined with other commands. It's definitely worth learning it's capabilities if you are not familiar with it. It is definitely on the short list of must have *NIX administration tools. Just read over the man page and at least look at some of the examples in it....