Results 1 to 7 of 7
This command compresses all files in a directory and it's subdirectory and replaces them by compressed files.
$ gzip --recursive --best ./*
But how to make gzip compress the files ...
- 12-08-2007 #1Just Joined!
- Join Date
- Jul 2007
- Posts
- 6
Gzipping without replacing original
This command compresses all files in a directory and it's subdirectory and replaces them by compressed files.
$ gzip --recursive --best ./*
But how to make gzip compress the files but leave the original files alone? (Not replacing.)
- 12-08-2007 #2Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
Code:find ./* -type f | while read file do gzip --best <$file >$file.gz done
- 12-08-2007 #3Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
This is on the first screen of man gzip ... cheers, drl
The man command (with experimentation) is one of your best friends ... cheers, drlDESCRIPTION
Gzip reduces the size of the named files using Lempel-Ziv coding
(LZ77). Whenever possible, each file is replaced by one with the
extension .gz, while keeping the same ownership modes, access and modi-
fication times. (The default extension is -gz for VMS, z for MSDOS,
OS/2 FAT, Windows NT FAT and Atari.) If no files are specified, or if
a file name is "-", the standard input is compressed to the standard
output. (emphasis mine)Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 12-08-2007 #4Just Joined!
- Join Date
- Jul 2007
- Posts
- 6
- 12-09-2007 #5Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
Yes, in my code it's the shell that's opening and truncating the output file so gzip knows nothing about it. > will always truncate an existing file (as I've sometimes learned to my detriment when I get the input redirection character wrong!).
- 12-09-2007 #6Just Joined!
- Join Date
- Jul 2007
- Posts
- 6
Thank you.
I did not know that about ‘>’. (Even though I have seen it used many times.)
- 12-09-2007 #7Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
Knowing that the shell takes care of re-direction and how it can destroy files is valuable information, and the attending lesson is one many of us re-learn from time to time
There are mechanisms in most shells to protect one's files. Here is how it works in bash:
producing:Code:#!/usr/bin/env bash # @(#) s1 Demonstrate over-writing files with re-direction. set -o nounset echo debug=":" debug="echo" ## Use local command version for the commands in this demonstration. echo "(Versions displayed with local utility \"version\")" version >/dev/null 2>&1 && version bash # Remove debris. rm -r t1 echo echo " Create a file:" echo Hello >t1 cat t1 echo echo " Clobber the file:" echo Goodbye >t1 cat t1 echo echo " Set protection on:" set -o noclobber echo Oops >t1 cat t1 exit 0
See man bash for details.Code:% ./s1 (Versions displayed with local utility "version") GNU bash 2.05b.0 Create a file: Hello Clobber the file: Goodbye Set protection on: ./s1: line 33: t1: cannot overwrite existing file Goodbye
On my system, noclobber is off by default in bash (I use tcsh for interactive work, and it's on there -- many a file has been saved thereby which otherwise would have be destroyed by a slip of the mind and fingers) ... cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )


Reply With Quote
