xargs problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting xargs problem
# 1  
Old 11-07-2004
xargs problem

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.
# 2  
Old 11-07-2004
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.
Code:
while read line
do
  mv $dir1/$line $dir2/$line
done < /my/list/of/files

Just my two pence though!

Cheers
ZB
# 3  
Old 11-07-2004
Just tested the code for problem 2

Thanks once again :0
# 4  
Old 05-16-2009
4.5 years later, still good Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with xargs

I entered the following <zzz.list xargs showtell |more which does a echo "<<<<<<<<<<<<<<<<<<<<<<<<< $1 >>>>>>>>>>>>>>>>>>" head -20 $1 The file zzz.list contains 525 lines representing user scripts (1 per line), but only the first, 181st, and 399th lines were processed. What am I missing? TIA (2 Replies)
Discussion started by: wbport
2 Replies

2. Shell Programming and Scripting

Problem using xargs with rm

I am trying to call xargs, however rm is complaining find . -maxdepth 1 -name "*tests*" -print0 | xargs -0 rm rm: missing operand Try `rm --help' for more information. (3 Replies)
Discussion started by: kristinu
3 Replies

3. Shell Programming and Scripting

Help with xargs

Using the bash shell I'm trying to either create a command for the command line or a script that will show netstat info for a given process name. Here is an example of what I'm trying to do:$ ps aux |grep catalina |grep -v grep | awk '{print $2}' 5132 $ netstat -nlp |grep 5132 (Not all processes... (11 Replies)
Discussion started by: axiopisty
11 Replies

4. Shell Programming and Scripting

piping problem with xargs

I'm trying to pipe the output from a command into another using xargs but is not getting what I want. Running this commands: find . -name '33_cr*.rod' | xargs -n1 -t -i cut -f5 {} | sort -k1.3n | uniq | wc -l give the following output: cut -f5 ./33_cr22.rod cut -f5 ./33_cr22.rod ... 9224236... (7 Replies)
Discussion started by: ivpz
7 Replies

5. Shell Programming and Scripting

Help with xargs

hi Could any one please tell me the option using which we can run multiple commands using xargs I have list of files, I want to run dos2unix and chmod at one shot on them I tried google n searched man pages but couldnt really find the solution , please help right now im doing this ls... (4 Replies)
Discussion started by: sunilmenhdiratt
4 Replies

6. Shell Programming and Scripting

xargs command problem

Hi I am trying to use "xargs" command to loop through each file, modify it and overwrite the old file with the modification but with the same file name. I thought it is easy but I just can't get it to work I tried the following I thought {} would give me the current file name, but it... (1 Reply)
Discussion started by: tiger66
1 Replies

7. Solaris

Problem in using wildcard characters in xargs with find

Hi, Under my parent diectory I have directory named "Response" in many of its subfolders. I am interested to see all files with extention .pro in Response Directory. I am giving following command - find . -name "Response" -type d | xargs -i ls -lrt {}/*.pro but it is not giving result. ... (3 Replies)
Discussion started by: sanjay1979
3 Replies

8. UNIX for Dummies Questions & Answers

problem with grep in combination with xargs

Dear all, I have tried the following 2 lines xargs -t -i -exec grep -i -w {} file_1 >>test < file_2 cat -s file_2| xargs -t -i -exec grep -i -w {} file_1 >> test They were meant to search for the contents of file_2 in file_1 and write the respective lines of file_1 into file "test" .... (15 Replies)
Discussion started by: Bruno
15 Replies

9. Shell Programming and Scripting

problem with "xargs rm -i"

Hi, I could not understand why the following command does not work find . -name "foo" | xargs rm -i but, find . -name "foo" | xargs rm works perfectly alright. (3 Replies)
Discussion started by: royalibrahim
3 Replies

10. Shell Programming and Scripting

Problem using find and xargs

I'm using Imagemagick to create thumbnails for a large directory tree. The only thing I can't see is how to get it to write the thumbnails to a "thumbs" subdirectory! Either of these two commands from the Imagemagick site does most of the job: find -name '*.jpg' | xargs -n1 sh -c 'convert $0... (5 Replies)
Discussion started by: quixote
5 Replies
Login or Register to Ask a Question