LLHOST INC.
Posted 2 years ago

#servers #linux #directories

Reading time: 7 min.

img

Linux Files, Directories and Folders. Linux Filesystem Structure

The UNIX file structure of such operating systems is based on the FHS (Filesystem Hierarchy Standard). The standard allows for a unified hierarchy of directories and general-purpose files in a file system. To manage Linux folders, you need to understand the basics of the file hierarchy structure.

The FHS standard defines the structure and contents of directories on Unix-like operating systems. In FHS, all folders and files appear in the root directory /, regardless of the storage location (physical or virtual device). Directories on UNIX systems have a common principle of use. The information below is only relevant for Linux systems, not for the X Window System and analogs.

Linux FHS Structure of Files and Folders
Linux FHS Structure of Files and Folders - photo

The file and directory tree starts with the root of the primary hierarchy (/). The only root user has the authority to edit this directory. /root is the home directory of the root user, which is not the same as the root /.

  • /bin - binary files (programs). The directory contains the basic user files required to mount the system. /bin directly contains executable files for many of the basic shell commands such as ps, ls, ping, grep, cp.
  • /sbin - system executable files. The directory is similar to the /bin directory. It contains important binaries that are usually intended to be run by the root user for system administration.
  • /etc - the directory contains configuration files, which are usually edited manually in a text editor. The /etc/directory contains system-wide configuration files (such as the hostname) - custom configuration files are found in each user's home directory.
  • /dev - device files. The directory contains several special files representing devices (For example, /dev/sda represents the first SATA drive on the system. /Dev/random generates random numbers. /Dev/null is a special device that automatically discards all input).
  • /proc - the information about processes. The directory contains special files that represent information about the system and the processes. It is a pseudo-filesystem that contains information about running processes. Usage examples: find out the uptime of /proc/uptime, check information about the processor /proc/cpuinfo, or check the memory usage of your Linux /proc/meminfo system.
  • /var - variable files. This is where information about the execution time of programs is stored (syslog, user tracking, caches, and other system-generated files).
  • /tmp - temporary application files. These files are usually removed when you restart your system and can be removed at any time using utilities such as tmpwatch.
  • /usr - user programs. This is where locally compiled applications are installed by default so as not to mess up the rest of the system. The directory contains applications and files used by users. The libraries for each of them are located in the /usr /lib directory. The directory also contains architecture-independent files such as graphics located in /usr/share.
  • /home is the home folder. The home folder contains user data files and user configuration files. Each user can only write to their home folder and must be granted with the administrator (root) rights to modify other files on the system.
  • /boot - bootloader files. These are the files required to boot the system (For example, the GRUB bootloader and Linux kernel files).
  • /lib - System libraries required for the core binaries in the /bin and /sbin folder. The libraries required for binaries in the /usr /bin folder are located in /usr /lib.
  • /opt - additional programs. The directory contains subdirectories for additional software packages. It is typically used by proprietary software that does not follow the standard file system hierarchy.
  • /mnt - mount. This is where sysadmins mount temporary filesystems while they are in use. For example, the Windows mountable partition for file recovery is /mnt /windows. You can mount other file systems anywhere on the system.
  • /srv - server. The catalog contains data on the services provided by the system. When using the Apache HTTP Server to serve the website, the website files are stored inside the /srv directory.
  • /run - processes. The directory contains temporary files that cannot be stored in /tmp (for example, sockets and process IDs). It is important to remember that /tmp files can be deleted.
  • /sys - information about the system. It is a virtual filesystem that can be accessed to install or get information about the kernel's representation of the system.

Basic Commands To Work With The File System
Basic Commands To Work With The File System - photo

The most common tasks of working with file systems are navigation, manipulating files and directories, and changing access rights. Let's consider the basic commands for solving these tasks.

Basic commands to navigate the terminal

cd (eng: change directory) - change to another directory.

 

ls (eng: list) - view the contents of the directory.

 

Working with files
Working with files  - photo

There are three main ways to create a text file in a Linux terminal. These are touch command, output redirection, and text editors. Let's consider the methods in detail.

 

Use cat to view the contents of a file. For large files use a combination of cat and more.

 

Use find and grep to search by title or content.

 

To create a folder through the terminal, use the mkdir (make directory) command and specify the directory name (mkdir name). Important: for complex names that consist of two or more words, use quotation marks, the space will be interpreted by the system as a command to create separate folders (mkdir “new name”). In names, use minuses (“-”) instead of spaces and backslashes (“\”) to escape special characters.

Creating files from the command line is more versatile and much faster than creating files in various applications. You must specify the file name and desired extension to exclude the "Save As" process in applications.

Trustpilot