-->
Previous | Table of Contents | Next |
The rm command works primarily with files. If you try to delete a directory with rm, an error message displays. The command normally used to remove (delete) directories is rmdir. The syntax is rmdir <directory>.
Before you can remove a directory, it must be empty (the directory cant hold any files or subdirectories). Otherwise, you see
rmdir: <directory>: Directory not empty
This is as close to a safety feature as you will see in Linux!
This one might baffle you:
darkstar:/home$ ls fido/ root/ zippy/ darkstar:/home$ ls zippy core kazoo stuff darkstar:/home$ rm zippy/* darkstar:/home/zippy$ ls zippy darkstar:/home$ rmdir zippy rmdir: zippy: Directory not empty darkstar:~$
The reason for the Directory not empty message is that files starting with . are usually special system files that are usually hidden from the user. To list files whose names start with ., you have to use ls -a. To delete these files, use rm .*:
darkstar:/home$ ls -a zippy ./ ../ .bashrc .profile darkstar:/home$ rm zippy/.* rm: cannot remove . or .. darkstar:/home$ ls -a zippy ./ ../ darkstar:/home$ rmdir zippy darkstar:/home$ ls fido/ root/ darkstar:~$
You will most often come across this situation in a system administrator role.
Sometimes you want to remove a directory with many layers of subdirectories. Emptying and then deleting all the subdirectories one by one is very tedious. Linux offers a way to remove a directory and all the files and subdirectories it contains in one easy step. This is the r (recursive) option of the rm command. The syntax is rm -r <directory>. The directory and all its contents are removed.
Warning:
You should use rm -r only when you absolutely have to. To paraphrase an old saying, Its only a shortcut until you make a mistake. For example, if youre logged in as root, the following command removes all files from your hard disk, and then its Hello, installation procedure time (do not type the following command!):rm -r /Believe it or not, people do this all too often. Dont join the club!
Most Linux files are stored on the installation CD-ROM in compressed form. This allows more information to be stored. If you work with DOS or Windows, you may have seen utilities that ZIP files into a larger library. Utilities such as PKZIP and WINZIP are very popular in those operating systems. The same type of technique has been used by UNIX for decades, although a different name and compression technique are used.
When you install Linux, the installation program uncompresses many of the files it transfers to your hard drive. However, if you look, you will be able to find compressed files!
Any file ending in .gzfor example, squashed.gzis a compressed file. To uncompress this particular type of file, type gunzip <file>. For this example, type gunzip squashed.gz. The gunzip program creates an uncompressed file and removes the .gz extension. Therefore, you wind up with a normal file called squashed. To compress a file, use the gzip command. Typing gzip squashed compresses squashed and renames it squashed.gz.
Another type of compressed file you may see ends with the extension .zip. Use unzip to uncompress these files. To create files of this type, use zip.
Theres a couple of other compression systems used by Linux. These provide compressed files ending with .Z or .z (the two are not produced by the same compression tool).
Most of the directories that hold Linux system files are standard. Other UNIX systems will have identical directories with similar contents. This section summarizes some of the more important directories on your Linux system.
This is the root directory. It holds the actual Linux program, as well as subdirectories. Do not clutter this directory with your files!
This directory holds users home directories. In other UNIX systems, this can be the /usr or /u directory.
This directory holds many of the basic Linux programs. bin stands for binaries, files that are executable and which hold text only computers can understand.
This directory holds many other user-oriented directories. Some of the most important are described in the following sections. Other directories found in /usr include
docs | Various documents, including useful Linux information |
man | The man pages accessed by typing man <command> |
games | The fun stuff! |
This directory holds user-oriented Linux programs.
This directory has several subdirectories. mail holds mail files, spool holds files to be printed, and uucp holds files copied between Linux machines.
Linux treats everything as a file! The /dev directory holds devices. These are special files that serve as gateways to physical computer components. For instance, if you copy to /dev/fd0, youre actually sending data to the systems floppy disk. Your terminal is one of the /dev/tty files. Partitions on the hard drive are of the form /dev/hd0. Even the systems memory is a device!
A famous device is /dev/null. This is sometimes called the bit bucket. All information sent to /dev/null vanishesits thrown into the trash.
This directory holds system administration files. You must be the root user to run most of these commands.
This directory holds system files that are usually run automatically by the Linux system.
Previous | Table of Contents | Next |