Visit Our UNIX and Linux User Community


Extraction of .tar.gz creates additional unwanted directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extraction of .tar.gz creates additional unwanted directories
# 1  
Old 07-12-2012
Extraction of .tar.gz creates additional unwanted directories

I'm working on a project that requires me to compress then relocate directories to a different location based on their last date of modification. After running the script I check to see if it worked, and upon unzipping the tar.gz using [tar -zxvf] I created everything that should be there is. I then performed the [ls] command, and saw that two additional directories had shown up after the extraction of the tar.gz, my home and downloads directories.

I'm VERY new to bash so I am probably missing something obvious but here is my script, and help would be appreciated!
Code:
cd ../Downloads
JULY=$(find . -type f -newermt 2012-07-09 ! -newermt  2012-07-10)

tar -zcvf July_compressed.tar.gz /home/josh/Downloads/${JULY} 
    cp July_compressed.tar.gz /home/josh/Documents/July

# 2  
Old 07-12-2012
I'm not sure of your exact requirements.

This is how to move a directory's contents - from ./old to ./new
Code:
cd /path/to/old
mkdir /path/to/archives/new
tar cvf - . | ( cd /path/to/archives/new;  tar xf -)

Pipe from one tar in the old directory to tar in the new one.
# 3  
Old 07-12-2012
I need to move files from one directory into another directory based on their modification date. I'll be moving the files from the old directories to 12 new directories based on months of the year. How would include only files with set modification date in your script?
# 4  
Old 07-12-2012
Code:
cd /path/to/old
mkdir /path/to/archives/new
JULY=$(find . -type f -newermt 2012-07-09 ! -newermt  2012-07-10)
tar cvf -  $JULY | ( cd /path/to/archives/new;  tar xf -)

using your find statement result:
# 5  
Old 07-13-2012
Code:
gzip -dc file.gz | tar -xvf -


Last edited by Franklin52; 07-14-2012 at 06:29 AM.. Reason: Please use code tags for data and code samples, thank you

Previous Thread | Next Thread
Test Your Knowledge in Computers #400
Difficulty: Medium
The first release for HP 9000 Series 500 HP-UX for Series 500 was HP-UX 1.0 (1982).
True or False?

10 More Discussions You Might Find Interesting

1. Red Hat

Script creates additional file

Hi, I have created a test script like this : # cat script1.sh DAY=$(date +%d) MONTH=$(date +%b) YEAR=$(date +%Y) BC01="Blast_BC01" BC15="Blast_BC15" DIR1="$MONTH$YEAR_$BC01" DIR2="$MONTH$YEAR_$BC07" DIR3="$MONTH$YEAR_$BC15" if ;then mkdir -p "$YEAR/$DIR3" fi # When I... (5 Replies)
Discussion started by: anaigini45
5 Replies

2. Shell Programming and Scripting

Speed up extraction od tar.bz2 files using bash

The below bash will untar each tar.bz2 folder in the directory, then remove the tar.bz2. Each of the tar.bz2 folders ranges from 40-75GB and currently takes ~2 hours to extract. Is there a way to speed up the extraction process? I am using a xeon processor with 12 cores. Thank you :). ... (7 Replies)
Discussion started by: cmccabe
7 Replies

3. Emergency UNIX and Linux Support

extraction of directory and below using gnu tar

i need to restore everything in a certain directory and lower. I have a tgz archive of all of the files, and i need to restore everything in /user/home/xxxx/ and below. this is a users home directory. this is a dumb question and i know when i see the answer i am going to say DUH, but i am... (2 Replies)
Discussion started by: frankkahle
2 Replies

4. UNIX for Advanced & Expert Users

tar and gzip extraction issues

Not sure if this is really in the right forum but here goes.... Looking for a way to extract individual compressed files from a compressed tarball WITHOUT tar -zxvf and then recompressing. Basically we need to be able to chunk out an individual compressed file while it still remains... (6 Replies)
Discussion started by: athos
6 Replies

5. AIX

Tar extraction error in aix 5.3

Hi root@appdr01 #ls -latr total 2887400 drwxr-xr-x 2 root system 256 May 06 11:34 lost+found drwxr-xr-x 34 root system 4096 May 06 11:34 .. drwxr-xr-x 3 root system 256 May 06 12:20 . -rw-r----- 1 root system 1478338560 May 06... (1 Reply)
Discussion started by: samsungsamsung
1 Replies

6. UNIX for Dummies Questions & Answers

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 (3 Replies)
Discussion started by: Andysundar
3 Replies

7. 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

8. Shell Programming and Scripting

Help with tar extraction!

I have this tar file which has files of (.ksh, .ini &.sql) and their hard and soft links. Later when the original files and their directories are deleted (or rather lost as in a system crash), I have this tar file as the only source to restore all of them. In such a case when I do, tar... (4 Replies)
Discussion started by: manthasirisha
4 Replies

9. UNIX for Dummies Questions & Answers

Very slow Tar extraction from tape

I'm pulling a 1MB file from tape using tar. It's a 300GB DLT tape and it does have a lot of files on it because it's go the entire OS and Oracle RMAN files and 3000 table exports, but it's taking 2-3 hours to pull this file off of it. Is this type of performance what I should expect? The... (0 Replies)
Discussion started by: citrowske
0 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

Featured Tech Videos