Example: I just copied all my music over from my Windows partition. Unfortunately, I use to buy music off of Itunes. This left me with part of my music collection unusable. Well, I am not going to spend the time figuring out how to unsuck my songs, so I want just want to remove them all.
So, I start off looking at the file names and notice that the protected ones are of type m4p. Perfect. I can just look for those and delete them.
First, let me find all the protected songs.
$ find . -type f | grep '.m4p'
Awesome, I now know where all the files I want to delete.
In case I need to remember that I actually used borrow a song from Apple, I am going to save a list of songs that I am going to delete.
$ find . -type f | grep '.m4p' > ~/the_itunes_bonage.out
Now for the big show, "DELTEETED!!!!!" (sorry, strongbad reference).
$ find . -type f | grep '.m4p' | xargs rm
Wait, crap. That didn't work. Apparently, xargs treats anything separated by whitespace as an individual file.
Searching the interweb tells me to use --print0 on find and -0 on xargs. This uses null delimination instead of new lines. Well, that is great, but I really need to filter out all the songs that I want to keep.
You can ask grep to also treat null as the delimiter by adding the --null option. This didn't work for me. I didn't spend any extra time figuring out why not either.
Looks like I need to quote the damn things myself.
$ find . -type f | grep '.m4p' | awk '{print "\""$0"\""}' | xargs rm
There we go.
Moral of the story:
- Don't use spaces in filenames
- By music from Amazon MP3, it is DRM free!!
No comments:
Post a Comment