What is the correct UNIX terminal command in order to list (ls), delete (rm), copy (cp) or whatever all files of a certain type (e.g. all ".jpg" images) inside a specific directory but including all sub-directories at any level?
For instance, I have a folder named "Photos" with a bunch of .jpg files spread all around in its root, sub-directories and sub-directories of the sub-directories etc. and I want to delete all of them (but leave the folders and any other files alone):
I've been experimenting with the list command (ls) as it's not quite as destructive as "rm" (remove)
.... and believe I need to use the "-R" (recursive) option, but I'm not sure if I'm getting it right.
I've tried this: ls -lR Photos/* *.jpg
But it seems to also include other files and folders.
And yes, I'm aware that using the "rm" command this way can be quite destructive if you don't know what you're doing (but also quite effective and time-saving). Backing up the folder structure first is probably a smart move.
For instance, I have a folder named "Photos" with a bunch of .jpg files spread all around in its root, sub-directories and sub-directories of the sub-directories etc. and I want to delete all of them (but leave the folders and any other files alone):
Code:
/Photos/
[B]Phone.jpg[/B]
[B]Mac.jpg[/B]
/People/
[B]popstar.jpg[/B]
/Family/
[B]dad.jpg[/B]
[B]mom.jpg[/B]
[B]sister.jpg[/B]
/Uncles/
[B]Uncle_Jim.jpg[/B]
[B]Uncle_Bob.jpg [/B]
/Places/
[B]Tokyo.jpg[/B]
[B]London.jpg[/B]
[B]Paris.jpg[/B]
[B]New_York.jpg[/B]
I've been experimenting with the list command (ls) as it's not quite as destructive as "rm" (remove)
I've tried this: ls -lR Photos/* *.jpg
But it seems to also include other files and folders.
And yes, I'm aware that using the "rm" command this way can be quite destructive if you don't know what you're doing (but also quite effective and time-saving). Backing up the folder structure first is probably a smart move.
Last edited: