Using xargs

For sometime now i have been trying to use the xargs command but it sometimes proves somewhat hard for me to understand but now i think i have got the hang of it. Here is a sample code to demonstrate how easy it really is.

% find . -maxdepth 1 -name ‘filesys*’ -print0 | xargs -0 -Ifil mv fil “thefile”

The various parts of the command are :

  • .   : Represents the current directory.
  • -maxdepth : Tells the find command to which depth should it recursively look for the search term. In this case its 1.
  • -name : The name of the search term or item.
  • -print0 : Note its “Zero” not O. This prints out the file matching the name. The 0 handles file names that have whitespaces in them. I think its always good to have them on.
  • -0 : It also handles white space characters for you.
  • -I : Temporarily store the currently matched file in the variable “fil”.
  • mv : Rename the file represented by fil to ;
  • the file. You can do without the double quotes.

Hope that helped.

About these ads

One response to this post.

  1. If you find xargs useful, you might also like GNU Parallel

    Watch the intro video to GNU Parallel at


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: