Tar only the Directories and Sub Directories


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Tar only the Directories and Sub Directories
# 1  
Old 12-23-2004
Tar only the Directories and Sub Directories

Hi all,

I want to only tar the Directories and the Sub Directories. I dont want the files which are created in those directories.

Can you please help me out in this issue.

Regards
Andy
# 2  
Old 12-23-2004
i do like this ......

Code:
#!/usr/bin/ksh
mkdir tmp
for i in `find . -type d -print`
do
   mkdir -p tmp/$i
done

cd tmp ; rm -rf tmp

tar cvf dirs.tar .
mv dirs.tar ../
rm -rf tmp

# 3  
Old 12-23-2004
small modification to remove the tmp dir
cd ..


[CODE]

#!/usr/bin/ksh
mkdir tmp
for i in `find . -type d -print`
do
mkdir -p tmp/$i
done

cd tmp ; rm -rf tmp

tar cvf dirs.tar .
mv dirs.tar ../
cd ..
rm -rf tmp


[/QUOTE]
# 4  
Old 06-01-2008
The script is OK but it do not maintain the ownership and permission of folders.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with tar cmd for directories

Hi, I'm working on HP-UX B.11.23 64bit. I tried to tar couple of directories but failed to do so. $ tar -cvf tar_file_name -C /dir1 /dir2 the -C is for directories as mentioned in the man pages. But still unable to create a tar file having directories and sub-directories. Requesting help in... (1 Reply)
Discussion started by: sam_bd
1 Replies

2. Shell Programming and Scripting

Tar extract a multiple directories

i extract it through script, is there any way to script or automate to tar extract a tarfiles in multiple directories at once? Cannot open: No such file or directory tar: Error is not recoverable: exiting now for dir in `ls -d /tarfiles/*/ | sed 's/.$//'` do rm -f $dir/*.tar mv -f... (1 Reply)
Discussion started by: kenshinhimura
1 Replies

3. UNIX for Dummies Questions & Answers

Using tar to move directories

I have figured out how to create a tar file that holds all the files in a particular directory. The plan is to move the tar to a new system via FTP so that we can test the new system with our files and libraries. What I can't figure out is how to unzip the tar file; I keep getting messages that... (8 Replies)
Discussion started by: KathyB148
8 Replies

4. UNIX for Advanced & Expert Users

Extracting directories only from tar ball

Hi Somebody must have done this before, but I can't seem to find any answer on my problem. On HP-UX 11i v3 I have a relatively large tar ball (~120 GB), and I want to create the directory structure only from the archive. There is no option to make a new archive with only the directory... (3 Replies)
Discussion started by: hpvm_adm
3 Replies

5. Shell Programming and Scripting

compress directories with .tar extension

hi guys.. Since am a bit new to shell scripting, can anyone help me with this problem please.. i've been struggling with it since 2 days. :( I have a directory lets say myFolder and within it I have sub directories let say myFolder1.tar, myFolder2, myFolder3, etc. I need to write a shell... (12 Replies)
Discussion started by: kanexxx
12 Replies

6. Solaris

Tar and moving directories

I'm redoing my file system partitions on a Sunblade 100. The system came with a 999mb root and slice 6 with 35GB. I redid the file system by creating separate /opt1, /usr1, /var1, and a /data on different partitions (slice 3, 4, 5 and 7). I need a command to tar my opt, var, opt, usr that's under... (2 Replies)
Discussion started by: stocksj
2 Replies

7. UNIX for Dummies Questions & Answers

Tar-ing the correct directories

Hi all, my directory structure is as follows /a/b/c. I would like to tar the /a directory including the subdirectories b and c. i intend to use the command tar -cvfz a.tgz a/ My question is where do i execute the command? do i execute it at the '/' prompt or at '/a' prompt ? My concern at... (1 Reply)
Discussion started by: new2ss
1 Replies

8. UNIX for Dummies Questions & Answers

how to tar directories that begins with 'sample_ZZZ'????

Hi, I have a bunch of images (8k) in several directories. I want to tar these directories up and unzip them to development and production with the same path. Example: /about/images/sample_01 /about/images/sample_02 /about/images/sample_03 /about/images/lorem_ipsum... (4 Replies)
Discussion started by: andylee80
4 Replies

9. Shell Programming and Scripting

excluding directories in tar

In a bash script I am writing I am having a problem excluding selected directories from tar. From the machine $SERVER I issue the command #start netcat on storage server gnetcat -l -vv -p 2011 >$FILEPATH/$SHORT_NAME.$today.tar & The the following command is then sent to the $CLIENT. #start... (2 Replies)
Discussion started by: thumper
2 Replies

10. UNIX for Dummies Questions & Answers

excluding directories while using tar

How do I exclude some directories while creating a tar file with a number of directories? thanks. (2 Replies)
Discussion started by: uchachra
2 Replies
Login or Register to Ask a Question