Jump to content

[Solved] Quick question: Linux command for deleting all files of certain type


joshpond

Recommended Posts

Posted

Hi All,

 

I have a user share, TV Shows and there are all these .jpg files in different subfolders for YAMJ. I'd like to delete all these file types but not sure what the command line would be.

 

I'm guessing it is the -r switch to delete all .jpg files:

 

rm -r *.jpg

 

Thanks Josh

Posted

If you just want to delete jpg files in the current directory, all you need to do is

 

rm *.jpg

 

The -r option tells the rm command to recurse down through all sub-directories below your current directory and delete the jpg files in those directories as well, so don't use it if you only want to delete files in your current directory.

 

A client of mine once ran "rm -r *" in the root directory.  They didn't realize until I told that they had deleted _all_ files on their system. It's a very dangerous command. (Fortunately it was only a test system and they had a backup.)

Posted

Thanks, that was what I was after. -r was the switch I wanted. I want to delete all .jpg files as they are scattered in diff directories for the nfo/metadata. I just want to keep the movie files like avi and isos.

 

Thanks Josh

Posted

 

root@Ho:/mnt/user/Media/TV Shows# rm -R *.jpg

rm: cannot remove `*.jpg': No such file or directory

 

Okay, Doesn't quite work, this is what I get.

Under the TV shows directory there are folders for each TV show.

 

Josh

Posted

It would be better with the find command.

Read up on find.

 

 

Try something like

 

find '/mnt/user/Media/TV Shows' -type f -name '*.jpg' -ls

 

This will list all your files that match the specs.

 

If it's what you want you can do

 

find '/mnt/user/Media/TV Shows'-type f -name '*.jpg' -ls -exec /bin/rm -vi {} \;

 

or you could take away the -vi and just do -v

 

The quotes are necessary, and so is the semicolon.

  • 2 weeks later...
Posted

This is the line I use to keep all them pesky windows thumbs out of my unraid :P

 

find /mnt/disk1/Movies/* -type f -name "Thumbs.db" -exec rm {} \;

 

although looking at Weebos would this one be better?

 

find '/mnt/disk1/Movies/' -type f -name 'Thumbs.db' -ls -exec /bin/rm -vi {} \; 

 

Just wondering is there a forum here on useful scripts for unraid users? I was looking for one yesterday and couldn't find anything. I got some scripts that im sure some people would find useful, like creating a log of everything copied to your drives (from cache) so it would be like tv added Jan 5th .... etc. I also got a script to update my external drive media added in the last x amout of days etc. A script to install and ready addons like snap etc when I reboot. Just thought it would be good to share and people could improve them/post their own etc

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...