Solved

Copy files - Argument list too long

Posted on 2009-07-11
11
1,070 Views
Last Modified: 2013-11-22
I ran this:

cp 1241* /usr/local/virtual/domain.com/mailman/new/

And got the following error:

/sbin/cp: Argument list too long.

Any ideas?
0
Comment
Question by:hrolsons
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 12

Expert Comment

by:Let_Me_Be
ID: 24831895
* is expanded before calling the command. If you have to many files starting with 1241 the argument list might be indeed to long.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24831911
Hi,

use 'find' and 'xargs'. Assuming '/dir' was the directory containing the files, issue

find /dir -type f -name 1241\* | xargs -I{} cp {} /usr/local/virtual/domain.com/mailman/new/

That should do the trick.

wmp
0
 

Author Comment

by:hrolsons
ID: 24831935
woolmilkporc,

What would I put in place of "/dir" if I am already in the directory I'm going to copy files from?
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 12

Expert Comment

by:Let_Me_Be
ID: 24831939

`pwd`

Open in new window

0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24831941
Just a dot ( . )
0
 

Author Comment

by:hrolsons
ID: 24831953

find . -type f -name 1241\* | xargs -I{} cp {} /usr/local/virtual/domain.com/mailman/new
 
xargs: {}: No such file or directory

Open in new window

0
 

Author Comment

by:hrolsons
ID: 24831955
'pwd'???
0
 

Author Comment

by:hrolsons
ID: 24831962
Sorry, pwd is:

/usr/local/virtual/domain.com/all/cur
0
 
LVL 12

Expert Comment

by:Let_Me_Be
ID: 24831970
Its not 'pwd' but `pwd` Anything between `` will be executed and the output will be used in the place where you wrote it.
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 24832002
As for the error - maybe xargs for FreeBSD needs a space between '-I' and '{}'. Try

find . -type f -name 1241\* | xargs -I {} cp {} /usr/local/virtual/domain.com/mailman/new

If that doesn't work neither, try

find . -type f -name 1241\* | xargs -J % cp % /usr/local/virtual/domain.com/mailman/new

..and 'new' should be a directory and must already exist!
 
0
 
LVL 62

Expert Comment

by:gheist
ID: 24832020
cp 1241\* /usr/local/virtual/domain.com/mailman/new/
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question