-->
Previous | Table of Contents | Next |
When you installed Linux, your setup program probably set up a partition specifically for the swap space. You can, when the original installation is completed, set Linux to use a file instead of the partition, thus freeing up the partitions disk space.
Generally, there is a performance degradation with using a file because the file system is involved, although the effect can be negligible on fast disks and CPUs. However, this is a useful technique when you need to add more swap space, such as when you temporarily want to run a swap-spaceintensive application such as a compiler.
To create a file used as the swap space, issue the following command:
dd if=/dev/zero of=/swap bs=1024 count=16416
This creates a file (called swap) for swap space that is about 16MB (in this case, 16,416 blocks). If you want a different size, replace the number after count with the correct value in bytes. Next, physically create the file swap file with the following command:
mkswap /swap 16416
The number should match the blocks determined earlier. Turn the swap space on with the following command:
swapon /swap
If you want to remove the swap file and use the swap partition, use the following command followed by a standard rm command to remove the file:
swapoff /swap
Swap files cant be larger than 16MB with most Linux versions, but you can have up to eight swap files and partitions on your system.
Files abound on a UNIX system, adding up to a large chunk of disk real estate. Instead of deleting files, an alternative is to compress them so that they take up less space. Several compression utilities are available for UNIX and Linux systems. The most commonly used are compress and the newer GNU gzip.
When run on a file, compress creates a smaller file with the extension .Z, which immediately identifies the file as being compressed. To compress a file, use the following command:
compress filename
You can also use wildcards to compress several files at once. compress supports a number of options, but most arent used often. By default, when a file is compressed, the uncompressed original is deleted, although this can be changed with a command-line option.
To uncompress a compressed file, run the uncompress program:
uncompress filename
Alternatively, you can use a wildcard such as *.Z to uncompress all the compressed files. Remember to include the .Z suffix when specifying the filename.
The gzip utility is a new compression tool that uses different algorithms than compress. The gzip program has a few extra features that were added since compress was released, such as adjustable compression (the more compression required, the longer it takes to compress). To use gzip, specify the filename to be compressed and the compression type:
gzip -9 filename
The -9 option, which tells gzip to use the highest compression factor, will probably be the option you use the most. Alternatively, leave this option off and let gzip work with its default settings. A gzip compressed file has the extension .gz appended, and the original file is deleted. To uncompress a gzipped file, use the gunzip utility.
The tar (tape archiver) utility has been used with UNIX systems for many years. Unfortunately, its not very friendly and can be quite temperamental at times, especially when youre unfamiliar with the syntax required to make tar do something useful.
The tar program is designed to create a single archive file, much as the ZIP utilities do for DOS. With tar, you can combine many files into a single larger file, which makes it easier to move the collection or back it up to tape. The general syntax used by tar is as follows:
tar [options] [file]
The options available are lengthy and sometimes obtuse. Files can be specified with or without wildcards. A simple example of creating a tar archive file is as follows:
tar cvf archive1.tar /usr/tparker
This command combines all the files in /usr/tparker into a tar archive called archive1.tar. The c option tells tar to create the archive; the v tells it to be verbose, displaying messages as it goes; and the f tells it to use the filename archive1.tar as the output file.
The extension .tar is not automatically appended by tar, but is a user convention that helps identify the file as an archive. This convention isnt widely used, although it should be because it helps identify the file.
The c option creates new archives. (If the file existed before, it is deleted.) The u (update) option is used to append new files to an existing archive or to create the archive if it doesnt exist. This is useful if you keep adding files. The x option is used to extract files from the archive. To extract all the files in the archive in the earlier example with the tar command, use the following command:
tar xvf archive1.tar
Theres no need to specify a filename, because the filenames and paths are retained as the archive is unpacked. Its important to remember that the path is saved with the file. So if you archive /usr/tparker and then move into /usr/tparker and issue the extract command, the files are then extracted relevant to the current directory, which places them in /usr/tparker/usr/tparker. You must be very careful to extract files properly. If you want to force a new directory path on extracted files, a command-line option allows this.
The tar system does not remove the original files as they are packed into the archive nor does it remove the archive file when files are extracted. These steps must be performed manually.
You can use tar to copy files to tapes or floppies by specifying a device name and the f option as a device name. To archive files in /usr/tparker to a floppy disk in the first drive, you could use the following command:
tar cvf /dev/fd0 /usr/tparker
This can cause a problem if the floppy doesnt have enough capacity, however, so tar lets you specify the capacity with the k option. In this case, the command for a 1.44MB floppy is as follows:
tar cvfk /dev/fd0 1440 /usr/tparker
Previous | Table of Contents | Next |