Page 2 of 2 FirstFirst 12
Results 11 to 18 of 18

Thread: rm command

  1. #11
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: rm command

    find . ! -iname '*.jpg' -print0 | xargs -0 rm
    I leave it to you to exclude other file suffixes.

  2. #12
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    26,225

    Default Re: rm command

    Back after a nice sleep and a fine run on sundaymorning

    Found the solution using the shell only (not calling other helpers like find, rc, perl, etc.). I will use echo instead of rm for obvious reasons:
    Code:
    echo *[!.][!j][!p][!g]
    Do we continue providing more solutions (we did not reach 10 until now)?

    Also works::
    Code:
    ls | while read FN
    do      [[ $FN == *.jpg ]] || echo $FN
    done
    Who offers a PHP solution?

    mooreted, are yo still with us? Did you already decide what to use? Or gave you up following us
    Henk van Velden

  3. #13
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: rm command

    Quote Originally Posted by hcvv View Post
    Also works::
    Code:
    ls | while read FN
    do      [[ $FN == *.jpg ]] || echo $FN
    done
    Who offers a PHP solution?

    mooreted, are yo still with us? Did you already decide what to use? Or gave you up following us
    Careful with filenames containing spaces.

  4. #14
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    26,225

    Default Re: rm command

    I made a file with a space in it and it works, see the last file down here:
    Code:
    henk@boven:~> ls | while read FN
    > do      [[ $FN == *.jpg ]] || echo $FN
    > done
    Afbeeldingen
    bin
    Desktop
    Documents
    google-earth
    logs
    Mail
    public_html
    ripper
    spatie spatie
    henk@boven:~>
    But I agree that when yyou want to program such actions in a script, you should test all those peculiarities.
    Henk van Velden

  5. #15

    Default Re: rm command

    Wow.

    I am not awake enough to think about all of that yet.

    Thank you all for your solutions. I will have to try them on some test files and see which seems the most elegant for me.

    I was thinking I could do:

    mkdir temp
    mv *jpg* temp
    rm *

    As well.

  6. #16
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    26,225

    Default Re: rm command

    Solution #6 (or 7 or so).

    May I correct a little bit?

    Code:
    mkdir temp
    mv *.jpg temp/
    rm *
    cd temp
    mv * ../
    cd -
    rmdir temp
    Because yours would also move a file like README-about-these-jpg-files, mine only those ending in .jpg and mine moves the saved files back and removes the tempdir to clean everything up (not that you did not think about that yourself of course). The / at the end of the directories are not mandatory butI like to make clear it is about a directory.
    Henk van Velden

  7. #17

    Default Re: rm command

    Quote Originally Posted by hcvv View Post
    Solution #6 (or 7 or so).

    May I correct a little bit?

    Code:
    mkdir temp
    mv *.jpg temp/
    rm *
    cd temp
    mv * ../
    cd -
    rmdir temp
    Because yours would also move a file like README-about-these-jpg-files, mine only those ending in .jpg and mine moves the saved files back and removes the tempdir to clean everything up (not that you did not think about that yourself of course). The / at the end of the directories are not mandatory butI like to make clear it is about a directory.
    Well yeah. I figured the last bit was understood.

    You have to move the files back to their original dir.

    My solution is not very granular though. When I have time I will have to look at some of the other solutions for better control when lots of different files are mixed and need to be sorted out easily.

  8. #18
    Tilman Schmidt NNTP User

    Default Re: rm command

    hcvv schrieb:
    > Back after a nice sleep and a fine run on sundaymorning
    >
    > Found the solution using the shell only (not calling other helpers like
    > find, rc, perl, etc.). I will use *echo *instead of *rm *for obvious
    > reasons:
    >
    > Code:
    > --------------------
    > echo *[!.][!j][!p][!g]
    > --------------------



    Close, but no cigar:

    ts@xenon:~/kernel> mkdir /tmp/tessst
    ts@xenon:~/kernel> cd !$
    cd /tmp/tessst
    ts@xenon:/tmp/tessst> touch a.jpg b.kpg c.pkg d.pgk
    ts@xenon:/tmp/tessst> ls
    a.jpg b.kpg c.pkg d.pgk
    ts@xenon:/tmp/tessst> echo *[!.][!j][!p][!g]
    *[!.][!j][!p][!g]
    ts@xenon:/tmp/tessst> touch e.jpgk
    ts@xenon:/tmp/tessst> echo *[!.][!j][!p][!g]
    e.jpgk
    ts@xenon:/tmp/tessst>


Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •