useful unix command: xargs

In our mailserver, we backup every incoming email and keep it for a week. Sometime, it’s PITA when you want to purge the old email. For example;

[takizo@rooney backup]# rm -rf S0118*
-bash: /bin/rm: Argument list too long

when come to rm large amount of files, or editing, or rename, xargs is … very useful, no more PITA.

[takizo@rooney backup]# find . -name ‘S0118*’ | xargs rm

that’s it, so my friend, don’t do rm S011800*, S011802*, S011803*, S011804*, S011823 …. It’s wasting your time :D

update 20080721 : for file name with spaces with it use “find . -iname S0118* -print0 | xargs -0 rm”.

Related posts:

  1. ls & rm with regular expression e.g. rm -rf backup-20070[8-9]-* would delete : backup-200708-morning backup-200708-evening backup-200709-night...
  2. convert epoch using date command date -d ‘<Unix epoch> <epoch date> sec’ e.g. date -d...
  3. Check DNS Record with Dig Command Check DNS Record with Dig Command How do you find...
  4. exim: rejected EHLO, syntactically invalid argument If you email having problem with rejected EHLO or HELO,...
  5. Backup and Archive Incoming Email with Exim Loitering around Google and finding a way to archive/backup incoming...
  6. Changing File’s Date and Time on Unix Systems Change Data and Time of a File At times, we...

4 Responses to “useful unix command: xargs”

  1. LW Says:

    thankz!!

  2. rd Says:

    If you get “argument list too long” error again with xargs, its time to use

    $ find . -name ‘S0118*’ -exec rm {} \;

    ;)

  3. pradeep Says:

    help

    whare is ablevel openwebmail users address book in linux 9

    my id is pspal83@gmail.com

  4. mymac Says:

    if the file/directory name has spaces in it, use “find ./ -iname ‘S0118*’ -print0 | xargs -0 rm -rf” instead …

Leave a Reply