Create tar file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Create tar file
# 1  
Old 04-09-2012
Create tar file

Following are the list of files available in the dataout directory
Code:
a1.txt.gz
a2.txt.gz
b3.txt.gz

Step 1:
now the tar file needs to be created as follows.
Code:
tar -cvf ab.tar *.gz

All the files with extn .gzg has to be bundled in the tar file.

Once the tar file is created, the files which are inside the tar file should not be available in the dataout directory.

what is the unix command that i have to give to bundle the *.gz files in dataout directory and those *.gz files should not be available in the dataout directory which are inside the tar file.

Step 2:
I have to check the size of the tar file ab.tar. If it is greater than 1600000000 bytes, then echo "file size is high" else echo "file size is low"

Can anyone help me out?

Thanks
Krishnakanth

Last edited by methyl; 04-09-2012 at 06:18 PM.. Reason: after 37 posts, please use code tags.
# 2  
Old 04-09-2012
Quote:
All the files with extn .gzg has to be bundled in the tar file.
Please post a sample with extn .gzq .
# 3  
Old 04-10-2012
Sorry Sir... its a typo error.

All the files with extn .gz has to be bundled in the tar file.

Can you help me to fix this issue.
# 4  
Old 04-10-2012
Quote:
Originally Posted by kmanivan82
Once the tar file is created, the files which are inside the tar file should not be available in the dataout directory.
With GNU tar:
Code:
tar cvf archive.tar *.gz --remove-files

Quote:
Originally Posted by kmanivan82
Step 2:
I have to check the size of the tar file ab.tar. If it is greater than 1600000000 bytes, then echo "file size is high" else echo "file size is low"
Code:
[ $(du -b archive.tar  | awk '{print $1}') -gt  1600000000 ] && echo "file size is high" || echo "file size is  low"


Last edited by balajesuri; 04-10-2012 at 04:00 AM..
# 5  
Old 04-10-2012
seems, you want to remove the .gz files are creating tar file ?

Code:
tar -cvf ab.tar *.gz && rm *.gz

# 6  
Old 04-10-2012
thank you itkamaraj and balajesuri.

only the following command works for me.
Code:
tar -cvf ab.tar *.gz && rm *.gz

the following command to get the file size is not working...
Code:
[ $(du -b archive.tar  | awk '{print $1}') -gt  1600000000 ] && echo "file size is high" || echo "file size is  low"

we are working on ksh.

Can you help me!

Thanks
Krishnakanth

Moderator's Comments:
Mod Comment Welcome to the UNIX and Linux Forums. Please use code tags. Video tutorial on how to use them

Last edited by Scrutinizer; 04-10-2012 at 07:05 AM.. Reason: code tags
# 7  
Old 04-10-2012
Code:
[ $(du -b archive.tar  | awk '{print $1}') -gt  1600000000 ] && echo "file size is high" || echo "file size is  low"

1) The du command posted gives the result in 512 byte blocks.
2) The -b parameter to du is irrelevant in this context (and is doesn't mean bytes).

Try doing the comparison in 512 byte blocks:
Code:
[ $(du archive.tar  | awk '{print $1}') -gt  3125000 ] && echo "file size is high" || echo "file size is  low"

This User Gave Thanks to methyl For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to create a TAR File in a Custom Destination Directory?

I want to create the tarzip file into a destination directory, i am in /var/sftp/home/archive/rquadri directory and i am using below command. However it is creating the file in the /var/sftp/home/archive/rquadri directory itself instead of /tmp, may i please know how do i resolve this. tar -cvzf... (5 Replies)
Discussion started by: Ariean
5 Replies

2. UNIX for Dummies Questions & Answers

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?? (4 Replies)
Discussion started by: vx04
4 Replies

3. HP-UX

Unable to create a tar file due to link

Hi, I am trying to tar a directory structure. but unable to do due to a symbolic link. Please help indomt@behpux $ tar -cvf test.tar /home/indomt a /home/indomt symbolic link to /dxdv/03/ap1dm1 Thanks (1 Reply)
Discussion started by: nag_sathi
1 Replies

4. Shell Programming and Scripting

Create tar file excluding all hard links

I have a problem with tar. Taring a folder with a lot of contents, causes the tar to contain hard links to some files, seen with the same name but 0 in size. The hard links don't exist in the first place. How can I prevent that from happening? I am using the -T option with either -n or... (2 Replies)
Discussion started by: Tribe
2 Replies

5. UNIX for Dummies Questions & Answers

How to create .tgz file without creating .tar file?

Hi, Could anyone help me in providing command to generate .tgz file without creating .tar file? currently i am using below command for doing the same but if tar file has big size and there is no space in drive then tgz file will not be generated. I want to generate tgz file directly without... (4 Replies)
Discussion started by: Pawan Kumar
4 Replies

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

7. UNIX for Dummies Questions & Answers

tar -cvf test.tar `find . -mtime -1 -type f` only tar 1 file

Hi all, 4 files are returned when i issue 'find . -mtime -1 -type f -ls'. ./ora_475244.aud ./ora_671958.aud ./ora_934052.aud ./ora_934050.aud However, when I issued the below command: tar -cvf test.tar `find . -mtime -1 -type f`, the tar file only contains the 1st file -... (2 Replies)
Discussion started by: ahSher
2 Replies

8. Solaris

Find files older than x days and create a consolidated single tar file.

Hello, I need help in finding files older than x days and creating a single consolidated tar file combining them. Can anyone please provide me a script? Thanks, Dawn (3 Replies)
Discussion started by: Dawn Bosch
3 Replies

9. UNIX for Advanced & Expert Users

How to create a Tar of multiple Files in Unix and FTP the tar to Windows.

Hi, On my Unix Server in my directory, I have 70 files distributed in the following directories (which have several other files too). These files include C Source Files, Shell Script Source Files, Binary Files, Object Files. a) /usr/users/oracle/bin b) /usr/users/oracle... (1 Reply)
Discussion started by: marconi
1 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

Featured Tech Videos