How do I create a tar file for only dir and its subdir structures??

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How do I create a tar file for only dir and its subdir structures??
# 1  
Old 11-12-2013
How do I create a tar file for only dir and its subdir structures??

How do I create a tar file for only dir and its subdir structures??
# 2  
Old 11-12-2013
One approach would be to list only directories under dir
tar -cf directory_structure.tar $(find /path/to/dir -type d)

# 3  
Old 11-12-2013
tar -cvzf filename.tar.gz DIR_NAME/

---------- Post updated at 10:41 PM ---------- Previous update was at 10:40 PM ----------

tar -czvf directory.tar.gz -C my_directory .

Last edited by Scott; 11-12-2013 at 07:17 PM.. Reason: Please use code tags
# 4  
Old 11-12-2013
I tried,
tar -cf directory_structure.tar $(find /path/to/dir -type d)

and it did not work.

I tried suggestions from other posts and they did not work either

---------- Post updated at 06:03 PM ---------- Previous update was at 02:13 PM ----------

***** SOLVED ******

After looking at one of the examples in manual. Following code worked.
find /dir -type d > fl_list
tar -cvf my.tar -L $fl

So my guess is 1st line can be changed to get any pattern of files and then using -L option.

Last edited by Scott; 11-12-2013 at 07:18 PM.. Reason: Code tags
# 5  
Old 11-12-2013
A POSIX alternative:
find /dir -type d | pax -wd > my.tar

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

copying the dir/subdir structure from one server to another?

Hi All, I want to copy the dir/subdir structure from SERVER-A to SERVER-B without copying all the files in each dir. Is it possible using SCP / SFTP command? For example, SERVER-A has following two dir/subdirectories and files under each subdir. ... (1 Reply)
Discussion started by: Hangman2
1 Replies

2. Shell Programming and Scripting

Move all files from dir and subdir to Archive with File name as complete path_filename

HI, I need to move all files from a dir & its all subdir to Archive folder which is indise dir only. and moved filename should changed to complete path ( Like Dir_subdir_subdir2_.._filename ). also all files names shoud capture in a file in order to mail I written below code ... (11 Replies)
Discussion started by: minijain7
11 Replies

3. Shell Programming and Scripting

Create tar file

Following are the list of files available in the dataout directory a1.txt.gz a2.txt.gz b3.txt.gzStep 1: now the tar file needs to be created as follows. tar -cvf ab.tar *.gzAll the files with extn .gzg has to be bundled in the tar file. Once the tar file is created, the files which are... (9 Replies)
Discussion started by: kmanivan82
9 Replies

4. Shell Programming and Scripting

Create file Dir and Sub Dir same time

Hi Guys , I want create files Dire and Sub Dire. as same time using variable. EX: x1="/hk/Pt/put/NC/R1.txt" x2="/hk/pt/Put/Ot/NC/RN.txt" And i want delete all after done with my script. Thanks (2 Replies)
Discussion started by: pareshkp
2 Replies

5. UNIX for Advanced & Expert Users

Create corrupted *.tar.gz file ?

Hello. I`m writing a bash script who archive log files and send them to backup server. I need some kind of checking mechanism for *.tar.gz files. I found something like: gunzip -t file.tar.gz //Not output from it. And for tar: tar tf file.tar.gz //Only lists archive 1.) I need make a... (3 Replies)
Discussion started by: jabalv
3 Replies

6. Shell Programming and Scripting

Perform action in dir if dir has .git subdir

Hi, I want to run git status for the dir which has subdir ".git" in it with dir path mentioned in output log? If a dir does not have .git subdir then skip that dir. Dir will have 100 main dirs & 500 + subdirs and so on. I appreciate all your help :b: (4 Replies)
Discussion started by: dragon.1431
4 Replies

7. Shell Programming and Scripting

replace string in multiple files, dir and subdir

Hello, I have a directory www with multiple directories. Every directory has site name with .htm, .html, .php files or sub directories with .htm, .php, .html file as example - www - sitename 1 - site 1 - sitename 2 - sitename 3 What I'm looking for is a... (7 Replies)
Discussion started by: andyjill
7 Replies

8. Shell Programming and Scripting

moving dir subdir and files

I have created a directory structure and under the directory subdirectories and files are there.I need to move the entire thing to another path.How can i write a script to do that. currently the path of files is as below : /data1/serial/mcycle/archive : under this path differnt sub dir exist ... (6 Replies)
Discussion started by: dr46014
6 Replies

9. Shell Programming and Scripting

how to create new dir fro a file list

Hi, What will be the best way to do the follwing: i have a file calld dir.list /cav /cav/brif /usr/main /cat i want to run a script that will take each of the item in the file and create a new dir in a location that i'll choose it nee to do mkdir cav mkdir cav cd cav mkdir brif... (8 Replies)
Discussion started by: banjo
8 Replies

10. UNIX for Dummies Questions & Answers

script to create tar file

hello, im a newbie in unix scripting. can someone pls send me a sample script that will tar files in the folders of a specific directory, but will exclude specific files, and afterwards, will ftp the tar into another server. for example: in this directory, pshrprod:/opt/psoft/weblogic/818sp9_80... (2 Replies)
Discussion started by: ajrandrup
2 Replies
Login or Register to Ask a Question