You are not logged in.

#1 2007-06-23 02:10:26

azwethinkweiz
Member
Registered: 2007-01-25
Posts: 101

A quick question about deleting in command line

What I want to do is simply delete all the album art that manages to get download with some torrents. However I have a huge music collection...and to sort thrugh all the floders trying to delete the jpgs would simply take too long. So is there a command I can use in terminal to recursivley delete ONLY the jpg files in my music directory??


"The hardest thing is rendering a moment moving to fast to endure"

Offline

#2 2007-06-23 02:17:58

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: A quick question about deleting in command line

find . -name '*.jpg' -exec rm {} \;

Should do it for you.  If you want to ensure that only the right files are being deleted, just run

find . -name '*.jpg'

That will list everything that would be removed.

man find

for more.

Offline

#3 2007-06-23 04:35:18

azwethinkweiz
Member
Registered: 2007-01-25
Posts: 101

Re: A quick question about deleting in command line

well the only problem with is...when I run the command to list the files that would be removed...it shows all my photos, icons etc...


"The hardest thing is rendering a moment moving to fast to endure"

Offline

#4 2007-06-23 05:01:35

ataraxia
Member
From: Pittsburgh
Registered: 2007-05-06
Posts: 1,553

Re: A quick question about deleting in command line

So find on your music directory instead of '.' .

Offline

#5 2007-06-23 07:59:51

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: A quick question about deleting in command line

Two small additional suggestions:
- find has its own removal flag, so you could also do:

find /path/to/music -name '*.jpg' -delete

- find also has a very good man page wink

Offline

#6 2007-06-23 20:54:30

azwethinkweiz
Member
Registered: 2007-01-25
Posts: 101

Re: A quick question about deleting in command line

Ok...unless Im doing something wrong...which is very possible. This isnt doing what I want it to do. I dont even know if you CAN do what I want. I want to delete every jpg image in my music directory with one command. A buddy told me this can be done with wildcards but he doesnt know how. So rather than going through each album in my music directory, Im wanting to know if there is a command to delete only jpg images from my entire music directory...without it recursing into my home in turn wiping out all my photos too. This may be what you are telling me and Im making a mistake somewhere on my end. But Im just using a test folder with files I dont really care about and can be replaced, and so far either the entire directory is deleted or nothing at all is deleted. For instance...

find /home/nate/test -Disc_4 '*.jpg' -delete...gives me this
find: invalid predicate `-Disc 4'
and the entire directory /home/nate/test is deleted

find /home/nate/test '*.jpg' -delete returns the '*.jpg': no such file or directory...which I thought it would do but I tried it anyway.

So I'm wondering...Did I still use the command wrong? Or is this command not going to do what Im trying to do? If so is there a command that will?

Thank you for all your help


"The hardest thing is rendering a moment moving to fast to endure"

Offline

#7 2007-06-23 21:36:19

Kerowyn
Member
Registered: 2006-05-18
Posts: 2

Re: A quick question about deleting in command line

I think what you are looking for is:

find /home/nate/test/Disc_4 -name '*.jpg'

Offline

#8 2007-06-23 21:50:16

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: A quick question about deleting in command line

Or in more general terms, you could try using the command as it was given i.e. with the -name flag. smile

Seriously though tongue -
this

find /home/nate/test -Disc_4 '*.jpg' -delete

doesn't work because there's a space and '-' between 'test' and 'Disc_4', so find attempts to make some sense of 'Disc_4' as a flag, which obviously doesn't work out.

The reason I suggested reading the man page was that I thought you might like to work out the right command for yourself, rather than rely on suggestions here (notwithstanding the IMO overall high quality of advice given). If you would prefer not to do that, the various commands given above will work, IF you use them as given, AND insert the full path to your music directory.

Last edited by tomk (2007-06-23 21:51:13)

Offline

#9 2007-06-23 22:04:21

azwethinkweiz
Member
Registered: 2007-01-25
Posts: 101

Re: A quick question about deleting in command line

Id have to agree that the advice is of very high quality...thats what keeps me comin back hehe. Thanks that worked...I figured it must have been a typo in the command. It wasnt exactly what I was looking for but Ill check the man pages and see if i can refine it alittle. Thanks again for all the help everyone


"The hardest thing is rendering a moment moving to fast to endure"

Offline

Board footer

Powered by FluxBB