-->
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 hasnt been changed recently to make sure that its picked up.
The touch command has the following three flags that you can use to modify its default behavior:
-a | Updates only the files access date and time stamp |
-m | Updates only the files modification date and time stamp |
-c | Prevents touch from creating a file if it doesnt already exist |
The default syntax for touch is touch -am filelist.
If space is tight on a system or you have large ASCII files that arent 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 extensionfor example, archive1.tar.Z. Red Hats distribution also provides the zip and unzip programs for compressing and archiving lists of files.
TIP: Its 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 dont 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 youve 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 cant 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 commands 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 PKWAREs 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.
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:
Previous | Table of Contents | Next |