Jump to content

Unix/Linux command


take it take

Recommended Posts

I'd like to copy files with a specific filename format. Here's an example:

picture1.jpg

picture1.highlight.jpg

picture1.thumb.jpg

picture.sized.jpg

picture2.jpg

picture2.highlight.jpg

picture2.thumb.jpg

picture2.sized.jpg

I only want the ones WITHOUT the "highlight", "thumb", and "sized", therefore, I only want picture1.jpg and picture2.jpg. If I issue a:

cp *.jpg ../temp

ALL the files ending with .jpg will be copied and I eventually have to delete the rest manually by:

rm *.highlight.jpg

rm *.sized.jpg

rm *.thumb.jpg

in the temp directory.

Is there a nifty way to only grab the ones I want? BTW, that was a small example. I have to grab about 200-300 images in each directory x 50 directories. :?:

Link to comment
Share on other sites

well, one way would be to use 3 commands per directory

(this is presuming that the numbers are not of uniform length)

cp picture?.jpg <insert your destination folder here>

cp picture??.jpg <insert your destination folder here>

cp picture???.jpg <insert your destination folder here>

? is a wild character similar to * except that it means that it can be replaced by any single character, not multiple characters.

ofcourse, this task is made much easier if the numbers are of uniform length (eg, 3 characters such as 001)

this could also be chucked in a script to automate each directory.

my linux command line skills aren't the best though, so maybe there is a way to have multiple source files in the one command.

**edit**

just did some exploring, this should work for you

cp picture?.jpg picture??.jpg picture???.jpg <insert your destination folder here>

Link to comment
Share on other sites

Okay, my first example wasn't a good one. Yes, there are picture1.jpg, picture2.jpg, but there's also concert2.jpg, people29.jpg and city127.jpg and so on in the same directory. Doing a

cp picture?.jpg ../temp

would work partially. I apologize for not giving a good example. :(

@Sparda: I tried

cp [12].jpg ../temp

and I got this:

cp: cannot stat `[12].jpg': No such file or directory

Link to comment
Share on other sites

@Sparda: I tried

cp [12].jpg ../temp

and I got this:

cp: cannot stat `[12].jpg': No such file or directory

need the *, sorry ;)

Corrected command:

cp *[12].jpg

If all the files you want to copy have a number befor .jpg, then you should beable to use:

cp *[1234567890].jpg

with no problems.

Link to comment
Share on other sites

using cp *[1234567890a].jpg should get you all the files you want out of that list.

it's a pattern matching command, it's basically asking for any file that ends in .jpg, as well as the character before that being in the approved list (enclosed in the square brackets)

as long as none of your other files end in d or b, you should be fine making it something like

cp *[1234567890acefghijklmnopqrstuvwxyz].jpg <your destination directory>

Link to comment
Share on other sites

ahh, so thats the not operator. ty sparda, i shall remember this ;) i've been meaning to learn RegExp's for a while now.

*edit* btw, is it just more or does it look like he is cleaning out a directory where he just dumped a crawl of a porn site? :P

Link to comment
Share on other sites

more filez.txt | grep [^em][^db].jpg

101349oct306Alina.jpg

111349oct306Alina.jpg

11349oct306Alina.jpg

121349oct306Alina.jpg

131349oct306Alina.jpg

1349GroupShot10306.jpg

141349oct306Alina.jpg

151349oct306Alina.jpg

161349oct306Alina.jpg

171349oct306Alina.jpg

181349oct306Alina.jpg

191349oct306Alina.jpg

1Me1349Oct306.jpg

201349oct306Alina.jpg

211349oct306Alina.jpg

21349oct306Alina.jpg

221349oct306Alina.jpg

231349oct306Alina.jpg

241349oct306Alina.jpg

251349oct306Alina.jpg

261349oct306Alina.jpg

271349oct306Alina.jpg

281349oct306Alina.jpg

291349oct306Alina.jpg

2Me1349Oct306.jpg

301349oct306Alina.jpg

311349oct306Alina.jpg

31349oct306Alina.jpg

31CelticFrost10306Alina.jpg

321349oct306Alina.jpg

32CelticFrost10306Alina.jpg

331349oct306Alina.highlight.jpg

331349oct306Alina.jpg

33CelticFrost10306Alina.jpg

341349oct306Alina.jpg

34CelticFrost10306Alina.jpg

351349oct306Alina.jpg

35CelticFrost10306Alina.jpg

361349oct306Alina.jpg

36CelticFrost10306Alina.jpg

371349oct306Alina.jpg

37CelticFrost10306Alina.jpg

381349oct306Alina.jpg

38CelticFrost10306Alina.jpg

391349oct306Alina.jpg

39CelticFrost10306Alina.jpg

3Me1349Oct306.jpg

401349oct306Alina.jpg

40CelticFrost10306Alina.jpg

411349oct306Alina_001.jpg

411349oct306Alina.jpg

41349oct306Alina.jpg

41CelticFrost10306Alina.jpg

421349oct306Alina.jpg

42CelticFrost10306Alina.jpg

431349oct306Alina.jpg

43CelticFrost10306Alina.jpg

441349oct306Alina.jpg

44CelticFrost10306Alina.jpg

451349oct306Alina.jpg

45CelticFrost10306Alina.jpg

461349oct306Alina.jpg

46CelticFrost10306Alina.jpg

471349oct306Alina.jpg

47CelticFrost10306Alina.jpg

481349oct306Alina.jpg

48CelticFrost10306Alina.jpg

491349oct306Alina.jpg

501349oct306Alina.jpg

511349oct306Alina.jpg

51349oct306Alina.jpg

521349oct306Alina.jpg

531349oct306Alina.jpg

541349oct306Alina.jpg

551349oct306Alina.jpg

561349oct306Alina.jpg

571349oct306Alina.jpg

581349oct306Alina.jpg

591349oct306Alina.jpg

601349oct306Alina.jpg

611349oct306Alina.jpg

61349oct306Alina.jpg

621349oct306Alina.jpg

631349oct306Alina.jpg

641349oct306Alina.jpg

651349oct306Alina.jpg

661349oct306Alina.jpg

671349oct306Alina.jpg

681349oct306Alina.jpg

71349oct306Alina.jpg

81349oct306Alina.jpg

91349oct306Alina.jpg

CandyKingMeGd103006.jpg

CandyMe1349gig10306.jpg

CandyMeSahgGd10306.jpg

From what I can tell, there is only one false positive an no false negatives, but I haven't looked at it that carefully ;)

Link to comment
Share on other sites

Well, here's some ideas:

cp * <destination> && rm <destination>/*{highlight,thumb,sized}.jpg

for file in `ls | grep "[^(sized|thumb|highlight)].jpg"`; do cp $file <destination> ; done

But the winner should be:

find . -name "*[^(sized|thumb|highlight)].jpg" -exec cp {} <destination> ;

Link to comment
Share on other sites

brainstorming

ls -Q *.jpg | grep -v -e highlight -e thumb -e sized | xargs cp destinationdir/

update: it didnt worked...

i got this to work nontheless

for pics in `ls *.jpg | grep -v -e highlight -e thumb -e sized `; do cp $pics destinationdir/ ; done

update2: oops i just saw a very similar command just above...

here's one with sed

for pics in `ls | sed 's/thumb|highlight|sized/DONTCOPY/g' | grep -v DONTCOPY `; do cp $pics destdir/ ; done

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...