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. Linux/Unix Search and Replace Text from Multiple Files In Linux/Unix, for newbie to do search text from multiple...
  5. exim: rejected EHLO, syntactically invalid argument If you email having problem with rejected EHLO or HELO,...
  6. Backup and Archive Incoming Email with Exim Loitering around Google and finding a way to archive/backup incoming...
  7. How to Change Hostname in Unix FreeBSD We have interesting hostname for our all our servers. Some...
  8. PostgreSQL Database psql Command Line Query Sometime psql command line query can be useful when it...
  9. windows 2000 – command line (cmd) command auto completion By default, windows 2k server does not activate this function....

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