/bin/rm: Argument list too long (find's delete flag!)

Discussion in 'Command Line' started by Rob, Dec 2, 2011.

  1. Rob

    Rob Administrator Staff Member

    Messages:
    575
    Likes Received:
    217
    Trophy Points:
    43
    At some point in your Linux life you'll come across a directory of session files (or something similar) that you want to remove. BUT, when you try to remove the files with linux's rm command you're met with the error message:

    /bin/rm: Argument list too long


    Fret not.. use find to remove these session files with it's -delete flag!

    Let's say we're looking to delete files named session_848938, session_45949343, session_454344, etc.. and they live in /path/to/files/

    [xcode=bash]find /path/to/files/ -name "session_*" -delete[/xcode]

    Before I found out about find's cool -delete flag I'd pair up find with exec or xargs..

    [xcode=bash]find /path/to/files/ -name "session_*" -exec rm {} \;
    find /path/to/files/ -name "session_*" -print0 | xargs -0 rm[/xcode]

    Now, however.. i'll use the -delete flag.


    Does anyone know how long it's been around?
  2. fijiaaron

    fijiaaron New Member

    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I don't know how long it's been around, but on my Ubuntu 8.10 the delete flag is listed in the man page, but it doesn't work. I get this message:

    find: invalid predicate `-delete'
  3. Bill

    Bill New Member

    Messages:
    127
    Likes Received:
    5
    Trophy Points:
    0
    8.10 is fairly old. Ubuntu 12.10 will be out in a few months. 8.10 is nearly 4 years old. Have you considered upgrading?

Share This Page