Archive and Compress Files Recursively Using gzip-rIf you want to use gzip on several files in a directory, just use a wildcard. You might not end up gzipping everything you think you will, however, as this example shows. $ ls -F bible/ moby-dick.txt paradise_lost.txt $ ls -l * -rw-r--r-- scott scott 1236574 moby-dick.txt -rw-r--r-- scott scott 508925 paradise_lost.txt bible: -rw-r--r-- scott scott 207254 genesis.txt -rw-r--r-- scott scott 102519 job.txt $ gzip * gzip: bible is a directory -- ignored $ ls -l * -rw-r--r-- scott scott 489609 moby-dick.txt.gz -rw-r--r-- scott scott 224425 paradise_lost.txt.gz bible: -rw-r--r-- scott scott 207254 genesis.txt -rw-r--r-- scott scott 102519 job.txt Notice that the wildcard didn't do anything for the files inside the bible directory because gzip by default doesn't walk down into subdirectories. To get that behavior, you need to use the -r (or --recursive) option along with your wildcard. $ ls -F bible/ moby-dick.txt paradise_lost.txt $ ls -l * -rw-r--r-- scott scott 1236574 moby-dick.txt -rw-r--r-- scott scott 508925 paradise_lost.txt bible: -rw-r--r-- scott scott 207254 genesis.txt -rw-r--r-- scott scott 102519 job.txt $ gzip -r * $ ls -l * -rw-r--r-- scott scott 489609 moby-dick.txt.gz -rw-r--r-- scott scott 224425 paradise_lost.txt.gz bible: -rw-r--r-- scott scott 62114 genesis.txt.gz -rw-r--r-- scott scott 35984 job.txt.gz This time, every fileeven those in subdirectorieswas gzipped. However, note that each file is individually gzipped. The gzip command cannot combine all the files into one big file, like you can with the zip command. To do that, you need to incorporate tar, as you'll see in "Archive and Compress Files with tar and gzip." |