Discussion Locked

Copying files in UNIX

0 helpful
13 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have Folder1 with 12000 files in that folder.
I can easely copy all files from this folder to another folder using commands:

su
Password: xxxx
cp ./Folder1/* ./Folder2/

I created a script in csh - "copyFiles",
again :
su
Password: xxxx

then I use "exec" command to run script in the same shell:
exec copyFiles
it copies portion of Folder1 and gives me an error
"Argument too long"
What I'm doing wrong?

Thanks

13 replies

by jaqui

first, why are you having to copy as su?
insanely high risk, you can copy without the su, as long as copying to a directory that doesn't need su priveledges to write.

with 1200 files in original directoy, the script is passing 1200 arguments to the command cp

see if you can edit the csh config to increase argument capability from scripts. might be built in
to csh to limit argument from scripts as a security measure.
I use bash myself, and haven't had this error show up.

by camille.savoie

DEALING WITH TOO MANY FILES

In case there are too many files in a
particular directory and you try doing

$ grep "ABC" *

And it fails saying
ksh: /usr/bin/find: 0403-027 The parameter list is too long.

what would you do?

Well you can do the following:

$ls |xargs grep "ABC"

The same approach could be taken when attemptung to copy files.

Under AIX you can use the getconf ARG_MAX to find out how many arguments can be passed to any command.
Under AIx 5.2 it is set to 24576.

I hope this is helpful

by ghislain.levesque

cd fromdir; tar cf - . | (cd todir; tar xfBp -)
or
cp -rp from_dir to_dir
That way, you will keep the owner, file perm & group....

by todd

You can also use the find command, which, like the above example using "xargs" will parse the directory tryy one file at a time and avoid the "arg" limit of the shell:

use something similar to:

find ./Folder1/* -exec cp {} ./Folder2/ \;

-cheers

This discussion is closed to new replies.