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


joshpond

Recommended Posts

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.)

Link to comment

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.

  • Like 1
Link to comment
  • 2 weeks later...

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

 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.