Bash: Gzip files in Directory and itīs Subdirectories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash: Gzip files in Directory and itīs Subdirectories
# 1  
Old 02-10-2010
Bash: Gzip files in Directory and itīs Subdirectories

Hello dear Community,
I have a task to wrtie a script which will gzip not zipped files in a directory and itīs subdirectories. I succeeded in gzippung the directory but not the subdirectories:

Code:
#/bin/bash
#go to the directory where to zip
cd $1
#Zip unzipped files
for i in `ls | xargs file | awk -F: ' ! /gzip/{print $1}'`
do
gzip $i

done

I am a newby at scriptiung. Found the above script in parts somwehre in the web.

What do I must add to let the script zip files in subdirectories of the directory aswell as files in the directory.
pls Help Smilie
# 2  
Old 02-10-2010
From the man page of gzip:
Quote:
-r --recursive
Travel the directory structure recursively. If any of the file
names specified on the command line are directories, gzip will
descend into the directory and compress all the files it finds
there (or decompress them in the case of gunzip ).
It will even automagically skip files it know are already compressed using gzip.
# 3  
Old 02-10-2010
Thanks a lot Smilie
it worked just fine for me Smilie

Code:
...
gzip -r $i
...

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to create new directory by date followed by identifier and additional subdirectories

I have a bash that downloads a list and if that list has data in it then a new main directory is created (with the date) with several subdirectories (example1, example2, example3). My question is in that list there are portion of specific file types (.vcf.gz) - identifier towards the end that have... (0 Replies)
Discussion started by: cmccabe
0 Replies

2. Shell Programming and Scripting

Append string to all the files inside a directory excluding subdirectories and .zip files

Hii, Could someone help me to append string to the starting of all the filenames inside a directory but it should exclude .zip files and subdirectories. Eg. file1: test1.log file2: test2.log file3 test.zip After running the script file1: string_test1.log file2: string_test2.log file3:... (4 Replies)
Discussion started by: Ravi Kishore
4 Replies

3. Shell Programming and Scripting

Bash script monitor directory and subdirectories for new pdfs

I need bash script that monitor folders for new pdf files and create xml file for rss feed with newest files on the list. I have some script, but it reports errors. #!/bin/bash SYSDIR="/var/www/html/Intranet" HTTPLINK="http://TYPE.IP.ADDRESS.HERE/pdfs" FEEDTITLE="Najnoviji dokumenti na... (20 Replies)
Discussion started by: markus1981
20 Replies

4. Shell Programming and Scripting

Bash script deleting my files, and editing files in subdirectories question

#!/bin/bash # name=$1 type=$2 number=1 for file in ./** do if then filenumber=00$number elif then filenumber=0$number fi tempname="$name""$filenumber"."$type" if (4 Replies)
Discussion started by: TheGreatGizmo
4 Replies

5. Shell Programming and Scripting

gzip files inside directory

Hello folks I hope every one is fine. I need to ask one question. I have directory /xx/abcd/data/ inside that data there are files like 11.txt 23.txt 12.txt *.txt i want that i will do compress each txt file inside that directory /xx/abcd/data/. But it will not gzip data... (1 Reply)
Discussion started by: learnbash
1 Replies

6. Shell Programming and Scripting

Loop through subdirectories to gzip files

I have a directory has many subdirectories. Each subdirectories has several very large files. Some of the large files already compressed (*.Z). I need to uncompress those files if they are *.Z files then gzip them to save more space. But those files are too large so they can only be done uncompress... (2 Replies)
Discussion started by: visio2000
2 Replies

7. UNIX for Dummies Questions & Answers

Find Files in a Directory Excluding Subdirectories

Hi, I have a filename Location.txt in a directory /abc. Similar name file is present in its subdirectory /abc/xyz. I want to find the file which is present only in /abc and not in /abc/xyz. Please any1 of u can provide a quick suggestion. Its very urgent. Thanks, Amol (2 Replies)
Discussion started by: Amol_Dicholkar
2 Replies

8. UNIX for Dummies Questions & Answers

How to remove directory with subdirectories and files?

I'm trying to remove several directories which contains sun-dirs and files inside. I used the command rm -r <dirname> But, it always ask "examine file in directory <dirname> yes/no?" line by line. So, i need to write "y" for every line. How can i skip this step and remove all directories with... (9 Replies)
Discussion started by: ppa108
9 Replies

9. Shell Programming and Scripting

search files in a directory and its subdirectories

Hello my friends, I need to write a simple shell bad file :D that search and delete a file it's name 'Microsoft.txt' in the current directory and its subdirectories? So can you help to guide me how i can write this shell, Just give me the beginning :o thank you. (1 Reply)
Discussion started by: Net-Man
1 Replies

10. UNIX for Dummies Questions & Answers

gzip all the files in a directory

Hi, There are multiple files in a directory with different names.How can they be gzipped such that the timestamp of the files is not changed. (2 Replies)
Discussion started by: er_ashu
2 Replies
Login or Register to Ask a Question