Problem untaring gzip


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem untaring gzip
# 1  
Old 07-16-2012
Problem untaring gzip

I'm having an issue extracting my tar.gz file. I am trying to compress all directories based on their last modified date (particularly their last modified month), and move them to a different directory by month. When I run my script everything seems to work ok and my compressed file gets moved to the desired location directory. The issue is when I check to see what directories got compressed and moved, by extracting the files, the directory path appears as well. For example I'm compressing a directory named "dir" with the path name /home/username/directory/dir. When I compress "dir" then move and extract it, it extracts both the contents of dir (which is what I wanted) but also /home/user/directory.

How do I fix this?

My script is below

Code:
cd /home/user/directory
MONTH=`find . -type d -newermt 2012-07-01 ! -newermt 2012-07-31`

for F in ${MONTH}
do
        tar -zcvf dir.tar.gz /home/user/directory/${F}
done

mv dir.tar.gz /home/user/newdirectory/month

# 2  
Old 07-16-2012
Try adding ! -name '.' to your find statement.
# 3  
Old 07-16-2012
Quote:
Originally Posted by jrymer
For example I'm compressing a directory named "dir" with the path name /home/username/directory/dir. When I compress "dir" then move and extract it, it extracts both the contents of dir (which is what I wanted) but also /home/user/directory.
If I understood you correctly, your problem is that the members of the archive are using an absolute path and you want them to be relative, so that when you extract them the newly-created pathnames are relative to the current working directory at the time of extraction.

If that's the case, you probably want tar to switch working directory before creating the archive:
Code:
tar -zcvf dir.tar.gz -C /home/user/directory "${F}"

Regards,
Alister
This User Gave Thanks to alister For This Post:
# 4  
Old 07-16-2012
Quote:
If that's the case, you probably want tar to switch working directory before creating the archive:
Code:
tar -zcvf dir.tar.gz -C /home/user/directory "${F}"

It works, thanks a lot.
# 5  
Old 07-16-2012
I understood that the home directory "." was being compressed also and it was only sub directories of this that were wanted. As I suggested this can be done with excluding the path using ! -name option, or -mindepth 1 and perhaps also -maxdepth 1 if you only want directories at the top level.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue in Untaring the Tar files Script

I have written a below script to untar the tar files from /tmp/tarfiles/ directory. # cat /tmp/tarfiles/script.sh #!/bin/sh cd /tmp/tarfiles/ TFL="tar_files_list.txt" TCF="tar_completed_list.txt" ls -l *.tar | awk '{print $9}' > $TFL for i in `cat $TFL` do if then for j in... (2 Replies)
Discussion started by: thomasraj87
2 Replies

2. UNIX for Advanced & Expert Users

gzip vs pipe gzip: produce different file size

Hi All, I have a random test file: test.txt, size: 146 $ ll test.txt $ 146 test.txt Take 1: $ cat test.txt | gzip > test.txt.gz $ ll test.txt.gz $ 124 test.txt.gz Take 2: $ gzip test.txt $ ll test.txt.gz $ 133 test.txt.gz As you can see, gzipping a file and piping into gzip... (1 Reply)
Discussion started by: hanfresco
1 Replies

3. Shell Programming and Scripting

Recursively UNTARing and then TARing back

I've just finished writing a shell script that searches for a string recursively in all text files and replace them with another string. Now, all these files come from a location nested deep within some TAR files which are inside another mother TAR. To make my script work, we had been UNTARing... (6 Replies)
Discussion started by: exchequer598
6 Replies

4. UNIX for Dummies Questions & Answers

gzip-gunzip a problem

Hi all, i have a gzipped file. <file_name>.gz . when i try gunzip this file i get, invalid compressed data--format violated this file gzipped like gzip -f -S <file_name> 2 > <error_log_file> there is no error in log. it seems that the file gzipped properly. how this ... (3 Replies)
Discussion started by: dummydba
3 Replies

5. Shell Programming and Scripting

tar and gzip problem

Hi Guys, I have a few files. i want to tar these files and zip it using gzip it. -rw-r----- 1 magesh magesh 12940369 Jul 27 09:26 dcx_imds_c.asc -rw-r----- 1 magesh magesh 1221391 Jul 27 09:27 dcx_imds_h.asc -rw-r----- 1 magesh magesh 1105673 Jul 27 09:27... (6 Replies)
Discussion started by: mac4rfree
6 Replies

6. Shell Programming and Scripting

gzip problem

Hi, I am quite new to unix. I need to do the following using gzip. a file suppose abc.gz is in the directory. I need to uncompress it and rename the uncompressed file to ecoes.dat. can anyon please help me in this regard?? (4 Replies)
Discussion started by: UBD
4 Replies

7. Programming

problem about using zlib to uncompress gzip in memory

I wrote a function which for uncompressing data for gzip or deflate format using zlib,see followed code; source param is pointed to the compressed data,len param is the size of compressed data, dest param is for returning the address which pointed to the uncompressed data;the last gzip param tell... (0 Replies)
Discussion started by: iwishfine
0 Replies

8. Shell Programming and Scripting

untaring multiple files

Hi, i'm pretty new to unix and shell scripting and i need to untar a load of files all with different names e.g. YAAN00.V404.T13467.tar, YAAN00.V404.T15623.tar etc with the .T* part following no particular series. I tried to untar them in a script using simply tar -xvf YAAN00.V404.T*.tar ... (3 Replies)
Discussion started by: rinceboy
3 Replies

9. Shell Programming and Scripting

gzip problem

Hi All, I am zipping a file using gzip -cq XYZ.txt > XYZ.txt.gz command. file got created with name XYZ.txt.gz but when i execute the following command i am getting errors, $ gzip -t XYZ.txt.gz gzip: XYZ.txt.gz: invalid compressed data--crc error gzip: XYZ.txt.gz: invalid... (6 Replies)
Discussion started by: rkrgarlapati
6 Replies

10. UNIX for Advanced & Expert Users

gzip or FTP problem?

I hope someone can help me on this little problem. Bit of background first. I've dumped an Oracle database to a plain text file that I wish to gzip then transfer via ftp to another machine. The dump and gzip runs fine and if I gunzip the file while still in unix the file looks fine. The... (2 Replies)
Discussion started by: DGM
2 Replies
Login or Register to Ask a Question