UNIX File System
The UNIX file system looks like a tree upside down. You start with the root directory, denoted by /, at the top and work down through sub-directories underneath it.
Each “box” is either a file or a directory of files, where the latter can contain other files and directories. You specify a file or directory by its path name, either the full (or absolute) path name or the one relative to a location.
The full path name starts with the root, /, and follows the branches of the file system, each separated by /, until you reach the desired file (e.g. path to bigbrother start up file): /usr/local/bb/bin/bbrun
A relative path name specifies the path relative to another, usually the current working directory that you are at. Two special directory entries should be introduced now:
- . : the current directory
- .. : the parent of the current directory
So if I'm at /usr/local/bb/bin and wish to specify a different path in a relative fashion I could use: cd ../ext/rbridge/tmp
This indicates that I should first go up one directory level, then come down through the ext directory, followed by the rbridge directory and then to tmp.
Linux and UNIX operating systems have a standardized filesystem hierarchy that was introduced in August 1993 named Filesystem Hierarchy Standard, or FHS for short. In FHS all files and directories appear under the root directory "/", even if they are stored on different physical devices. Note however that some of these directories may or may not be present on a UNIX system depending on whether certain subsystems, such as the X Window System (the graphical interface for UNIX OS), are installed.
root and root directory of the entire file system
Essential command binaries that need to be available in single user mode; for all users (e.g., cat, ls, cp).
Boot loader files (e.g., kernels, initrd). Often a separate partition.
Essential devices (e.g., /dev/null).
Host-specific system-wide configuration files (the name comes from editable text config).
Configuration files for /opt/.
Configuration files for the X Window System, version 11.
Startup and stopping scripts for services
System configuration files on LFS and RedHat
Users' home directories - containing saved files, personal settings etc. Often a separate partition.
Libraries essential for the binaries in /bin/ and /sbin/.
Mount points for removable media such as CD-ROMs
Temporarily mounted filesystems.
Optional application software packages.
Virtual filesystem for kernel and process status.
Home directory for the root user.
Essential system binaries (e.g., init, route, ifup).
Site-specific data which is served by the system, e.g.: /srv/www.
Temporary files (see also /var/tmp).
for user data; the name comes from UNIX shared resources; contains the majority of (multi-)user applications
Non-essential command binaries (not needed in single user mode)
Standard include files.
Libraries for the binaries in /usr/bin/ and /usr/sbin/.
Non-essential system binaries (e.g. daemons for various services).
Architecture-independent (shared) data.
Source code (e.g. the kernel source code with its header files).
X Window System, Version 11 Release 6.
for local data, specific to this host. Typically has further subfolders, e.g. bin/, lib/, share/
Variable files, such as logs, spool files, and temporary e-mail files.
Lock files. Files keeping track of resources currently in use.
Log files. Various logs.
Information about the running system since last boot (e.g. currently logged-in users and running daemons).
Spool for tasks waiting to be processed (e.g. print queues and unread mail).
Deprecated location for users' mail-boxes.
Temporary files to be preserved between reboots.
File System and Directories
A directory is a special file that contains a table listing the files contained within it, giving file names to the inode numbers in the list. An inode is a special file designed to be read by the kernel to learn the information about each file. It specifies the permissions on the file, ownership, date of creation and of last access and change, and the physical location of the data blocks on the disk containing the file.
The FHS does not require any particular structure for the data in the file itself. The file can be ASCII or binary or a combination, and may represent text data, a shell script, compiled object code for a program, directory table, junk, or anything you would like. There's no header, trailer, label information or EOF (End Of File) character as part of the file.
As it was mentioned before, UNIX systems have one universal interface when it comes to handling ordinary files, directories, hardware devices, etc. And it is a file. UNIX treats everything as a file. The following kind of “files” exist in UNIX systems:
- Text file : ASCII files, readable to humans (e.g. config files, log files, etc.)
- Binary file : Files that are contain information understandable by the system
- Directory : Special file that contains the list of files and directories within itself
- Socket : A special “two-way tunnel” to exchange information between applications
- Pipe : A special “one way tunnel” to exchange information between applications
- Device file : A special file that enables applications to access hardware in a system (disk, video card, sound card, network cards, etc)
- Proc file : A special file system to describe processes currently running on the system
Files and directories have special parameters called “permission rights”. These settings tell the operating system what applications and/or users have what kind of access to those files.
Every file or folder in UNIX has access permissions. There are three types of permissions (what is allowed to be done with a file):
- read access
- write access
- execute access
Permissions are defined for three types of users:
- the owner of the file
- the group that the owner belongs to
- other users
Thus, UNIX file permissions are nine bits of information (3 types x 3 type of users), each of them may have just one of two values: allowed or denied.
Simply put, for each file it can be specified who can read or write from/to the file. For programs or scripts it also can be set if they are allowed to be executed.
It is used in UNIX long directory listings. It consists of 10 characters. The first character shows the file type. Next 9 characters are the permissions, consisting of the three groups: owner, group, others. Each group consists of three symbols: rwx (in this order), if some permission is denied, then a dash "-" is used instead.
-rwxr--r-- root root useradd 0123456789
- Symbol in the position 0 ("-")is the type of the file. It is either "d" if the item is a directory, or "l" if it is a link, or "-" if the item is a regular file.
- Symbols in positions 1 to 3 ("rwx") are permissions for the owner of the file (root).
- Symbols in positions 4 to 6 ("r--") are permissions for the group (root).
- Symbols in positions 7 to 9 ("r--") are permissions for others.
The next article will further expand on Linux Commands