General discussion

Locked

Copying files in UNIX

By dodik ·
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

This conversation is currently closed to new comments.

13 total posts (Page 1 of 2)   01 | 02   Next
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by Jaqui In reply to Copying files in UNIX

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.

Collapse -

by dodik In reply to

Poster rated this answer.

Collapse -

by camille.savoie In reply to Copying files in UNIX

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

Collapse -

by dodik In reply to

Poster rated this answer.

Collapse -

by Gary_W In reply to Copying files in UNIX

I answered this question before from you, and you accepted it:

http://techrepublic.com.com/5208-6239-0.html?forumID=37&threadID=166396&start0

Anyway, never hardcode the root password in a shell script! Obvious security risk!

Gary

Collapse -

by dodik In reply to

Poster rated this answer.

Collapse -

by ghislain.levesque In reply to Copying files in UNIX

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....

Collapse -

by dodik In reply to

Poster rated this answer.

Collapse -

by todd In reply to Copying files in UNIX

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

Collapse -

by dodik In reply to

Poster rated this answer.

Back to Linux Forum
13 total posts (Page 1 of 2)   01 | 02   Next

Related Discussions

Related Forums