Linux mv with xargs

Sany's Linux and Open Source Blog

 

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

View original post

Leave a Reply

Please log in using one of these methods to post your comment:

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 )

Connecting to %s