Find the answer to your Linux question:
Results 1 to 7 of 7
Is it possible to delete all the files that appear in the find command's output , for example .. i tried this command in order to delete every file which ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2003
    Posts
    20

    is it possible to "rm" the find's output ?


    Is it possible to delete all the files that appear in the find command's output , for example .. i tried this command in order to delete every file which has been modified more than 8 days ago
    in /bla/ directory .

    Code:
     find /bla/* -mtime +8 | rm
    but it didnt work ...
    rm: too few arguments
    Try `rm --help' for more information.

  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Why of course. You can't pipe the output to rm. rm deletes files that it finds on its command line, not on its standard input. Try this instead:
    Code:
    find /bla/* -mtime +8 -exec rm {} \;

  3. #3
    Linux Engineer
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    796
    Or like this...

    Code:
    find /bla/* -mtime +8 | xargs rm *
    Regards

    Regards

    Andutt

  4. #4
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Yeah, but the problem with xargs is that it chokes on special characters. If you want to use xargs, at least do it like this:
    Code:
    find /bla/* -mtime +8 -print0 | xargs -0 rm
    By the way, you do _not_ want to do "xargs rm *", andutt! I think you'll see why if you look at it once more.

  5. #5
    Just Joined!
    Join Date
    Apr 2003
    Posts
    20

    thanks

    ok , it worked ..
    thanks for the tips pals ..
    peace ,

    Smokie :P

  6. #6
    Just Joined!
    Join Date
    May 2006
    Posts
    3
    Wow... This thread helped me alot...
    Got a ton of files off a mac user, and was crawling with shadow files...

    so I used: "find */*/._* -print0 | xargs -0 rm"
    I'm too lazy to make it automaticly crawl all dirs, it was mainly 2 subdirs in...

  7. #7
    Just Joined!
    Join Date
    Apr 2014
    Location
    Dublin
    Posts
    9
    Code:
     find /bla/* -mtime +8 | rm
    the post is vy old but I think the below may be helpful for others.

    today I messed with xargs and find and it gave me error message like:

    'rm : missing operand' to the below command:
    find ./ -name "x[a-z]" -print0 | xargs -0 rm

    according to tutorials it should be enough, but it wasn't. so I added the missing 'operand':

    find ./ -name "x[a-z]" -print0 | xargs -0 rm x*

    and it worked. I guess, similarly you should do with your command. be mindeful of 'rm' command (!). i.e. be very specific of what to remove.

    good luck!

Posting Permissions

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