Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-09-2007, 06:09 AM   #1
Registered: Jan 2006
Location: Sri Lanka
Posts: 615

Rep: Reputation: 34
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
Old 03-09-2007, 06:31 AM   #2
Registered: Oct 2006
Location: Melbourne, Australia
Distribution: ArchLinux, ArchServer, Fedora, CentOS
Posts: 449

Rep: Reputation: 34
Why can't you just do:

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...?
Old 03-09-2007, 06:45 AM   #3
Senior Member
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
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:
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:
find 123 -type d -exec mkdir /new/path/{} \;
tar -cvf 123.tar /new/path/123/
Check your results via a "tar -tvf 123.tar".
Old 03-09-2007, 06:53 AM   #4
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677
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 .
Old 03-12-2007, 01:46 AM   #5
Registered: Jan 2006
Location: Sri Lanka
Posts: 615

Original Poster
Rep: Reputation: 34
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



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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
(un)tar a certain directory from an archive Suinatsa Linux - Software 2 06-20-2006 08:09 AM
how to copy-in cpio archive to temp directory jxi Slackware 2 03-08-2006 05:32 PM
tar - extracting a single directory from a large archive? lowpro2k3 Linux - General 1 07-24-2005 03:44 AM
divide a directory into multiple archive files with par ddaas Linux - General 1 02-26-2005 02:52 PM
Trying to archive a 4.6 GB directory kaplan71 Linux - General 2 04-27-2004 11:31 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:00 PM.

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