Argument list too long


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Argument list too long
# 1  
Old 11-12-2014
Argument list too long

Hi Team,

Here's the situation.
I have approximately 300000 to 500000 jpg files in /appl/abcd/work_dir
Code:
mv  /appl/abcd/work_dir /appl/abcd/process_dir

The above move command will work if the jpg files count is close to 50000 (not sure). If the count is less this mv command holds good. But if the files count is relatively high, the mv command fails by throwing following error message.
Code:
ksh :/bin/mv: Argument list too long

but using the following command, it works
Code:
find ./appl/abcd/work_dir -name -type f -name "*.vgx" -exec mv -f {} /appl/abcd/process_dir \;

Can anyone please let us know how to handle this situation?

Thanks
Krishna
Moderator's Comments:
Mod Comment With 9 formal warnings and infractions, it is obvious that you don't care about the forum rules, and you expect the forum moderators to clean up your posts for you. Enough is enough. Your account has been set to read-only status for three days. Continued refusal to use CODE tags may result in a permanent ban.

Last edited by Don Cragun; 11-12-2014 at 05:00 PM.. Reason: Add CODE and ICODE tags.
# 2  
Old 11-12-2014
If you get this, use xargs:
Code:
ls | xargs -n101 echo | while read l
do
 mv $l dest
done

Now, with more reading of man xargs, you can find ways to have xargs do the mv, putting the list into the middle of the mv command.
# 3  
Old 11-12-2014
I am presuming your original command was something like:
Code:
mv /appl/abcd/work_dir/*.vgx /appl/abcd/process_dir

Otherwise you would not get that error message.

You are get the message because *.vgx first gets expanded to file1.vgx file2.vgx .... filen.vgx and passed as parameters to the mv command .
Depending on your OS limit at some point that would exceed the ARG_MAX limit or a similar limit for your OS.

Last edited by Scrutinizer; 11-12-2014 at 05:45 PM..
# 4  
Old 11-12-2014
How does find set his limit, I wonder? Early xargs was buffer capped at 480 bytes, but that was for way back systems. Smilie

Man find says see xargs, man xargs says try for 128K or the argument length limit for exec, less the size of your environment, less 2048 bytes of headroom -- whichever is less; man exec says, well, it gets fuzzy. I wonder if the three are still in sync? https://www.unix.com/man-page/linux/2/execve/

I wrote a few xargs enhancements a fxargs2, where the limit is something like 1K args or 256K of text (how much economy of scale do you want, and why wait to start?), runs are concurrent with subsequent arg collection and if the input blocks, the args accumulated are fired off. Of course, if you are deeper into chaos, there is GNU parallel. However, there will be a grand fight over the target directory inode control!

Last edited by DGPickett; 11-12-2014 at 05:59 PM..
# 5  
Old 11-12-2014
You could also try:

Code:
find ./appl/abcd/work_dir -name -type f -name "*.vgx" -execdir mv -f -t /appl/abcd/process_dir -- {} +

Which will batch up as many filenames onto the mv command as the commanline size will allow. This is more efficient as you don't end up executing mv once for each file to be moved.

Last edited by Chubler_XL; 11-12-2014 at 05:56 PM..
# 6  
Old 11-12-2014
I think there is two times the same problem.
Code:
ls | xargs -i echo mv -f {} /appl/abcd/process_dir

invokes mv for each argument.
It works with GNU mv -t where you can append the arguments:
Code:
ls | xargs -n101 echo mv -f -t /appl/abcd/process_dir

And you need the invokation for each argument with find:
Code:
find ./appl/abcd/work_dir -type f -name "*.vgx" -exec echo mv -f {} /appl/abcd/process_dir \;

Again, with mv -t you can have the {} at the end and the + works.
Code:
find ./appl/abcd/work_dir -type f -name "*.vgx" -exec echo mv -f -t /appl/abcd/process_dir {} +

Remove the echo to really execute!
This User Gave Thanks to MadeInGermany For This Post:
# 7  
Old 11-12-2014
@DGPickett:
With -exec cmd ... {} + it cuts the argument into chunks that are lower than the limit. But that is not usable here since the + -sign must appear at the end, right after the curly braces..

With -exec cmd ... \; the curly braces can be put anywhere, but the arguments are passed to the command one at a time, which can be slow..


--
@MadeinGermany: thanks for the GNU mv -t option with which the + can be used after all (but GNU mv needs to be present)..

Last edited by Scrutinizer; 11-12-2014 at 05:58 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Argument list too long w/ sed

Hi all, I am using GNU sed (named gsed under macports) in OSX. I have a directory with a series of files named pool_01.jpg through pool_78802.jpg. I am trying to use this command to rename the files to their checksum + extension. md5sum * | gsed -e 's/\(*\) \(.*\(\..*\)\)$/mv -v \2 \1\3/e' ... (3 Replies)
Discussion started by: openthomas
3 Replies

2. Shell Programming and Scripting

mv : Argument list too long

Hi I am using find command -- find "directory1" -type f | xargs -i mv {} "directory2" to avoid above argument list too long problem. But, issue i am facing is directory1 is having subdirectories due to this i am facing directory traversal problem as i dont want to traverse subdirectories... (9 Replies)
Discussion started by: VSom007
9 Replies

3. Shell Programming and Scripting

grep : Argument list too long

Hi, i am having some trouble with the below command, can some one suggest me the better way to do it. grep -l 'ReturnCode=1' `find $Log -newer /tmp/Failed.tmp -print | xargs ls -ld | egrep SUB | egrep -ve 'MTP' -ve 'ABC' -ve 'DEF' -ve 'JKL' -ve 'XYZ' | awk '{print $9}'` > $Home1 Its... (2 Replies)
Discussion started by: Prateek007
2 Replies

4. Shell Programming and Scripting

Argument list too long!!

Dear Experts, I have a list of 10K files in a directory. I am not able to execute any commands lile ls -lrt, awk, sed, mv, etc........ I wanna execute below command and get the output. How can I achieve it?? Pls help. root# awk -F'|' '$1 == 1' file_20120710* | wc -l /bin/awk: Argument list... (2 Replies)
Discussion started by: Naga06
2 Replies

5. Shell Programming and Scripting

Argument list too long for date command

Dear Friends, The following script processes a 14508 lines log file. #!/bin/sh while read line do d=`sed 's/* - * \*\/*\/* *\)\] .*/\1/' | tr '/' ' ' | sed 's/\(*\):\(*\)/\1 \2/'` y=`date -d "${d}" "+%Y%m%d%H%M%S"` echo "${y}" done While running the above script, I am... (4 Replies)
Discussion started by: tamil.pamaran
4 Replies

6. Shell Programming and Scripting

Argument list too long problem

I have a huge set of files (with extension .common) in my directory around 2 million. When I run this script on my Linux with BASH, I get /bin/awk: Argument list too long awk -F'\t' ' NR == FNR { a=NR } NR != FNR { sub(".common", "", FILENAME) print a, FILENAME, $1 } '... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

7. UNIX for Dummies Questions & Answers

Argument list too long for Sed command

Hi guys Following command results in sed -i 's/#/\\#/g' /home/test/sqlstents* -bash: /bin/sed: Argument list too long Please help me solve it.. is there any other way i can do this?.. thanks (4 Replies)
Discussion started by: depakjan
4 Replies

8. Shell Programming and Scripting

Argument too long list error

I have a wrote a script which consits of the below line.. Below of this script I'm getting this error "ksh: /usr/bin/ls: arg list too long" The line is log_file_time=`ssh -i $HOME/.ssh/id_rsa -q $i ls -lrt /bp/karthik/test/data/log/$abc*|tail -1|awk '{print $8}'` And $abc alias is as "p |... (1 Reply)
Discussion started by: 22karthikreddy
1 Replies

9. UNIX for Dummies Questions & Answers

Argument list too long - SSH

Hi I executed the code for file in `ls pdb*.ent` do new_name=`echo $file | sed 's/^pdb//;s/.ent/.txt/'` mv $file $new_name done Its giving error at ' ls pdb*.ent' argument list too long i have around 150000 entries please help Thank you (6 Replies)
Discussion started by: empyrean
6 Replies

10. Shell Programming and Scripting

Argument list too long - Shell error

Trying to tar specific files from a directory causes problems when the number of files is too large. ls ~/logs | wc -l 5928 In the logs directory - I have 5928 files If I want to include all files with today's date - I run the following command tar cf ~/archive/LoadLogs_20060302.tar... (8 Replies)
Discussion started by: dad5119
8 Replies
Login or Register to Ask a Question