LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-29-2001, 02:27 PM   #1
system
Member
 
Registered: Dec 2001
Distribution: LFS, RH, Slack
Posts: 104

Rep: Reputation: 15
How to copy a directory tree without copying the files in it?


Hello. I want to copy a directory and all the subdirectories in order to make a duplicate of the directory structure. I don't want to copy any of the files though, just directories. Isn't this possible using cp and telling it to copy only files with the dir flag set or something?
 
Old 12-30-2001, 09:59 AM   #2
bluecadet
Member
 
Registered: Oct 2001
Distribution: MD81 RH71
Posts: 555

Rep: Reputation: 30
well, it's a bit of an odd thing to want to do, so i doubt there's a nice way to do it officially. i did however write a script pretty similar last night actually!

Code:
cd "$1"
for i in *
do
  if [ -d "$i" ]
  then
    newdirpath=`echo "$PWD/$i" | sed s/smb// | tr ' ' '_' | tr A-Z a-z | sed s/_-_/-/`
    echo $newdirpath
    mkdir "$newdirpath"
    find "$PWD/$i" -iname '*.mp3' -fprint "$newdirpath"/mp3.m3u 
    /home/chris/clone "$i"    
  fi
done
cd -
it creates a replica of a directory tree with a winamp/xmms m3u file in every single directory of every mp3 in that directory, and recursive subdirectories. It also converts spaces to underscores and all letters to lower case.

I was gonna hack it around, and take out various bits.. but i think i'll leave that for you to do if you decide to!

oh, as it works recursively, the program IS /home/chris/clone... which obviosuly isn't right for you...

incidentally, if you wanna alter it to not create leaf-directories, i'd gladly accept the ocde back!
 
Old 01-15-2002, 09:36 PM   #3
kervin
Member
 
Registered: Jan 2002
Location: Melbourne, FL.
Distribution: redhat
Posts: 168

Rep: Reputation: 30
find . -type d -exec mkdir -p /tmp/copy_dest2/{} \;

This line should do it.

The first '.' ( dot ) is for current directory and can be replace by the directory name you're about to copy. The /tmp/copy_dest2 is the path you'd like to copy to, and can also be replaced.

the above will not follow symlinks, but can be modified to.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically Copying files from the ftp directory into the html directory swatward Linux - General 3 04-17-2005 10:55 PM
Copying all files from subdirectories into one directory Hegemon Linux - General 3 01-17-2005 11:25 AM
locate and copy files - without directory tree rodda Linux - General 1 01-16-2005 02:10 AM
copying files to protected directory? webazoid Linux - Software 1 07-11-2004 09:08 AM
How to copy tree without files in it? BladeRunner Linux - Newbie 6 03-22-2004 01:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration