script for Gzip thousands of file


 
Thread Tools Search this Thread
Operating Systems Solaris script for Gzip thousands of file
# 8  
Old 12-30-2007
The below code can be run as a whole script. Run it from an appropriate directory, for example /home/username.

Code:
# In the beginning it's good to create a temp directory temp_dir that will contain only the gzipped files.

mkdir /home/temp_dir

cd /home/mmc
for i in `ls | xargs file | awk -F: '! /gzip/{print $1}'`
do
gzip $i
mv $i".gz" /home/temp_dir/
done

# Now cd to temp_dir to remove extension gz from files just created 

cd /home/temp_dir
for i in `ls`
do
mv $i "$(basename $i .gz)"
done

# Now if you need the just created files to be moved to your specific directory say /home/ttc, while you are still at /home/temp_dir do a mv

mv * /home/ttc


Code:
ls | xargs file | awk -F: '! /gzip/{print $1}'

ls | xargs file --> list files and execute the file command ( to find out the file type)
awk -F: '! /gzip/{print $1}' --> from the results give me only the files that are not zipped, ( ! /gzip/).


Last edited by rubionis; 04-15-2008 at 06:50 PM.. Reason: code tags
# 9  
Old 12-30-2007
Quote:
Originally Posted by thepurple
what is the the meaning of the abve code? mainly 2> /dev/null
gzip will report that a file is not in gzip format. 2>/dev/null discards the standard error output.

Code:
$ gzip -t blah

gzip: blah: not in gzip format

$ gzip -t blah 2>/dev/null
$

# 10  
Old 01-02-2008
Hi Rubionis,

Many thanks. Script runs well.
# 11  
Old 01-02-2008
thanks Frank for the information
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script not able to zip the file using gzip

Hi all, I am calling Temp.sh and it is has simple line $gpath=`which gzip` $gpath $FilePath/My_temp.log if I run this script, logging to server then its works fine. But when I send this script over the SSH it does not work at it. gzip is command is not execute. I am using gzip 1.6... (2 Replies)
Discussion started by: girijajoshi
2 Replies

2. Shell Programming and Scripting

Help/How-to - simple UNIX script / gzip (beginner)

Hey all, I would like to ask your help and sorry in advance for my ignorance since I am a complete beginner in this. I need to create a UNIX script that will: - scan a small number of folders and subfolders (see a similar file tree in the attachment) - - for each final folder (each of... (8 Replies)
Discussion started by: McNulty
8 Replies

3. Shell Programming and Scripting

help with a script to gzip/move files

Hi Please can you help me in writing a script to find files on a specific directory, and of extension "tap" but only of the month of september, gzip and move them to another directory. Your help will be appreciated. (4 Replies)
Discussion started by: fretagi
4 Replies

4. UNIX for Advanced & Expert Users

gzip vs pipe gzip: produce different file size

Hi All, I have a random test file: test.txt, size: 146 $ ll test.txt $ 146 test.txt Take 1: $ cat test.txt | gzip > test.txt.gz $ ll test.txt.gz $ 124 test.txt.gz Take 2: $ gzip test.txt $ ll test.txt.gz $ 133 test.txt.gz As you can see, gzipping a file and piping into gzip... (1 Reply)
Discussion started by: hanfresco
1 Replies

5. Shell Programming and Scripting

gzip and encrypted in a shl script

After I move the file to a directory, I need to gzip and encrypted. I never do this in a shl script, I do it from the command line and it works.. cd /home/nelnet spinel:/home/nelnet$ gpg -e 2010_11_07_05_11_xxxxxx_bills.dat.gz `/home/nelnet/.gnupg/gpg.conf' `/home/nelnet/.gnupg/gpg.conf'... (3 Replies)
Discussion started by: rechever
3 Replies

6. Shell Programming and Scripting

script with dates to gzip and remove

Good morning all! I am new to programming and trying to learn; please be patient. I am wanting to write a script that takes the current date and gzip 5 days or older, then remove 10 days or older. This is the directory I want to work in; this is what it looks like ... (2 Replies)
Discussion started by: bigben1220
2 Replies

7. Solaris

gzip a file and append creation date stamp to file

I want to gzip a file and append the creation date to the end of the file. How can I accomplish this task. Basically they are log files which need a creation date stamp appended to make sure they do not overwrite other log files. -jack (3 Replies)
Discussion started by: jacktravine
3 Replies

8. UNIX for Dummies Questions & Answers

How to truncate thousands of file names

Folder of e-mails in maildir format had been corrupted. Typical file name is 1246281161.6777.m21JH:2,S . The " :2,S prevents " copying to another device. How can I simply remove the last four characters? (2 Replies)
Discussion started by: steve900
2 Replies

9. UNIX for Dummies Questions & Answers

How do I send a file as an attachment (gzip file) on a Unix system

Hi, How do I send a file as an attachment (gzip file) on a Unix system ? Using sendmail. Please help me. :confused: (3 Replies)
Discussion started by: lacca
3 Replies

10. Shell Programming and Scripting

gzip in shell script called by cron

I'm puzzled by this one. I hope you can explain it to me. I have a ksh shell script that gzips a file among other things. This works perfectly fine when the script is manually run through a shell. However, when the same script is run through cron, it does everything correctly, but it will... (2 Replies)
Discussion started by: hbau419
2 Replies
Login or Register to Ask a Question