LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   need to careate archive od only the directory (https://www.linuxquestions.org/questions/linux-newbie-8/need-to-careate-archive-od-only-the-directory-535940/)

procfs 03-09-2007 05:09 AM

need to careate archive od only the directory
 
I want to create an archive of directory structure. and I have tried to pipe the output of find command as fallows but it is not working

find ./123/ -type d | tar -cvf 123.tar

Can some one tell me how to do this. All I need is the empty directories

fukawi2 03-09-2007 05:31 AM

Why can't you just do:

Code:

tar cvf 123.tar *
EDIT: I just re-read, and I think you were actually saying you just want to DIRECTORIES, not the file inside them...?

timmeke 03-09-2007 05:45 AM

A few remarks:
1. Don't pass a directory and all it's subdirectories to "tar". If you give it the (top-level) directory to archive, then it'll go through all files/subdirectories recursively.
So, in your case, you only need to do:
Code:

tar -cvf 123.tar 123/
2. If you only want empty directories (so bare directory tree), without any regular files, you first need to either remove all regular files (ie run "find 123 -type f -exec rm {} \;" ) or to create a copy of your directory structure (without copying the files). The latter can be done for instance by running:
Code:

find 123 -type d -exec mkdir /new/path/{} \;
tar -cvf 123.tar /new/path/123/

Check your results via a "tar -tvf 123.tar".

jschiwal 03-09-2007 05:53 AM

You could create an identical directory structure in another directory and then tar that.

mkdir 123tardir
find 123/ -type d -exec mkdir ../123tardir/'{}' \;
cd 123tardir
tar cvf ../123.tar .

procfs 03-12-2007 12:46 AM

Hi Guys Thank you for you'r help. What I wanted was to take a empty directory structure to a another machine and create it there (directories only). I was able to do this by using

Create the directory tree

1) find . -type d -depth -print |cpio -ovcB > dir-tree.cpio


Extract - Only Directory Tree

2) cpio -icvBdum < dir-tree.cpio

Best regards

Asanka


All times are GMT -5. The time now is 10:34 PM.