Help!

Copying nested folders


Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> UK RSS
Next:  "Offline files" and Linux  
Author Message
NickNoxx
External


Since: Jul 10, 2007
Posts: 5



PostPosted: Tue Jul 10, 2007 2:33 pm    Post subject: Copying nested folders
Archived from groups: uk>comp>os>linux (more info?)

Hi

I have a number of folders containing various formats of music. I'd like
to be able to copy all the folders containing a file with .mp3 extension
to an appropriately nested folder in another location ie

/music/Compilations/Rebel Music/04 The Russians Are Coming.mp3
should be copied to
/mp3/Compilations/Rebel Music/04 The Russians Are Coming.mp3

whereas

music\Compilations\The Album\1-01 Clint Eastwood.wav
would be left alone

I'm thinking along the lines of:

find /music | grep mp3 |cp $ /mp3

but don't have the scripting skills to get it to work. Can anyone help
please?

Thanks
Back to top
John Taylor
External


Since: Nov 09, 2006
Posts: 46



PostPosted: Tue Jul 10, 2007 2:33 pm    Post subject: Re: Copying nested folders [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

NickNoxx wrote:
> Hi
>
> I have a number of folders containing various formats of music. I'd like
> to be able to copy all the folders containing a file with .mp3 extension
> to an appropriately nested folder in another location ie
>
> /music/Compilations/Rebel Music/04 The Russians Are Coming.mp3
> should be copied to
> /mp3/Compilations/Rebel Music/04 The Russians Are Coming.mp3
>
> whereas
>
> music\Compilations\The Album\1-01 Clint Eastwood.wav
> would be left alone
>
> I'm thinking along the lines of:
>
> find /music | grep mp3 |cp $ /mp3
>

How about:
find ./music -name "*.mp3" | cpio -pudv /mp3

Regards
JohnT
Back to top
NickNoxx
External


Since: Jul 10, 2007
Posts: 5



PostPosted: Tue Jul 10, 2007 5:06 pm    Post subject: Re: Copying nested folders [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

John Taylor wrote:
> NickNoxx wrote:
>> Hi
>>
>> I have a number of folders containing various formats of music. I'd
>> like to be able to copy all the folders containing a file with .mp3
>> extension to an appropriately nested folder in another location ie
>>
>> /music/Compilations/Rebel Music/04 The Russians Are Coming.mp3
>> should be copied to
>> /mp3/Compilations/Rebel Music/04 The Russians Are Coming.mp3
>>
>> whereas
>>
>> music\Compilations\The Album\1-01 Clint Eastwood.wav
>> would be left alone
>>
>> I'm thinking along the lines of:
>>
>> find /music | grep mp3 |cp $ /mp3
>>
>
> How about:
> find ./music -name "*.mp3" | cpio -pudv /mp3
>
> Regards
> JohnT

Would that create the necessary folders, in this case 'Compilations' and
'Rebel Music' if they didn't exist?
Back to top
John Taylor
External


Since: Nov 09, 2006
Posts: 46



PostPosted: Tue Jul 10, 2007 5:08 pm    Post subject: Re: Copying nested folders [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

NickNoxx wrote:
> John Taylor wrote:
>> NickNoxx wrote:
>>> Hi
>>>
>>> I have a number of folders containing various formats of music. I'd
>>> like to be able to copy all the folders containing a file with .mp3
>>> extension to an appropriately nested folder in another location ie
>>>
>>> /music/Compilations/Rebel Music/04 The Russians Are Coming.mp3
>>> should be copied to
>>> /mp3/Compilations/Rebel Music/04 The Russians Are Coming.mp3
>>>
>>> whereas
>>>
>>> music\Compilations\The Album\1-01 Clint Eastwood.wav
>>> would be left alone
>>>
>>> I'm thinking along the lines of:
>>>
>>> find /music | grep mp3 |cp $ /mp3
>>>
>>
>> How about:
>> find ./music -name "*.mp3" | cpio -pudv /mp3
>>
>> Regards
>> JohnT
>
> Would that create the necessary folders, in this case 'Compilations' and
> 'Rebel Music' if they didn't exist?
>

Yes.
p option tells cpio to copy the files
u tells it to copy unconditionally, so will replace any existing files
d tells it to create directories
v is verbose, so you can see what it is doing
Back to top
NickNoxx
External


Since: Jul 10, 2007
Posts: 5



PostPosted: Tue Jul 10, 2007 10:29 pm    Post subject: Re: Copying nested folders [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

John Taylor wrote:

>
> Yes.
> p option tells cpio to copy the files
> u tells it to copy unconditionally, so will replace any existing files
> d tells it to create directories
> v is verbose, so you can see what it is doing

Thanks very much
Back to top
Rikishi 42
External


Since: Oct 27, 2005
Posts: 177



PostPosted: Tue Jul 10, 2007 11:35 pm    Post subject: Re: Copying nested folders [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On 2007-07-10, John Taylor <john RemoveThis @example.com> wrote:

>>> find ./music -name "*.mp3" | cpio -pudv /mp3

>> Would that create the necessary folders, in this case 'Compilations' and
>> 'Rebel Music' if they didn't exist?

> p option tells cpio to copy the files
> u tells it to copy unconditionally, so will replace any existing files
> d tells it to create directories
> v is verbose, so you can see what it is doing

Thank you for teaching me something. Smile


--
There is an art, it says, or rather, a knack to flying.
The knack lies in learning how to throw yourself at the ground and miss.
Douglas Adams
Back to top
Nix
External


Since: Jul 29, 2004
Posts: 680



PostPosted: Tue Jul 10, 2007 11:36 pm    Post subject: Re: Copying nested folders [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On 10 Jul 2007, Rikishi told this:

> On 2007-07-10, John Taylor <john DeleteThis @example.com> wrote:
>
>>>> find ./music -name "*.mp3" | cpio -pudv /mp3
>
>>> Would that create the necessary folders, in this case 'Compilations' and
>>> 'Rebel Music' if they didn't exist?
>
>> p option tells cpio to copy the files
>> u tells it to copy unconditionally, so will replace any existing files
>> d tells it to create directories
>> v is verbose, so you can see what it is doing
>
> Thank you for teaching me something. Smile

Tell you what's unusual: finding anyone using cpio for anything at all.

This sort of thing is what it's good at: anything with filenames on
stdin is much more neatly handled with cpio than with `xargs tar'.

--
`... in the sense that dragons logically follow evolution so they would
be able to wield metal.' --- Kenneth Eng's colourless green ideas sleep
furiously
Back to top
Paul Martin
External


Since: Sep 21, 2004
Posts: 173



PostPosted: Fri Jul 13, 2007 7:18 am    Post subject: Re: Copying nested folders [Login to view extended thread Info.]
Imported from groups: per prev. post (more info?)

This message is not archived
Back to top
NickNoxx
External


Since: Jul 10, 2007
Posts: 5



PostPosted: Fri Jul 13, 2007 7:23 pm    Post subject: Re: Copying nested folders [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Paul Martin wrote:
> In article <REMki.6729$oa7.6134@newsfe1-gui.ntli.net>,
> John Taylor wrote:
>> NickNoxx wrote:
>>> Hi
>>>
>>> I have a number of folders containing various formats of music. I'd like
>>> to be able to copy all the folders containing a file with .mp3 extension
>>> to an appropriately nested folder in another location ie
>>>
>>> /music/Compilations/Rebel Music/04 The Russians Are Coming.mp3
>>> should be copied to
>>> /mp3/Compilations/Rebel Music/04 The Russians Are Coming.mp3
>>>
>>> whereas
>>>
>>> music\Compilations\The Album\1-01 Clint Eastwood.wav
>>> would be left alone
>>>
>>> I'm thinking along the lines of:
>>>
>>> find /music | grep mp3 |cp $ /mp3
>>>
>
>> How about:
>> find ./music -name "*.mp3" | cpio -pudv /mp3
>
> A little refinement:
>
> find ./music -name "*.mp3" -print0 | cpio -0pudv /mp3
>
> If you want to save disc space, and the files are on the same physical
> drive, and you're not going to be modifying them, you could use hard
> links instead.
>
> find ./music -name "*.mp3" -print0 | cpio -0lpudv /mp3
>
You'll have to explain what the refinement does as I'm afraid I don't
understand. The files will end up on different filesystems (that's kind
of the point Smile )

The 'basic' version worked a treat by the way.

For general information, I'm building an mp3 jukebox from a rugged hard
drive, an NSLU2 running mt-daapd, and (hopefully) a netgear MP101 for
use outside my camper van.
Back to top
Ben Bacarisse
External


Since: Jun 10, 2005
Posts: 90



PostPosted: Sat Jul 14, 2007 12:11 pm    Post subject: Re: Copying nested folders [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

NickNoxx <nick DeleteThis @munged_for_spam.com> writes:

> Paul Martin wrote:
>> In article <REMki.6729$oa7.6134@newsfe1-gui.ntli.net>,
>> John Taylor wrote:
>>> NickNoxx wrote:
>>>> Hi
>>>>
>>>> I have a number of folders containing various formats of
>>>> music. I'd like to be able to copy all the folders containing a
>>>> file with .mp3 extension to an appropriately nested folder in
>>>> another location ie
>>>>
>>>> /music/Compilations/Rebel Music/04 The Russians Are Coming.mp3
>>>> should be copied to
>>>> /mp3/Compilations/Rebel Music/04 The Russians Are Coming.mp3
>>>>
>>>> whereas
>>>>
>>>> music\Compilations\The Album\1-01 Clint Eastwood.wav
>>>> would be left alone
>>>>
>>>> I'm thinking along the lines of:
>>>>
>>>> find /music | grep mp3 |cp $ /mp3
>>>>
>>
>>> How about:
>>> find ./music -name "*.mp3" | cpio -pudv /mp3
>>
>> A little refinement:
>>
>> find ./music -name "*.mp3" -print0 | cpio -0pudv /mp3
>>
>> If you want to save disc space, and the files are on the same physical
>> drive, and you're not going to be modifying them, you could use hard
>> links instead.
>>
>> find ./music -name "*.mp3" -print0 | cpio -0lpudv /mp3
>>
> You'll have to explain what the refinement does as I'm afraid I don't
> understand.

Refinement 1: (-print0 in find and -0 in cpio) uses a zero byte rather
than newline to delimit entries. It is odd and disruptive but valid
to have a newline in a Linux file name.

Refinement 2: (-l in cpio) makes cpio link to the files rather than
copy them. Useful if you want to "pull out" a subset of files for
later action.

> The files will end up on different filesystems (that's
> kind of the point Smile )

OK, then the -l will not work (actually, it will simply have no effect
since hard linking across filesystems is not possible and the -l flag
is a "link is possible" flag).

--
Ben.
Back to top
NickNoxx
External


Since: Jul 10, 2007
Posts: 5



PostPosted: Sun Jul 15, 2007 10:41 am    Post subject: Re: Copying nested folders [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Ben Bacarisse wrote:
> snip explanation

Thanks
Back to top
Display posts from previous:   
Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> UK All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum