Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Copy maximum

Posted on 2001-06-26
1
Medium Priority
?
192 Views
Last Modified: 2010-04-20
sometimes when I use the cp command to copy files, I get the error code agument list too long.

This happens when I'm using
(1)> cp dira/* dirb/

I can copy the files recursively by using
(2)> cp -r dira/ dirb/
but the files will go to directory "dira/dirb/"

Of course there are many ways to get the files from "dira" to "dirb". Copying them with a script or using other stupid tricks, but my question is, why is there a maximum number for the command (1). And maybe someone has an elegant way to avoid this.
I'm using SUSE.Linux 6.0
0
Comment
Question by:JWTtheTh
1 Comment
 
LVL 40

Accepted Solution

by:
jlevie earned 300 total points
ID: 6227478
That's a limitation of the shell, not the cp command. When you use wildcards like that the shell expands the wildcard into a list of filenames that it passes to the command. If the wildcard expands to a large number of items the internal buffer in the shell can be filled and the command truncated.

A better way of copying large directories is to use tar in a pipe, like:

# cd dira
# tar cf - . | (cd /path-to/dirb; tar xvf -)
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

971 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