Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I am using Arch, and I have a ton of music on my computer. Well as all you of you that use bit torrent probably know anytime you download an album you usually download a ton of cover art. So I want to delete this cover art without having to go folder by folder...does anyone know how I can delete all the .jpg files from my music folder and all the folders it contains in one command. Im pretty sure you can do it with like sed or awk but I dont really know much about those 2. So anyways if anyone can tell me how to do this Id appreciate it...thanks
If all your music is in a general folder called "My Music" in /home/user, the command would be:
rm -fr *.jpg /home/user/My\ Music
The "rm" is for remove
The -f is for force without asking me to confirm every file individualy
The -r is for recursive (all subdirectories of My Music)
The *.jpg is a wild card meaning everything ending with .jpg
Last edited by Junior Hacker; 03-24-2007 at 09:45 PM.
Im a little nervous to to use -fr, I want to be sure it will only get rid of the jpg's I tried regular rm but its not recursive so it doesnt work, but its like 60gb of music I REALLY dont want to accidentaly delete it ya know?
Im a little nervous to to use -fr, I want to be sure it will only get rid of the jpg's I tried regular rm but its not recursive so it doesnt work, but its like 60gb of music I REALLY dont want to accidentaly delete it ya know?
That's good, because the rm command doesn't work that way. That command would have deleted your entire My Music directory. Instead, try this:
By way of explanation, the command "rm -r *.jpg /home/user/My\ Music" won't work for two reasons:
1) rm takes a list of file paths, not a pattern and a path.
2) Even if it did, the shell handles wildcard expansion, so rm would never actually see the *.jpg.
What would actually happen if you ran that command is that the shell would expand *.jpg to all the .jpg files (if any) in the current directory, then pass the expanded parameter list to rm. So after expansion, the command that was actually executed would look something like this:
rm -r ./foo.jpg ./bar.jpg ./baz.jpg /home/user/My\ Music
This would recursively delete each file in the parameter list, completely wiping out My Music.
By contrast, in the command I posted above, we use find to locate all the files that match the pattern *.jpg. The -exec option will then cause find to call the given command on each file in finds. You can simply replace "rm" with "echo" to see what files would be deleted.
I just ran a test without the -f, and it did ask to remove any file ending with a . and three letters. It asked to remove the .jpg first, then the .mp3, then descend into a subdirectory and asked for confirmation for the .jpg's in it again before the .mp3's. So it's a good thing freespeaker got nervous.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.