-->
Previous Table of Contents Next


You can use touch to fool a command that checks for dates. For example, if your system runs a backup command that backs up only files modified after a particular date, you can touch a file that hasn’t been changed recently to make sure that it’s picked up.

The touch command has the following three flags that you can use to modify its default behavior:

-a Updates only the file’s access date and time stamp
-m Updates only the file’s modification date and time stamp
-c Prevents touch from creating a file if it doesn’t already exist

The default syntax for touch is touch -am filelist.

Compressing Files

If space is tight on a system or you have large ASCII files that aren’t used often, you can reduce the size of the files by compressing them. The standard Linux utility for compressing files is gzip. The gzip command can compress an ASCII file by as much as 80 percent. Most UNIX systems also provide the command compress, which typically is used with tar to compress groups of files for an archive. A file compressed with the compress command ends with a .Z extension—for example, archive1.tar.Z. Red Hat’s distribution also provides the zip and unzip programs for compressing and archiving lists of files.


TIP:  It’s a good idea to compress a file before you mail it or back it up.

If a file is successfully compressed with the command gzip filename, the compressed file is named filename.gz, and the original file is deleted. To restore the compressed file to its original components, use the gunzip filename command.


NOTE:  You don’t have to append the .gz to the filename when you uncompress a file. The .gz extension is assumed by the gunzip command.

If you want to keep the file in its compressed form but want to pipe the data to another command, use the zcat command. The zcat command works just like the cat command but requires a compressed file as input. zcat decompresses the file and then prints it to the standard output device.


See “Connecting Processes with Pipes,” p. 355

For example, if you’ve compressed a list of names and addresses stored in a file named namelist, the compressed file is named namelist.gz. If you want to use the contents of the compressed file as input to a program, use the zcat command to begin a pipeline, as follows:


zcat namelist | program1 | program2

zcat suffers from the same limitation cat does: It can’t go backward within a file. Linux offers a program called zless that works just like the less command, except zless operates on compressed files. The same commands that work with less also work with zless.

The compress command’s legal status is in limbo; someone has claimed patent infringement. The compression program of choice for Linux is the freely distributed compression utility gzip. The gzip command has none of the potential legal problems of compress, and almost all the files installed by Linux that are compressed were compressed with gzip. gzip should work with most compressed files, even those compressed with the older compress program.

For those of you familiar with PKWARE’s PKZIP line of products, you can use the zip and unzip programs provided with the Red Hat distribution. The zip command compresses several files and stores them in an archive, just like PKZIP. The unzip command extracts files from an archive. See the man pages for zip and unzip for more information.

From Here…

Managing files and utilities in Linux is a relatively simple chore. Organizing files into directories is easy. Finding, moving, copying, renaming, and deleting files and directories are simple with the commands find, mv, cp, and rm. For more information, see the following:

  Chapter 14, “Managing File Systems,” which discusses practices for keeping your file system under control.
  The man pages for the various commands discussed in this chapter: ls, mkdir, mv, cp, rm, rmdir, cat, less, more, find, touch, gzip, compress, tar, zip, and unzip.


Previous Table of Contents Next