I am trying this and it's not working:
ls file_* | xargs mv {} temp/
Any ideas?
I am trying this and it's not working:
ls file_* | xargs mv {} temp/
Any ideas?
On OS X:
ls file_* | xargs -J {} mv {} temp/
On Linux:
ls file_* | xargs -i {} mv {} temp/
Use -t "specify target directoty" at mv, it should work moving files* to destination directory /temp
ex:- #ls -l file* | xargs mv -t /temp
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.
As suggested by @user1953864: {-i, -J} specify a token that will be replaced with the incoming arguments.
For example ls:
something.java exampleModel.java NewsQueryImpl.java 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 MacOS
ls *.java | xargs -J mv {} someDirectory
Another solution might be:
for f in file_* ; do
mv $f temp/$f
done
The disadvantage is that it forks a new mv process for each file.