mv : Argument list too long


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting mv : Argument list too long
# 8  
Old 05-13-2013
Quote:
Originally Posted by MadeInGermany
But the error message looks like there is a bug either in xargs or in mv. Or you have a filename with a * character.
I don't think there is any error message. The first post states that find-xargs is used to avoid it and that the problem is preventing a descent into subdirectories.

I think this is a case of a poorly titled thread.

Regards,
Alister

---------- Post updated at 04:22 AM ---------- Previous update was at 04:11 AM ----------

Quote:
Originally Posted by MadeInGermany
But with find | xargs it's not the shell.
Either xargs does not know the system limit or mv has a smaller limit than the system.
Neither makes sense since the OP's xargs -i passes only one argument per mv.

Ignore the thread title and re-read the first post. I think you've been mislead.

Regards,
Alister

---------- Post updated at 04:38 AM ---------- Previous update was at 04:22 AM ----------

Quote:
Originally Posted by MadeInGermany
BTW {} should be quoted "{}". This will handle most special characters alright.
Those quotes will not make any difference at all.

xargs will never see them, since the shell will consume them.

To the shell, they are pointless because {} is nothing special (not even to shells which perform brace expansion, which only do so when there's an unquoted comma within the braces).

Regards,
Alister
These 2 Users Gave Thanks to alister For This Post:
# 9  
Old 05-13-2013
Thank you all for your quick responses...
alister is right.
"More importantly, the solution is incorrect. If ../<<Your Directory>> itself contains a directory named <<Your Directory>>, it will not be pruned since -name only looks at the basename. "
and Skrynesaver's approach works fine...
Littele more help here....
going forward in script i have specified condition that If directory2 is having files in it then tar those file... code snippet looks like as follows
Code:
if [ "find directory2/*.*" ] 
 then
          tar -czvf $2.tar.gz directory2
          mv $2.tar.gz directory3
         for i in $1/wrk/*
        do if [ -f $i ]
        then
                 rm $i
        fi
        done

problem here i am facing is when there are no files in directory2 it is still creating tar file. is there any alternative to that?
P. S.: we are using "find" because using "ls" will result in again "argument list too long error"
If there are no files under directory2 i strictly dnt want to create tar file for the same...
# 10  
Old 05-13-2013
The reason that code doesn't complain about too many arguments is because it does absolutely nothing at all, it doesn't run find, it doesn't expand *, nothing, nada, zip. *.* is a DOS thing by the way, not a UNIX one.

The way to avoid too many arguments is to not experiment with quotes and find and backticks until you find a way that stops complaining when you jam too many arguments in the shell... If you find a way that probably means you broke it, because too many arguments is too many arguments no matter how you cut it. The way to avoid too many arguments is to not jam too many arguments into the shell.

Here I limit find's output to one filename, which should do it:

Code:
if [ -f "`find directory2 -type f | head -n 1`" ]
then
...
fi

This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Argument list too long

Hi Team, Here's the situation. I have approximately 300000 to 500000 jpg files in /appl/abcd/work_dir 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... (14 Replies)
Discussion started by: kmanivan82
14 Replies

2. 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

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