Following are the list of files available in the dataout directory
a1.txt.gz
a2.txt.gz
b3.txt.gz
Step 1:
now the tar file needs to be created as follows.
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
methyl
April 9, 2012, 5:17pm
2
Please post a sample with extn .gzq
.
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.
With GNU tar:
tar cvf archive.tar *.gz --remove-files
[ $(du -b archive.tar | awk '{print $1}') -gt 1600000000 ] && echo "file size is high" || echo "file size is low"
seems, you want to remove the .gz files are creating tar file ?
tar -cvf ab.tar *.gz && rm *.gz
thank you itkamaraj and balajesuri.
only the following command works for me.
tar -cvf ab.tar *.gz && rm *.gz
the following command to get the file size is not working...
[ $(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
methyl
April 10, 2012, 8:48am
7
[ $(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:
[ $(du archive.tar | awk '{print $1}') -gt 3125000 ] && echo "file size is high" || echo "file size is low"
1 Like
I am facing a new problem when creating a tar file.
Initially the files are available in the directory /home/krishna/test/dataout
a1.txt.gz
b1.txt.gz
c1.txt.gz
using the command tar -cvf abc.tar *.gz && rm -f *.gz, the 3 files are bundled and
removed from the directory /home/krishna/test/dataout
Now the tar file abc.tar will be moved to a different directory
/home/krishna/FileTransfer
When I untar it, i am expecting the files *.gz files to present in the directory /home/krishna/FileTransfer and not in /home/krishna/test/dataout
I realized that during creating a tar file, the folder/directory structure will be copied.
Can any one help me out to untar file in the folder where the tar file resides. (/home/krishna/FileTransfer)
Thanks
Krishnakanth
methyl
April 10, 2012, 12:05pm
10
What do you get from this command to list the contents of the tar file:
tar -tvf abc.tar
This will tell you whether you have absolute paths in the archive or not. None of the code you post would produce absolute paths in the archive.
Do you have the pax
command ? It can read tar archives containing absolute paths and output to a different directory.
1 Like
It worked... if i didnot mention any directory/paths...
Thank you all.
Krishnakanth