Index

Subject : Re: LUG: seeking elegant solution

From : Ian Kilgore <imkilgor@ncsu.[redacted]>

Date : Thu, 17 Nov 2011 01:18:54 -0500

Parent


There's no need to use 'ls' for this- some versions & configuration
like to spit out control characters for colours (as Stephen noticed),
and/or other garbage (eg, '*'s after executable files), though most
are clever enough to only do this if their stdout is a terminal.

sh will happily use its own globs (they expand strings, and 'for'
munches on strings). It's less typing anyway:

for I in 2/*; do cp 1/$I 2/$I;done

There's also rsync:

rsync --existing 1/* 2/

On Wed, Nov 16, 2011 at 8:31 PM, Stephen Roller <scroller@ncsu.[redacted]> wrote:
> Slight modification from Alex's post:
>
> for file in $(ls --color=none 2/); do cp 1/$file 2/$file; done
>
> The --color=none might not be necessary, but it was for me. The $ in
> front of the file inside the loop is definitely necessary.
>
> I would make backups of both directories before you do something you can't undo.

--
ik


Replies :