Читать книгу Linux Bible - Christopher Negus - Страница 122
CHAPTER 4 Moving Around the Filesystem IN THIS CHAPTER
ОглавлениеLearning about the Linux filesystem
Listing file and directory attributes
Making files and directories
Listing and changing permission and ownership
Making copies and moving files
The Linux filesystem is the structure in which all of the information on your computer is stored. In fact, one of the defining properties of the UNIX systems on which Linux is based is that nearly everything you need to identify on your system (data, commands, symbolic links, devices, and directories) is represented by items in the filesystems. Knowing where things are and understanding how to get around the filesystem from the shell are critical skills in Linux.
In Linux, files are organized within a hierarchy of directories. Each directory can contain files as well as other directories. You can refer to any file or directory using either a full path (for example, /home/joe/myfile.txt
) or a relative path (for example, if /home/joe
were your current directory, you could simply refer to the file as myfile.txt
).
If you were to map out the files and directories in Linux, it would look like an upside-down tree. At the top is the root directory (not to be confused with the root user), which is represented by a single slash (/
). Below that is a set of common directories in the Linux system, such as bin
, dev
, home
, lib
, and tmp
, to name a few. Each of those directories, as well as directories added to the root directory, can contain subdirectories.
Figure 4.1 illustrates how the Linux filesystem is organized as a hierarchy. To demonstrate how directories are connected, the figure shows a /home
directory that contains a subdirectory for the user joe
. Within the joe
directory are Desktop
, Documents
, and other subdirectories. To refer to a file called memo1.doc
in the memos
directory, you can type the full path of /home/joe/Documents/memos/memo1.doc
. If your current directory is /home/joe/
, refer to the file as Documents/memos/memo1.doc
.
FIGURE 4.1 The Linux filesystem is organized as a hierarchy of directories.
Some of these Linux directories may interest you:
/bin | Contains common Linux user commands, such as ls , sort , date , and chmod . |
/boot | Has the bootable Linux kernel, initial RAM disk, and boot loader configuration files (GRUB). |
/dev | Contains files representing access points to devices on your systems. These include terminal devices (tty* ), hard disks (hd* or sd* ), RAM (ram* ), and CD-ROM (cd* ). Users can access these devices directly through these device files; however, applications often hide the actual device names to end users. |
/etc | Contains administrative configuration files. Most of these files are plain-text files that, given the user has proper permission, can be edited with any text editor. |
/home | Contains directories assigned to each regular user with a login account. (The root user is an exception, using /root as his or her home directory.) |
/media | Provides a standard location for automounting devices (removable media in particular). If the medium has a volume name, that name is typically used as the mount point. For example, a USB drive with a volume name of myusb would be mounted on /media/myusb . |
/lib | Contains shared libraries needed by applications in /bin and /sbin to boot the system. |
/mnt | A common mount point for many devices before it was supplanted by the standard /media directory. Some bootable Linux systems still use this directory to mount hard disk partitions and remote filesystems. Many people still use this directory to temporarily mount local or remote filesystems, which are not mounted permanently. |
/misc | A directory sometimes used to automount filesystems upon request. |
/opt | Directory structure available to store add-on application software. |
/proc | Contains information about system resources. |
/root | Represents the root user's home directory. The home directory for root does not reside beneath /home for security reasons. |
/sbin | Contains administrative commands and daemon processes. |
/sys | Contains parameters for such things as tuning block storage and managing cgroups. |
/tmp | Contains temporary files used by applications. |
/usr | Contains user documentation, games, graphical files (X11 ), libraries (lib ), and a variety of other commands and files that are not needed during the boot process. The /usr directory is meant for files that don't change after installation (in theory, /usr could be mounted read-only). |
/var | Contains directories of data used by various applications. In particular, this is where you would place files that you share as an FTP server (/var/ftp ) or a web server (/var/www ). It also contains all system log files (/var/log ) and spool files in /var/spool (such as mail , cups , and news ). The /var directory contains directories and files that are meant to change often. On server computers, it is common to create the /var directory as a separate filesystem, using a filesystem type that can be easily expanded. |
The filesystems in the DOS or Microsoft Windows operating systems differ from Linux's file structure, as the sidebar “Linux Filesystems versus Windows-Based Filesystems” explains.