Sponsored Content
Top Forums Shell Programming and Scripting Check if file compressed or not Post 302088723 by badg3r on Thursday 14th of September 2006 04:58:56 AM
Old 09-14-2006
compress ALL non compressed files in a directory

I have now finished my script that will compress all uncompressed files in a directory, thought I'd post it to help anyone else out.
Code:
#!/bin/ksh

TEST_FILE=/tmp/tester$$
FILE=/tmp/result$$



#first cd to dir 
DIR=/u02/waptv/test

#then run file command to see what files are

for f in ${DIR}/*
do
     file $f >> $TEST_FILE
     done

#Now file TEST_FILE has many things in we need to exclude , such as the compressed files and scripts

cat $TEST_FILE|grep -v compressed|grep -v .sh  > $FILE

#now we have only the non compressed files

#remove colon and whitespace and add a gzip (or compression of choice) to the beginning of the output
TMP=/tmp/temp$$
cat $FILE | awk '{print $1}' | sed -e 's/[ \t]*$//' -e 's/\://g' -e 's/^/gzip /' >$TMP
mv $TMP $FILE

#Execute output which will compress all the files
. $FILE
# for testing cat $FILE

Hope that helps someone else too.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Import data from compressed file

HI I need to import data from a file which is in comressed format but system doesn't have enough space to uncompress file Is there any way so that i can do import from compressed file. (4 Replies)
Discussion started by: ap_gore79
4 Replies

2. UNIX for Dummies Questions & Answers

renaming a compressed file to filename without .Z

In a shell script I would like to use a compressed file name, i.e. with suffix of .Z, as a file input $1. After the file in uncompressed, I would like to use the file name without the .Z . How do I do this? Thank you. (8 Replies)
Discussion started by: bruceps
8 Replies

3. UNIX for Advanced & Expert Users

Is it possible to see the content of the compressed file?

How we can view the content of the file,if it compressed (or) Zipped ,without uncompress ? I have one file ,i compressed it,without uncompressing the file.Is it possible to see the content of the file? (2 Replies)
Discussion started by: bobprabhu
2 Replies

4. Shell Programming and Scripting

check to see if a file is compressed before trying to compress

I simply need to compress all files in a directory that are not already compressed and that are older than 10 days? I have this so far. I need to add to this so I don't try and compress file that are already compressed. Or if you think this can be simplified let me know. Thx. find... (3 Replies)
Discussion started by: rstone
3 Replies

5. UNIX for Dummies Questions & Answers

compressed file

I compressed a file by using gzip command gzip <<xx>> filename changed to xx.gz How to view this xx.gz file. Any idea. Thanks in advance. (7 Replies)
Discussion started by: venkatesht
7 Replies

6. Shell Programming and Scripting

Unix Commands to check a file is compressed or not?

Hi, I need to find out whether a file is compressed or not and based on that i need to compress that file and move it to archive folder. say for e.g: If file is compressed then just move to archive folder else compress and move end if i have implemented a... (2 Replies)
Discussion started by: kk17
2 Replies

7. Shell Programming and Scripting

Process a compressed file

Hi i have a filename.tar.bz2 and i have to parse it with a tool that doesn't support compressed files. I have to do it for many big files, so i can't decompress and then process. I'd like to do something like: tar -jxvf namefile.tar.bz2 | parsing_tool i mean analyze it directly,... (4 Replies)
Discussion started by: Dedalus
4 Replies

8. Shell Programming and Scripting

compressed file

i have a file 4d7a94d0.bbb.1292 when i do file 4d7a94d0.bbb.1292 the ouput is below 4d7a94d0.bbb.1292: gzip compressed data - deflate method and i run this command gunzip -c 4d7a94d0.bbb.1292 | awk '{gsub("\"","")}/I_ACCOUNT_ID/{print $2}' RS=":|;" FS="," i get... (3 Replies)
Discussion started by: blackzinga80
3 Replies

9. Shell Programming and Scripting

Get Compressed byte offset from .gz file

Hi , I have a .gz file whose contents look like below. data1^filename1 data2^filename2. .. . . Is it possible to find out the byte offset of each record from the .gz file. Like in an uncompressed file. grep -nb "Filename" give the byte offset of the record in this case. ... (4 Replies)
Discussion started by: chetan.c
4 Replies

10. UNIX for Dummies Questions & Answers

Size of compressed file

Hi All, Is there is any way to find the size of compressed file without doing decompression. The size should give the original uncompressed data size Thanks Arun (3 Replies)
Discussion started by: arunkumar_mca
3 Replies
GZEXE(1)						    BSD General Commands Manual 						  GZEXE(1)

NAME
gzexe -- create auto-decompressing executables SYNOPSIS
gzexe [-d] file ... DESCRIPTION
The gzexe utility uses gzip(1) to compress executables, producing executables that decompress on-the-fly when executed. This saves disk space, at the cost of slower execution times. The original executables are saved by copying each of them to a file with the same name with a '~' suffix appended. After verifying that the compressed executables work as expected, the backup files can be removed. The options are as follows: -d Decompress executables previously compressed by gzexe. The gzexe program refuses to compress non-regular or non-executable files, files with a setuid or setgid bit set, files that are already com- pressed using gzexe or programs it needs to perform on-the-fly decompression: sh(1), mktemp(1), rm(1), echo(1), tail(1), gzip(1), and chmod(1). SEE ALSO
gzip(1) CAVEATS
The gzexe utility replaces files by overwriting them with the generated compressed executable. To be able to do this, it is required that the original files are writable. BSD
January 26, 2007 BSD
All times are GMT -4. The time now is 10:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy