Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tar only dirctories

Status
Not open for further replies.

gotchausa

Programmer
Jan 24, 2002
64
CA
Is it possible to use 'tar' to only create an archive with directories - no files belonging to these dirs.? I basically only want to save the dir. structure without the files.
 
Try this script:

find /dir -type d > dir_list.txt
tar -cpf dir.tar -L dir_list.txt
 
The -L option is not available with the tar version that I have (Solaris 8). What does the option do?
 
Sorry! -L is in AIX and read a file that contain a list of what to save with tar.
Try this on Solaris:

# find /dir -type f > file_list.txt
# tar -cvpfX dir.tar file_list.txt /dir

The X option of the tar read a file_list.txt and exclude the contents.
 
I tried your suggestion and it seemed to work for exclude list with a few entries. However, when I do something like:

find / -type f > file_list.txt
tar cvfpX dir.tar file_list /

The exclude file is completely ignored!! The file has about 52,000 entries. Is there a max no. of exclude entries that tar can deal with?
 
You are right. The problem is that Solaris (I don't know why) append a / when you use tar on the root directory.
ex. tar -cvf /tmp/root.tar /
a //var
a //var/spool
ecc.

try to use relative path:
cd /
find . -type f > file_list.txt
tar -cvfpX /dir_with_free_space/dir.tar file_list.txt -C / .

52000 entries isn't a problem, i tried with 170000 entries.
But....if you have to save root directory tree you have to exclude also special files and link, so add this find in your script:
find . -type b >> file_list.txt
find . -type c >> file_list.txt
find . -type D >> file_list.txt
find . -type l >> file_list.txt
find . -type p >> file_list.txt
find . -type s >> file_list.txt

 
An alternative is to use cpio like:
To store:
Code:
find . -type d | cpio -o > /tmp/dirs
To create:
Code:
cd /tmp
cpio -id < dirs
Might not be as portable. Cheers, Neil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top