Re: cp list of files into another directory



On 08 May 2006 17:09:13 GMT
Stephane Chazelas <stephane_chazelas@xxxxxxxx> wrote:

On 8 May 2006 08:52:56 -0700, Sashi wrote:

pawan_test wrote:
Hi All,

i am trying to copy files from a directory to another.
here is what I am doing
ls -ltr INTER*
THE output is list of 80 files.

i have to copy all these 80 files into another directory
( say /home/pavi/folder) at a time.
can anyone please suggest me how do I do it.

thanks
pavi

If the file names do not contain spaces, a simple cp command would do:
cp INTER* /destination/directory/name/.
[...]

Whether the file names contain spaces or not will make no
difference (why would it?).

It may fail if the list of files, combined with the other
arguments and the environment is too big and reaches the systems
limit for the execve(2) system call.

In that case, you can do:

ls | sed -n '/^INTER/s/./\\&/gp' | xargs sh -c '
shift "$1" && exec cp "$@" /destdir' 2 1

(fails if file names may contain newline characters)

Or

find . \! -name . -prune -name 'INTER*' -exec sh -c '
shift "$1"
exec cp "$@" /destdir' 2 1 {} +

Or (but it runs a cp for every file):

for f in INTER*; do
cp "$f" /destdir
done

And people say UNIX is difficult to use...
:)

--
Magnus
.



Relevant Pages

  • Re: cp list of files into another directory
    ... ls -ltr INTER* ... It may fail if the list of files, ... (fails if file names may contain newline characters) ... shift "$1" ...
    (comp.unix.shell)
  • Re: OT - STOP Scientology
    ... But as I assume we are all against Narcon the Drug rehab Scientology front ... religion as required by the recent EU ruling. ... and by accepting scientology it puts cantheism well on the road to ...
    (uk.politics.drugs)
  • Re: Redirecting stdout of running program
    ... and for fairly good reasons. ... operations specific to that type later fail. ... philosophy includes giving us sharp tools, and leaving it up to us to ... Unix way. ...
    (comp.os.linux.development.system)
  • Re: 1905 Einsteins Relativity&Potential Energy
    ... > Therefore, according to you, Langevin's derivation would fail. ... Red doppler shift would fail, ...
    (sci.physics)
  • Re: 1905 Einsteins Relativity&Potential Energy
    ... > Therefore, according to you, Langevin's derivation would fail. ... Red doppler shift would fail, ...
    (sci.physics.relativity)