Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to replicate a branch, and copy only files maching a regex in that branch

1 view
Skip to first unread message

Chris Roy-Smith

unread,
Dec 21, 2008, 5:23:36 PM12/21/08
to
Hi,
caution, bash beginner here.
I am trying to figure out how to make a new copy
all subdirectories and copy only the contents that
match the expression *.ogg.

cp -R /source/*.ogg /target/

does not work, I figure that this may be because some
directories only contain subdirectories

I have experimented with looping like this:

for arg in $(ls -R /source/ | grep .ogg);
do
echo $arg;
done

but this only lists the files and not their paths

Thanks for your help
Chris Roy-Smith

Bill Marcum

unread,
Dec 21, 2008, 6:06:43 PM12/21/08
to
On 2008-12-21, Chris Roy-Smith <chris_r...@internode.on.net> wrote:
>
>
> Hi,
> caution, bash beginner here.
> I am trying to figure out how to make a new copy
> all subdirectories and copy only the contents that
> match the expression *.ogg.
>
> cp -R /source/*.ogg /target/
>
> does not work, I figure that this may be because some
> directories only contain subdirectories
>
It doesn't work because the shell expands wildcards, so the cp command
only gets the names of .ogg files in /source. You could do something
with find /source -name '*.ogg'

--
"Corrupt politicians make the other ten percent look bad."
__Henry A. Kissinger

Peter D.

unread,
Dec 22, 2008, 1:15:30 AM12/22/08
to
on Monday 22 December 2008 10:06
in the Usenet newsgroup alt.os.linux.mandriva
Bill Marcum wrote:

> On 2008-12-21, Chris Roy-Smith <chris_r...@internode.on.net> wrote:
>>
>>
>> Hi,
>> caution, bash beginner here.
>> I am trying to figure out how to make a new copy
>> all subdirectories and copy only the contents that
>> match the expression *.ogg.
>>
>> cp -R /source/*.ogg /target/
>>
>> does not work, I figure that this may be because some
>> directories only contain subdirectories
>>
> It doesn't work because the shell expands wildcards, so the cp command
> only gets the names of .ogg files in /source. You could do something
> with find /source -name '*.ogg'

Exactly correct.

It should be more obvious to the OP what is going on if he types,
ls /source/*.ogg


--
sig goes here...
Peter D.

Michael Schindler

unread,
Dec 22, 2008, 5:41:48 AM12/22/08
to
Chris Roy-Smith wrote:

try this:

find /source -name "*.ogg" -print0 | xargs -0 tar cf - | tar -C /target -xvf

Maxwell Lol

unread,
Dec 22, 2008, 6:17:47 AM12/22/08
to
"Peter D." <p...@live.home.invalid> writes:

>> It doesn't work because the shell expands wildcards, so the cp command
>> only gets the names of .ogg files in /source. You could do something
>> with find /source -name '*.ogg'
>
> Exactly correct.
>
> It should be more obvious to the OP what is going on if he types,
> ls /source/*.ogg

I always tell then to use "echo"
echo /source/*.ogg

0 new messages