The Linux file system can be thought of as a single abstract "tree." When you add files on a removable device—such as a floppy drive or CD-ROM—or a remote system, these subsidiary file systems are "grafted" onto the original file system at a mount point.
Mount points are usually empty directories.
A mount point—and, indeed, the entire abstract tree—has no relationship with physical reality. This behavior is different than in Microsoft Windows, where the files and directories on drive E are all on the logical or physical drive E.
Actually, the term file system has two meanings:
The entire Linux abstract file system
A subsection, or "branch," of the file system tree: in other words, a directory, possibly with subdirectories
Generally, it is apparent from the context which usage is meant.
There's no requirement that a Linux file system be organized in a particular way, but over time a kind of organizational convention has grown up. The root file system includes the root directory, the Linux kernel, /dev for device files, /etc for critical system files, and /bin for important utilities. Other standard directories and their contents are listed in Table 11.3.
It's also important to understand that every Linux file has a mode. The mode of a file controls who can read, write, and execute the contents of a file; it is also called the file's permissions. Generally only the owner of a file or the root superuser can change a file's permissions.
File systems are extended by mounting devices, such as a CD-ROM, floppy drive, or removable hard drive.
To mount and dismount a file system:
Standard Linux Directories and Their Contents | |
---|---|
Path Name | Contents |
/ | The root directory |
/bin, /sbin | Important utilities necessary for minimum system operability |
/dev | Device files for terminals, disks, modems, and so on |
/etc | Critical system files |
/tmp | Temporary files that disappear between reboots |
/usr/bin | Executable files |
/usr/lib | Support files for standard Linux programs |
/usr/man | Man pages |
/usr/src | Source code |
/var/log | Log files |
/var/spool | Spooling directories for printers, mail, and so on |
/var/tmp | Temporary space (files that don't disappear between reboots) |
To mount a CD-ROM:
1. | At the prompt, type mount /dev/cdrom /mnt/cdrom |
2. | Press Enter. |
To unmount a CD-ROM:
1. | At the prompt, type umount /dev/cdrom or umount /mnt/cdrom |
2. | Press Enter. |
To mount a floppy drive:
1. | At the prompt, type mount /dev/fd0 /mnt/floppy |
2. | Press Enter. |
To unmount a floppy drive:
1. | At the prompt, type umount /dev/fd0 or umount /mnt/floppy |
2. | Press Enter. |
To mount a device using Gnome:
1. | Log on as root. |
2. | On the Gnome desktop, open the Linux Configuration applet on the control panel. |
3. | |
4. | Select a device to mount it: for example, /dev/cdrom. |
5. |
Tip
You can use the control panel to unmount devices as well.
Directories are the containers for other Linux directories and files. Most likely, every time you start a new project or want to group related files together, you will create a directory.
To create a new directory:
1. | Move to the location in the directory tree where you want to create the new directory. |
2. | At the command prompt, type mkdir mynewdir |
3. | Press Enter. |
4. | Type ls -l to list the current directories. You will see mynewdir listed with a "d" in the leftmost column, indicating that it is a directory (Figure 11.8). |
Tip
If you try to create a directory using a name that already exists within the container directory, you will receive a message stating that a file of that name already exists, proving once again that directories are files in Linux.
Tip
The following are illegal characters in Linux file and directory names: <> {} [] () "" " * ? | / ^ ! # $ & ~
Tip
In addition to the illegal characters, avoid using spaces and dashes (-). Some Linux programs cannot handle them.
To delete a directory:
1. | Using the cd command, navigate to the parent of the directory you want to delete. |
2. | At the prompt, use the rmdir command to remove the directory: for example, type rmdir mynewdir. |
3. | Press Enter. |
If directories are the filing system, then files are the contents.
To list all files in a directory:
1. | At the prompt, type ls -al. |
2. |
Tip
The -l flag displays full information about the files; the -a flag displays all files, including hidden files. For more information on ls flags, see Appendix A.
To create a file:
1. | At the prompt, type touch followed by the new file name. For example, type touch happy.file |
2. | Press Enter. |
Tip
There are many ways to create files. One approach is to use a text editor such as vi.
To copy a file (or directory):
cp myfileordir yourfileordir
To move a file (or directory):
mv thefileordir /newloc/thefileordir
To delete a file:
1. | |
2. | Press Enter. |
Tip
The rm command, depending on the flags you use, and whether you are logged on as root, can be extremely dangerous. For example, the -f flag removes write-protected files without prompting, and the -r flag deletes files and directories recursively. This means that if root issues the command rm -rf, the entire file system could be removed. Don't try this at home!
To find a file:
find /home/hdavis/ch11 -name _ '*fig*' -print
To find text within a file (or files):
grep -n -3 elephant *
To view the beginning of a file:
1. | Type head myfile. |
2. | Press Enter. The first 10 lines of the file will be displayed. |
Tip
You can use the head command to view as many files as you want: for example, head -42 myfile displays the first 42 lines of myfile.
Tip
You can view the beginnings of multiple files by piping them to more: for example, head -5 my* | more
To view the end of a file:
1. | Type tail myfile. |
2. | Press Enter. The last 10 lines of the file will be displayed. |
Tip
As with the head command, you can determine the number of lines that are displayed and display multiple files in a single tail command.
Tip
The tail command is useful for keeping track of the most recent changes to log files when you are tracking or debugging the operation of a program—such as a database engine—that writes to a log file as it progresses.
3.143.0.85