LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-06-2016, 03:00 AM   #1
avyadav555
LQ Newbie
 
Registered: Apr 2016
Posts: 20

Rep: Reputation: Disabled
Argument list too long


hi..
Iam trying to move some files into another directory but gettin "Argument list too long" error
how can I resolve it

ex:
# mv -v *.zip /mnt/directory
 
Old 12-06-2016, 03:23 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 15,087

Rep: Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957
try:
mv -v a*.zip /mnt/directory
find . -name \*.zip -exec mv {} /mnt/directory \;
use perl/python
 
1 members found this post helpful.
Old 12-06-2016, 12:21 PM   #3
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,454

Rep: Reputation: 664Reputation: 664Reputation: 664Reputation: 664Reputation: 664Reputation: 664
A bit more efficient than
Code:
find . -name \*.zip -exec mv -v {} /mnt/directory \;
is
Code:
find . -name \*.zip -exec mv -v -t /mnt/directory {} +
 
2 members found this post helpful.
Old 12-07-2016, 11:04 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,790

Rep: Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538
I'm not sure OP wants recursion, so skipping 'find' (although you could use -maxdepth)
Code:
for file in $(ls|grep '\.zip')
do
    mv $file /mnt/directory
done
 
2 members found this post helpful.
Old 12-08-2016, 12:05 AM   #5
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 15,087

Rep: Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957
I'm not really sure if $(ls|grep '\.zip') was really correct, but you can use simply *.zip instead. And also I'm not really sure if it solves the arg list too long error.
 
1 members found this post helpful.
Old 12-08-2016, 12:31 AM   #6
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,237

Rep: Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655
There are plenty of one liners but sometimes I like to throw a more easily loggable process into the mix. Especially if it is an enormous list of files that will take many hours to copy/move. I like to have a record. So if that is how you would like to approach it:

Get the filelist to operate on (adjust to fit need):
Code:
find . -name \*.zip > filelist
Make a shell script to move a file at a time from the filelist and record all output to 'results'.

I like to use 'cp' to test my script logic, and then change it to 'mv' once I know it is working as expected. So this script will only COPY. Change the command to MOVE them once you like the results.
Code:
set -x
while read -r filename
do
cp -v $filename /mnt/directory/ >> results 2>&1
done < filelist
Make the script executable and run the script and capture all of its output as well.
Code:
chmod +x script.sh
./script.sh | tee script.out

Last edited by szboardstretcher; 12-08-2016 at 12:39 AM.
 
1 members found this post helpful.
Old 12-08-2016, 12:57 AM   #7
c0wb0y
Member
 
Registered: Jan 2012
Location: Inside the oven
Distribution: Windows
Posts: 417

Rep: Reputation: 74
While (no pun intended) doing an iteration might work and copy file one-at-a-time, why don't we batch copy it such as MadeInGermany's post

Quote:
find . -name \*.zip -exec mv -v -t /mnt/directory {} +
Also, 'find' info page shows a lot of useful info such as the one below I shamelessly copied:

Quote:
find /foo -maxdepth 1 -atime +366 -print0 | xargs -r0 sh -c 'mv "$@" /archive' move
which one can modify to suit.
 
2 members found this post helpful.
Old 12-08-2016, 01:05 AM   #8
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,237

Rep: Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655
Certainly an option. No argument there.

My option is more geared toward having to copy 45 million zip files while keeping system resources low and having a record of the results.

Reputation for all methods!!
 
Old 12-08-2016, 02:03 AM   #9
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 15,087

Rep: Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957Reputation: 4957
we may try to do a performance test, which one works faster.... but obviously it depends on the type of the filesystem, and also if it moves files onto another filesystem, the number/size of those files, depth of directory structure and .....
 
Old 01-17-2017, 06:04 AM   #10
avyadav555
LQ Newbie
 
Registered: Apr 2016
Posts: 20

Original Poster
Rep: Reputation: Disabled
try this

This command work fine

echo *.zip | xargs mv -t /mnt/directory
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Argument list too long crltzn.staff Linux - Newbie 11 10-19-2016 02:36 PM
Argument list too long ekelly30 Linux - Kernel 11 01-09-2012 10:46 AM
[SOLVED] argument list too long deep27ak Linux - Newbie 5 11-26-2011 03:52 PM
Argument list too long ust Linux - Software 11 10-26-2009 10:16 AM
Argument list too long trutnev Linux - General 3 04-22-2004 04:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 04:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration