April 26, 2011

Moving multiple files

I recently learned that you can move multiple files in one invocation of mv. As long as the last argument is a directory, then all the previous files/directories will be moved into it.

mike@shiner $ mv one.txt two.txt three.txt foobar

If the last argument isn't a directory, then you'll see an error.

mike@shiner $ mv one.txt two.txt three.txt 
mv: target `three.txt' is not a directory

3 comments:

  1. Another way to do this is with the -t argument. -t lets you specify the target directory:

    mv -t foobar one.txt two.txt three.txt

    I've found this useful in combination with xargs:

    ls *.txt | xargs mv -t foobar

    ReplyDelete
  2. Thanks, I found this post interesting. Curious if you find avantages to AB over Apache's Jmeter?

    ReplyDelete