Visit Our UNIX and Linux User Community


Unix Commands to check a file is compressed or not?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unix Commands to check a file is compressed or not?
# 1  
Old 09-04-2009
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 logic wherein i am checking for the last character in the file to be 'Z', if it is 'Z' i am not compressing it again and just moving the file or else i am compressing and moving the file. This is working fine in some cases but i want to know whether there is any command to find out whether a file is compressed or not.

Please provide some pointers on this.

Thanks & Regards,
Kiran
# 2  
Old 09-04-2009
file is the command which can show the file type.

When you give "file <FILENAME>", that will show the what type of compression also...


Code:
$ file test.gz 
test.gz: gzip compressed data, from Unix

There could be better ways to use it inside programs.
# 3  
Old 09-04-2009
It depends: the file command on Solaris and Linux will tell you if a file is compressed with either zip, gzip, or compress. On HPUX 10.2 the file command could not do that.

Try the "file" command
Code:
> file ./data//logs/91042131.log.gz
./data/logs/91042131.log.gz:     gzip compressed data - deflate method , original file name , max compression


Previous Thread | Next Thread
Test Your Knowledge in Computers #524
Difficulty: Medium
The ASCII table was designed to enforce a lexicographic ordering: letters are in alphabetic order, uppercase precede lowercase versions, and numbers come after both.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

FTP commands to check the file status

Hi Experts, Can some one let me know the FTP commands to check the file status i.e i want to check whether my files are locked or in open status. I am connecting FTP from local machine. Regards, Spidy (1 Reply)
Discussion started by: spidy
1 Replies

2. UNIX for Dummies Questions & Answers

Unix (compressed archieve, non-verbose)

I'm confusing with this question. :wall: Can any one tell me how to do and use which command? :confused: create a compressed archive of the "Test" directory and it's contents, called Test.tar.gz, and place it in the current directory. Use a non-verbose tar command with a single string, including... (5 Replies)
Discussion started by: wk9031
5 Replies

3. Shell Programming and Scripting

Need unix commands to delete records from one file if the same record present in another file...

Need unix commands to delete records from one file if the same record present in another file... just like join ... if the record present in both files.. delete from first file or delete the particular record and write the unmatched records to new file.. tried with grep and while... (6 Replies)
Discussion started by: msathees
6 Replies

4. Shell Programming and Scripting

Reading UNIX commands from file and redirecting output to a file

Hi All I have written the following script: #!/bin/ksh while read cmdline do echo `$cmdline` pid="$cmdline" done<commands.txt =========== commands.txt contains: ps -ef | grep abc | grep xyz |awk '{print $2}; My objective is to store the o/p of the command in a variable and do... (8 Replies)
Discussion started by: rahulparo
8 Replies

5. UNIX for Advanced & Expert Users

Check EOF char in Unix. OR To check file has been received completely from a remote system

Advance Thanks. (1) I would like to know any unix/Linux command to check EOF char in a file. (2) Or Any way I can check a file has been reached completely at machine B from machine A. Note that machine A ftp/scp the file to machine B at unknown time. (5 Replies)
Discussion started by: alexalex1
5 Replies

6. UNIX for Dummies Questions & Answers

check for a file and run some commands

Hi all, Can you guys please help me with this... I am on AIX and need to prepare a script which will 1. check for a file named do_backup in the current file system 2. If the file exists i need to run some commands and exit, if the file doesn't exist then sleep for 15 mins and try... (2 Replies)
Discussion started by: family_guy
2 Replies

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

8. Shell Programming and Scripting

Is there any commands to check the dynamic changes of a file

Hi guys i had a script which will generate a log file.Is there any commands to check the dynamic changes in the log file,i.e if i open the log file i should able to see the updating changes live...I hope u understand my query... (2 Replies)
Discussion started by: vinoo
2 Replies

9. Shell Programming and Scripting

Unix file editting commands

ok, are there any other file editting commands out there other than the below that comes with sunsolaris & linux vi, emacs, ed, (1 Reply)
Discussion started by: Terrible
1 Replies

10. Shell Programming and Scripting

Check if file compressed or not

Is there a way I can check if a file is comppressed or not? (Be it tar/gzip or compress). trying to write a generic housekeeping scrit that will delete files over 6 months old and compress any uncompressed files if less than 6 months old. But not sure if there is a clever way to check except for... (4 Replies)
Discussion started by: badg3r
4 Replies

Featured Tech Videos