how to clone a directory list to another directory

0

I am trying clone a directory and it's subdirectories into another directory. I have hundreds of music directories with sub-directories that I want to convert from flac to ogg. I want all the music Subdirectories under /Music to be cloned to /Music/Oggs/ so that when I do the conversion the files will all be written to the same directory names. Here's what I have:

/Music/Van_Halen_Discography/1980 Women And Children First/

What I need is the clone of directories to this:

/Music/Oggs/Van_Halen_Discography/1980 Women And Children First/

I tried using, 'find /Music -type d |cat > /Music/Oggs'

But it didn't work, what am I missing? Thanks

Widgeteye The Terrible

Posted 2014-09-13T19:13:34.993

Reputation: 77

1cat does not make directories. It just creates a text file /Music/Oggs in the given command – Vamsi – 2014-09-13T19:40:05.047

Answers

1

You could use rsync as follows.

 rsync -av -f"+ */" -f"- *" /path/to/Music/ /path/to/Music/oggs

Here -a tells rsync to recurse through dirs and preserve links, permissions and ownership while v makes it verbose. -f is a filter with the first argument including all directories and the second excluding all files. I suggest trying out on a small example first if you are unfamiliar with rsync.

Vamsi

Posted 2014-09-13T19:13:34.993

Reputation: 806

This worked but it made the directory /Music/Oggs/Music/ then music Sub-directories, which is fine, I just went into /Music/Oggs/Music and did a 'mv * ../' I got what I needed, Thanks – Widgeteye The Terrible – 2014-09-13T19:52:31.403

The first path should have been /path/to/Music/ with the ending slash. My bad. Glad you worked it out. – Vamsi – 2014-09-13T19:56:48.260

0

There is a simple way, let's suppose you are in ~/Music/ with the current shell.

mkdir Oggs            # In case you do not have done before    
cp -rp !(Oggs) Oggs  
  • cp is the normal command used in Linux to copy files and directories
  • -rp or if you prefer -r -p are options to recurse through directories and to preserve time accesses, ownerships ...
    Use man cp for a more complete insight.
  • !(Oggs) Tricky with ! you negate what is inside the parenthesis: so you are telling copy all file and not Oggs to Oggs

Note : This requires shopt extglob on, if is disabled use shopt -s extglob to enabled it.

Hastur

Posted 2014-09-13T19:13:34.993

Reputation: 15 043