Add directory to TAR file whitout files.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add directory to TAR file whitout files.
# 1  
Old 02-02-2009
Add directory to TAR file without files.

Hi,

What I'm trying to do is rather easy to explain, but I don't know if it's possible.

The main idea is that I have directories which I want to add to a TAR file, but for some of them I don't want to include the files in the directory. I just want to add the path to the TAR file as if the directory was empty. As an extra information I can say that the directories are added via an update (tar -uf).

Any help would be much appreciated.

Thanks upfront

Last edited by wisobe; 02-02-2009 at 01:06 PM..
# 2  
Old 02-02-2009
I do not think you can do that - directories are files with data in them. If you were able to extract just a directory with no actual files it referenced, then it would cause integrity problems for the filesystem. You would probably have to run fsck to fix it.

Note: I have never done any of this, so I don't know for sure.

Can you workaround it? - copy your directory tree to temporary disk storage, delete all the files and directories under the directories you want "clear" and then tar the whole mess?
# 3  
Old 02-02-2009
Quote:
Originally Posted by jim mcnamara
Can you workaround it? - copy your directory tree to temporary disk storage, delete all the files and directories under the directories you want "clear" and then tar the whole mess?
I also thought about that, but it's too risky if some other scripts are running (which are using the files in the future TAR) while I make the tar.

Anyway, thanks for your fast reply. Smilie
# 4  
Old 02-02-2009
Quote:
Originally Posted by jim mcnamara
I do not think you can do that - directories are files with data in them.
They certainly are, but on the systems I've played with it the OS doesn't let you play with their contents by means beyond mkdir, opendir, and unlink. It's also entirely possible to tar an empty directory:
Code:
$ mkdir something
$ tar -cf something.tar something
$ tar -tf something.tar 
something/
$

Extracting that would amount to a mkdir and a chmod(confirmed on my system with strace). You can even tell tar, GNU tar at least, to not recurse into directories with --no-recursion, which will cause it to ignore all files in all directories you give it.

But I don't think you can force tar to pretend one particular directory is empty while recursing into the others. You could run tar twice, the first time adding the directories twice, the second time with the --append and --no-recusion options to add the 'empty' directories you want.

Last edited by Corona688; 02-02-2009 at 09:00 PM..
# 5  
Old 02-03-2009
It seems like it is quite difficult to do this.

I decided to exlude those directories from the TAR. They will be created with another script.

Thank you all for your help !
# 6  
Old 02-03-2009
You could try it with find, eg.
Code:
$ tar -cf files.tar `find . -type d ! -name 'exclude1' ! -name 'exclude2' -print`

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How can i add each line from a txt file to different files in the same directory?

Hello, this is my first thread here :) So i have a text file that contains words in each line like abcd efgh ijkl mnop and i have 4 txt files, i want to add each line to each file, like file 1 gets abcd at the end; file 2 gets efgh at the end .... I tried with: cat test | while read -r... (6 Replies)
Discussion started by: azaiiez
6 Replies

2. AIX

Making Tar of directory and tar file is going to be placed

Quick question, is it possible to make a Tar of completely directory and placing the tar file in it (will this cause even the tar file to tarred ?) sample: /opt/freeware/bin/tar -cvf - /oracle | gzip > /oracle/backup.tgz will the tar file backup.tgz also include backup.tgz ? i tried... (5 Replies)
Discussion started by: filosophizer
5 Replies

3. Shell Programming and Scripting

Extract files from tar ball without directory structure

Hi, I have tar filw which has multiple directories which contain files. When i extract using tar -xf the directory structure also get extracted. I require only files and not directory structures as there will be overhead of moving the files again. So i searched here and got a solution but... (4 Replies)
Discussion started by: chetan.c
4 Replies

4. Shell Programming and Scripting

tar command to explore multiple layers of tar and tar.gz files

Hi all, I have a tar file and inside that tar file is a folder with additional tar.gz files. What I want to do is look inside the first tar file and then find the second tar file I'm looking for, look inside that tar.gz file to find a certain directory. I'm encountering issues by trying to... (1 Reply)
Discussion started by: bashnewbee
1 Replies

5. UNIX for Dummies Questions & Answers

tar files in directory

can someone give me a script to tar files that is older than 5 days in a directory that is not something like this: fileArray=($(find -mtime +5 asdfasdf)) tar -cvf asfadfasdfa ${fileArray} as the Unix I'm using has some problem with ($( )), I need another way to tar files in the folder.... (1 Reply)
Discussion started by: s3270226
1 Replies

6. UNIX for Advanced & Expert Users

How to rsync or tar directory trees, with hidden directory, but without files?

I want to backup all the directory tress, including hidden directories, without copying any files. find . -type d gives the perfect list. When I tried tar, it won't work for me because it tars all the files. find . -type d | xargs tar -cvf a.tar So i tried rsync. On my own test box, the... (4 Replies)
Discussion started by: fld2007
4 Replies

7. Shell Programming and Scripting

How to tar all executable file in a directory

Dear all I want to create a tar file which contains all executable files in a specific directory cd /appl/home/ file some_exe some_exe: 64-bit XCOFF executable or object module not stripped My current approach is to tar it one by one tar -cvf test.tar exefile1 tar -uvf test.tar... (2 Replies)
Discussion started by: on9west
2 Replies

8. UNIX for Dummies Questions & Answers

zipping all the tar files to singlr file in directory

Hi, i have more than 300 tar files in directory and i want to zip all tar files to single file. could anybody tell me the command since i know how to do zip for single tar file: bash-3.00$gzip 2008_11_10.tar bash-3.00$ pwd /oracle1/archivebackup in this directory i have lot files... (2 Replies)
Discussion started by: prakash.gr
2 Replies

9. UNIX for Dummies Questions & Answers

how to add files to an existing tar file - HP-UNIX

Hello, What is the command to add files to an existing tar file. Thanks, (5 Replies)
Discussion started by: Nomaad
5 Replies

10. UNIX for Dummies Questions & Answers

extract tar files without creating directory

I received a tar file of a directory with 50,000 files in it. Is it possible to extract the files in the tar file without first creating the directory? ie. Doing tar -xvf filename.tar extracts as follows: x directory/file1.txt x directory/file2.txt . . . I would like to avoid... (4 Replies)
Discussion started by: here2learn
4 Replies
Login or Register to Ask a Question