Linux mv with xargs

 

mv(move) command file/directory name we want to move and destination name.

Using mv command with xargs is bit tricky.

Here is the example to move all files from oldDir to newDir:

$ find oldDir -type f | xargs -n 1 -I '{}' mv {} newDir/

where,

-type f is to find only files

-n 1 is for one argument at a time, that will move one file at time.

{} is the default argument list marker. You need to use {} this with various command which take more than two arguments at a time.

The main advantage of using xargs is it’s faster and efficient.

-Sany

About these ads

One comment on “Linux mv with xargs

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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