TAR and ZIP files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers TAR and ZIP files
# 8  
Old 02-01-2012
Code:
tar -zcf file.tar.gz *.txt

# 9  
Old 02-01-2012
hi corona,

I am using the below commands (in a single line) in my script to tar the files as per your suggestion.

PHP Code:
FILE_LIST=`ls $ENVID_*_$DATE_OF_RUN.$ENVID_*.TXT` | echo "files are $FILE_LIST>>${logfile} | tar -zcf ${ENVID}_$(date +"%Y%m%d%H%M%S").tar.gz /opt/informatica/infa_shared/SrcFiles/arch 
I see a *.tar.gz in the path I am running the script. But I thought the tar file to be in /opt/informatica/infa_shared/SrcFiles/arch path. can you please advice?

Also, I would like to unzip/untar back the files to verify if the files are tar-red properly.. and used the below command from command line. It actually returns me the path - /opt/informatica/infa_shared/SrcFiles/arch but there are no files extracted... I am expecting to see the files individually.. can you help on how to extract the files?

PHP Code:
$  tar -zxvf FERAL_20120201100113.tar.gz
opt
/informatica/infa_shared/SrcFiles/arch
I have LINUX OS.

thanks!
# 10  
Old 02-01-2012
tar does not read from standard input. Smilie

tar works the way I showed you, not the way you're trying to use it. Smilie

Since you refuse to explain any of the details, I still have no idea what you're even trying to do. I also asked what your system was and received no answer. This information is needed to answer some of your questions.

Why would the tar file be in /opt/informatica/infa_shared/SrcFiles/arch when you told tar to read files from /opt/informatica/infa_shared/SrcFiles/arch ? It ends up in the current directory because you didn't tell it anything else.

There is also much useless use of ls * in your code. ls is not the thing that understands *, any command is given the corresponding filenames when you use *. You might as well just put the * where you want the filenames to appear in the first place -- which is, as I demonstrated, the last arguments of tar.

You also have lots of unbracketed variables which are going to screw up. _$DATE_OF_RUN_$OTHER will mess up because you have no variable named $DATE_OF_RUN_. You use ${VARNAME} style brackets to defeat that.

I'll venture a third try at what I'm guessing you want:

Code:
TARFILE="/opt/informatica/infa_shared/SrcFiles/arch/${ENVID}_$(date +"%Y%m%d%H%M%S").tar.gz"
# Create the compressed tar file
tar -zcf "${TARFILE}" "${ENVID}_"*"_${DATE_OF_RUN}.${ENVID}_"*".TXT"
# List files inside the tar file
tar -ztf "${TARFILE}" > ${LOGFILE}

And again, if you tell me what your system is, there may or may not be a 'verify' option that would be of use to you. But there's no point pointing it out if you don't have it. What is your system?
# 11  
Old 02-01-2012
Hi Corona,

I am very new to Unix that's why I have hiccups..

My machine is Linux OS.

My requirement is to take some files from landing directory (there will be many files, but I need to pick the files based on the date - the date value is stored in another file) and then archive them to another directory. As I have to pick only certain files, I used ls command to get a list of them.

This is just to back up the files and if the need be, the tar files from the archive directory has to be used and the individual files (like how it was initially) are taken from it and to be sent to landing directory for processing the files.

As it would occupy less space by ZIP ing them, I was trying to zip the files separately and store all the files to a single tar file.

I was told to zip them all individually and tar the zip-ped files into a single tar file. But, I remember that you said it is done the other way round. I am fine with it as long as I can untar and unzip the files and bring them back as individual files (like how it was)...

I will make the bracket changes you mentioned.

Thanks much!!
# 12  
Old 02-01-2012
Quote:
Originally Posted by Vijay81
My machine is Linux OS.
Thank you. You can use your version of tar to verify while it's creating the tarball, then, by doing tar --verify ....

Quote:
As it would occupy less space by ZIP ing them, I was trying to zip the files separately and store all the files to a single tar file.
The usual procedure is the opposite -- compress the tar. This also does a better job of preserving the file's permissions, something pure tar is very good at; if you went and mangled all the files by zipping them first, how well that'd work is anyone's guess.
Quote:
I was told to zip them all individually and tar the zip-ped files into a single tar file. But, I remember that you said it is done the other way round. I am fine with it as long as I can untar and unzip the files and bring them back as individual files (like how it was).
Doing it the other way around means you can extract them directly, and not have to unzip them individually. And you get good compression either way, especially with text files.
# 13  
Old 02-01-2012
Hi Corona,

With TAR verify, will I be able to extract the files back from the .tar.gz file?

eg., I create a .tar.gz file on all the below files. After I execute my script, I see that the .tar.gz file is created. Now, I want to execute some commands and see that I am able to extract all the below files individually, like how they are below. I want to untar / unzip to get the individual files, do you know if this is achievable?

PHP Code:
-rw-r--r-- 1 z06189 bi 16061 Jan 30 16:33 FERAL_CONTROL_20120115.FERAL_CTRL.txt
-rw-r--r-- 1 z06189 bi     0 Jan 31 11:46 FERAL_CONTROL_20120131.FERAL_CNTRL.TXT
-rw-r--r-- 1 z06189 bi   135 Jan 31 13:14 FERAL_CONTROL_20121213.FERAL_CTRL.TXT
-rw-r--r-- 1 z06189 bi   194 Jan 31 11:53 FERAL_DATA1_20120131.FERAL_DATA.TXT
-rw-r--r-- 1 z06189 bi   102 Jan 31 13:20 FERAL_DATA1_20121213.FERAL_98312.TXT
-rw-r--r-- 1 z06189 bi    91 Jan 31 11:53 FERAL_DATA_20120131.FERAL_CNTRL.TXT 
also, I used the TAR verify on the command prompt, but was not successful.
below are the commands... can you help?

PHP Code:
sh-3.2tar -xW verify FERAL_20120201125930.tar.gz
tar
Cannot verify stdin/stdout archive
tar
Error is not recoverableexiting now
sh
-3.2tar -tW verify FERAL_20120201125930.tar.gz
tar
Cannot verify stdin/stdout archive
tar
Error is not recoverableexiting now
sh
-3.2tar -cW verify FERAL_20120201125930.tar.gz
tar
Cannot verify stdin/stdout archive
tar
Error is not recoverableexiting now 

# 14  
Old 02-01-2012
Quote:
Originally Posted by Vijay81
Hi Corona,

With TAR verify, will I be able to extract the files back from the .tar.gz file?
You extract the files with tar -C /path/to/destination/folder/ -zxf filename.tar.gz

Quote:
also, I used the TAR verify on the command prompt, but was not successful.
You really need to read more carefully.

1) It's not verify, it's --verify.
2) You use it when creating the archive. It's not an extra step. Just add --verify in front when creating the archive.

Also, since the files are .tar.gz hence already compressed, you need the -z flag.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (1 Reply)
Discussion started by: b.saipriyanka
1 Replies

2. UNIX for Beginners Questions & Answers

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (2 Replies)
Discussion started by: b.saipriyanka
2 Replies

3. Shell Programming and Scripting

How to create zip/gz/tar files for if the files are older than particular days in UNIX or Linux?

I need a script file for backup (zip or tar or gz) of old log files in our unix server (causing the space problem). Could you please help me to create the zip or gz files for each log files in current directory and sub-directories also? I found one command which is to create gz file for the... (4 Replies)
Discussion started by: Mallikgm
4 Replies

4. Shell Programming and Scripting

Zip Multiple files to One .zip file in AIX system

Hi I have a requirement in unix shell where I need to zip multiple files on server to one single .zip file. I dont see zip command in AIX and gzip command not doing completely what I want. One I do .zip file, I should be able to unzip in my local Computer. Here is example what I want... (9 Replies)
Discussion started by: RAMA PULI
9 Replies

5. Shell Programming and Scripting

help with tar & zip only last months(say,Sep) files

Need to 1. archive all the files in a directory from the previous month into a tar/gz file, ignoring all already archived 'tar.gz' files 2. Check created .tar.gz file isnt corrupted and has all the required files in it. and then remove the original files. I am using a function to get the... (1 Reply)
Discussion started by: Prev
1 Replies

6. UNIX for Advanced & Expert Users

How to zip/tar millions of files?

Hi guys, I have an issue processing a large amount of files. I have around 5 million files (some of them are actually directories) in a server. I am unable to find out the exact number of files since it's taking "forever" to finish (See this thread for more on the issue). Anyway, now I... (6 Replies)
Discussion started by: verdepollo
6 Replies

7. AIX

ZIP multiple files and also specify size of zip file

I have to zip many pdf files and the size of zip file must not exceed 200 MB. When size is more than 200 MB then multiple zip files needs to be created. How we can achieve this in UNIX? I have tried ZIP utility but it takes a lot of time when we add individual pdfs by looping through a... (1 Reply)
Discussion started by: tom007
1 Replies

8. Shell Programming and Scripting

To write a shell script which groups files with certain pattern, create a tar and zip

Hi Guru's, I have to write a shell script which groups file names based upon the certain matching string pattern, then creates the Tar file for that particular group of files and then zips the Tar file created for the respective group of files. For example, In the given directory these files... (3 Replies)
Discussion started by: rahu_sg
3 Replies

9. UNIX Desktop Questions & Answers

Using Tar Zip

Hi, I want to backup my SQL database using tar zip but I'm paranoid that I will archive it. What I mean is I want the files to stay where they are but make a zipped copy of the files as well, I don't want to delete the originals. Is the command? tar -cvzf databasename.tar.gz... (1 Reply)
Discussion started by: chickenhouse
1 Replies

10. UNIX for Dummies Questions & Answers

unzip .zip file and list the files included in the .zip archive

Hello, I am trying to return the name of the resulting file from a .zip archive file using unix unzip command. unzip c07212007.cef7081.zip Archive: c07212007.cef7081.zip SecureZIP for z/OS by PKWARE inflating: CEP/CEM7080/PPVBILL/PASS/G0063V00 I used the following command to unzip in... (5 Replies)
Discussion started by: oracledev
5 Replies
Login or Register to Ask a Question