Hi
From the xargs man page (Solaris):
ls $1 | xargs -I {} -t mv $1/{} $2/{}
This would move all the files in directory $1 to directory $2
Problem 1:
In a shell script if I want to move files in d1 to d2
dir1=~/d1
dir2=~/d2
ls $dir1 | xargs -I {} -t mv $dir1/{} $dir2/{}
does not work......
Problem 2:
The idea is to move yesterday's file in dir1 to dir2
I have got all the yesterday's files in a variable called files
ls $files | xargs -I {} -t mv $dir1/{} $dir2/{}
produces - /usr/bin/ls -arg list too long
What am I missing???
Regards
enc.
For problem 1, the following works for me (under Linux)
ls -1 $dir1 | xargs -i -t mv $dir1/{} $dir2/{}
Should work in solaris too (-i and -I are equivalent - you don't need the {} after -i either as this is assumed as default).
When you say "does not work..." in what way does it not work, what error output is there, etc.
With Problem 2 - you are expanding the contents of "$files" which contains more filenames (i.e. arguments) than ls can handle (the sort of thing xargs was designed to combat!).
I think you'd be better off dropping the xargs approach altogether with this problem, and generate a file containing the list of filenames. Then just use a while loop to iterate through, e.g.
while read line
do
mv $dir1/$line $dir2/$line
done < /my/list/of/files
Just my two pence though!
Cheers
ZB
Just tested the code for problem 2
Thanks once again :0
4.5 years later, still good 