Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying this and its not working

ls file_* |xargs mv {} temp/

Any ideas

share|improve this question

migrated from Jan 8 '13 at 7:45

This question came from our site for professional and enthusiast programmers.

Anyone with a multi file move version of this? (xargs -n10 for example) – Gert van den Berg Apr 14 at 9:42
up vote 16 down vote accepted

On OS X:

ls file_* | xargs -J {} mv {} temp/

On Linux:

ls file_* | xargs -i {} mv {} temp/
share|improve this answer
whats happen with -i option – user1953864 Jan 8 '13 at 4:19
On Linux, at least, the / at the end is optional. You can include it if you want, but it’s not necessary. – Scott Jan 8 '13 at 4:20
@user1953864: -i (or -J) specify a token that will be replaced with the incoming arguments, instead of them just being tacked onto the end. man xargs – Amadan Jan 8 '13 at 4:23
You might need to say -i{}, without a space. Or say -I {}. – Scott Jan 8 '13 at 4:52
@dmonopoly: They don't mean anything. Whatever the parameter to -i is, it is getting replaced. ls file_* | xargs -iFOO mv FOO temp/ works exactly the same. – Amadan Jun 16 at 3:40

find . -name "file_*" -maxdepth 0 -exec mv {} temp/ \;

find is better than ls where there might be more files than the number of program arguments allowed by your shell.

share|improve this answer
Note that the question suggests a desire to process only the file_* files in the current directory, while find (without additional options) will search the entire directory tree under the current directory. – Scott Jan 8 '13 at 4:20
Yes, true. Add -maxdepth 0 to prevent this. – David-SkyMesh Jan 8 '13 at 4:22
"better" is subjective. More powerful, more complex, and slower; and while mv doesn't care if you process files together or individually, some other uses might. – Amadan Jan 8 '13 at 4:25
Edited (added -maxdepth 0) – David-SkyMesh Jan 8 '13 at 7:13

Use -t "specify target directoty" at mv, it should work moving files* to destination directory /temp

ex:- #ls -l file* | xargs mv -t /temp

share|improve this answer

as suggested by @user1953864: {-i, -J} specify a token that will be replaced with the incoming arguments.

For example ls:  readme someDirectory/

Then to move all java files into the someDirectory folder with xargs would be as follows:

On Linux

ls *.java | xargs -i mv {} someDirectory/

On Mac

ls *.java | xargs -J mv {} someDirectory
share|improve this answer

Another solution might be:

 for f in file_* ; do
   mv $f temp/$f

The disadvantage is that it forks a new mv process for each file.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.