cp command not working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cp command not working
# 1  
Old 02-21-2010
cp command not working

Hi Guys,

I have about 12000 files in a folder and I want to copy these to another folder. I am using the cp command to do this but it errors out saying cp -- argument list too long.

Is there any way to get around this?

I don't want to do a mv but use only cp.

Thanks
# 2  
Old 02-21-2010
Please post exactly what you typed and the exact error message you received. Knowing you Operating System and Shell would also help.
# 3  
Old 02-21-2010
Try tar

I use tar to move large directories around...use standard input and output:

Code:
tar cvf - .|(cd $DDIR;tar xf -)

Of course this will copy the entire directory. To only move certain files:
Code:
tar cvf - .$FILESPEC|(cd $DDIR; tar xv - )

This is where $DDDIR uis your destination directory and $FILESPEC is the filename specifications (you can use * to expand filenames).

Last edited by Scott; 02-21-2010 at 07:34 PM.. Reason: Added code tags
# 4  
Old 02-21-2010
Sorry to be rude, but I repeat.

Please post exactly what you typed and the exact error message you received. Knowing you Operating System and Shell would also help.

Geekasaurus post can be ignored because is uses erroneous syntax for irrelevant commands.
# 5  
Old 02-21-2010
The cp command

The cp command does not work for directories with large number of files in them. I don't know what the upper limit is; I could probably find out with a lot of research. Also, the mv and rm commands do not work either under the same circumstance.

I suspect that the upper limit of the number of files that it can work on is 65536. I know that it is greater than 10,000 and less than 100,000. The 65536 is a SWAG number based on 26 years of Unix shell-scripting experience.

A number of years ago, our data warehouse people left more than 4194304 million small files in a single directory. I don't know exactly how many, but they used the entire inode table and its size was set at 4194304 per filesystem (hpux 11.0). I had to reboot the system from CDROM, alter the boot parameters and mount the offending filesystem to the RAM image. Only then could I descend the directory tree and find the overfilled directory. As the OP said, the cp command does not work on directories with that many entries in it. Neither do the rm or mv commands.

I cleaned up the filesystem by removing files. I had to use a for-do-done loop and remove only one file at a time; this took many hours.

The shell being used does not matter. Neither does the OS (particularly). It is the same cp command (or rm, or mv) regardless of the shell.

The tar syntax I quoted is in the man page on my AIX box. I've been using something similar to it for more than 20 years. It works.
# 6  
Old 02-21-2010
Thanks, methyl and Geekasauras.

@methyl,
I did not save the error message and do not have the PC here so I will copy the error message next time I try it on the PC and post it.

@Geekasaurus,
I will try the tar command and see if it works.
# 7  
Old 02-21-2010
Quote:
Originally Posted by Geekasaurus
The cp command does not work for directories with large number of files in them. I don't know what the upper limit is; I could probably find out with a lot of research. Also, the mv and rm commands do not work either under the same circumstance.
It has nothing to do with the rm command. The limit is the size of the buffer that commandline parameters can be fit into. This applies to all commands(except certain shell builtins in certain shells).
Quote:
I suspect that the upper limit of the number of files that it can work on is 65536. I know that it is greater than 10,000 and less than 100,000. The 65536 is a SWAG number based on 26 years of Unix shell-scripting experience.
It is a "swag number" because it's a power of two, which memory is often allocated based on. It's the maximum size of the buffer for commandline arguments per process, and system-dependent.
Quote:
I cleaned up the filesystem by removing files. I had to use a for-do-done loop and remove only one file at a time; this took many hours.
You may have been interested in the xargs command. It converts things read on stdin into commandline arguments, spanning across as many executions as necessary.
Code:
# Delete everything in ./dir_containing_files
find ./dir_containing_files -type f -print0 | xargs --null rm

Quote:
The tar syntax I quoted is in the man page on my AIX box. I've been using something similar to it for more than 20 years. It works.
It works in certain situations, yes. It will probably do what the OP wants. I have my doubts that "$FILESPEC" is working the way you think it is though -- either that or AIX has a very strange implementation of tar...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute ssh command with additional terminal command to any remote user not working script

Hello i am having an issue with bash script and this is the code now=$(cat hosts1.txt | awk '{print $2;}') while read n ;do ssh root@$now 'useradd test1; echo -e "test1\ntest1" | passwd test1 && echo "test1 ALL=(ALL:ALL) ALL" >> /etc/sudoers' When i execute only part with cat, it... (8 Replies)
Discussion started by: tomislav91
8 Replies

2. UNIX for Dummies Questions & Answers

Shell script not working but command works in command prompt

Hi everyone I have a problem with my script If I try directly this command /usr/bin/nice -n 19 mysqldump -u root --password="******" wiki_schneider -c | nice -n 19 gzip -9 > /point_de_montage/$(date '+%Y%m%d')-wiki-db.sql.gz It works But if I simply add this command in a script and... (8 Replies)
Discussion started by: picemma
8 Replies

3. Shell Programming and Scripting

Maxdepth command not working in AIX.Need alternative solution for this command

Hi All, I am trying to select 30 days older files under current directory ,but not from subdirectory using below command. find <Dir> -type f -mtime + 30 This command selecting all the files from current directory and also from sub directory . I read some documention through internet ,... (1 Reply)
Discussion started by: kommineni
1 Replies

4. Shell Programming and Scripting

Working of command

What does the command do lpr -Pqpr *.jpg do ? (1 Reply)
Discussion started by: Nabeel Nazir
1 Replies

5. Shell Programming and Scripting

help with shell script: cp command not working, but mv command works...

Hello. I would like to ask your help regarding the cp command. We are using a cp command to create a back-up copy of our file but to no avail. It's just not working. We already checked the file and directory permissions and all seems correct. We have a script (ftp.script) which calls on... (1 Reply)
Discussion started by: udelalv
1 Replies

6. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi hc.sh "hc.sh" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

7. UNIX for Advanced & Expert Users

command for recently modified files - "find" command not working

I have three files a.txt , b.txt , c.txt in a directory called my_dir1 .These files were created before two or three months . I have a tar file called my_tar1.tar which contains three files a.txt , b.txt , d.txt . Somebody untarred the my_tar1.tar into my_dir1 directory. So existing two files were... (1 Reply)
Discussion started by: joe.mani
1 Replies

8. Shell Programming and Scripting

Here command not working

The below is a simple script, but doesnt work. #!/bin/ksh cat <<XYZ -h help -T Test (required) -D Develop (required) XYZ Help is appreciated (5 Replies)
Discussion started by: pinnacle
5 Replies

9. Solaris

ls command not working

Hi, I have installed opensolaris 10 in VMware. Everything is fine except ls command is not working. It is not displaying any files and directories. Sorry if the question is soo trivial. (8 Replies)
Discussion started by: mayahari
8 Replies

10. Solaris

last command not working

I have a Solaris 8 Ultra 1 on my network that we use as a utility server. The last command, which looks in the /var/adm/wtmpx file, is not working. When I do a last, the latest entry is dated June 3, but the /var/adm/wtmpx file is dated whenever a login is successful (verified by typing a... (3 Replies)
Discussion started by: antalexi
3 Replies
Login or Register to Ask a Question