- Imagine you are staring at a bunch of obscure directory names in Linux. You want to know where you should put a specific type of file. So I randomly put the files into /usr/share, hoping that this was done correctly.
- After a few days, you discover that it should be placed in /var/local.
- We have all had similar experiences. Linux's directory structure can be very confusing and sometimes doesn't make sense. What do these names actually mean? Where is the "correct" place to put the file?
- Get ready to decrypt your Linux directory as we embark on a journey through time to make your future more stress-free. In this article, we'll reveal what these names mean and where common types of files are located.
- /bin
- This is the primary storage location for executable binaries required by the system ( Hence the name "bin"). These basic binaries are required by the system during the boot process to ensure successful completion. Here you will find basic commands like ls and top.
- During the boot process, if /usr/bin is not available, /bin is sometimes provided as a symbolic link at the top level.
- /boot
- This directory contains all the key files needed to actually boot the operating system. These include kernel files, boot loader files (such as GRUB), and EFI files for modern UEFI systems.
- For Linux systems, this directory is one of the most important directories, because if something goes wrong here, your system may not be able to start, or you may not even know where to start.
- /dev
- /dev is the abbreviation of "device", which is used by Linux to store information about most connected devices on the system (including physical devices and virtual devices) ) is quoted. Here you can find references to hard drives, USB peripherals, virtual terminals, and even empty devices that you can direct things to so that they disappear.
- If you access any kind of device from the command line, even if it's not physical hardware, chances are it's there.
- /etc
- Most likely you have researched in the /etc directory before. This is where Linux keeps all its core configuration files, not only for its own programs, but also for third-party programs you install.
- If you need to modify the way the program runs, core network settings, or crontab, they all exist in this directory.
- /home
- This is one of the more descriptive top-level directories. This is exactly where the user's home directory is. Think of it as a separate space that each user has within the operating system. Typically, they own all files and subdirectories in their corresponding home directories.
- If you view this directory on a shared machine, you may find many subdirectories named after each specific user. After logging in on most systems, you can reference your home directory using the ~ character in the path. The corresponding path is /home/.
- This is the best place to store personal files that are relevant only to you. Pictures, music files, spreadsheets, or the next great novel should all be stored here. You should not store shared program configuration or system-level data here.
- /lib, /lib32, /lib64, …
- These directories contain shared C libraries and kernel modules. These modules and libraries are the basis for the executable binaries in the /bin directory we mentioned earlier. In other words, in order to actually boot the operating system and use any default binaries, we need the library files in these directories.
- Note: If there are multiple library files for different architectures, you will see that other lib directories exist.
- /lost found
- This directory is very simple. Here you will find some files that are corrupted but attempts have been made to recover them. This is usually caused by an unexpected power outage or sometimes a hardware failure.
- /media
- This is also very intuitive. This is a mount point for mounting removable media. Historically, it was used on CDs, floppy disks, and even Zip disk drives. Now, if you mount any virtual ISO or CD images, they can appear here, along with USB flash drives and other removable flash media.
- /mnt This is a more general mount point where you can mount removable media or an entire file system. Today, this is typically used to house external disks, NFS, and other remote file storage.
- This directory is empty, you can decide what to mount here and how to mount it.
- /opt
- This is short for "option" and was originally used to hold any additional packages. These packages are not included with the original release of the system and require additional cost.
- These days, this is one of the few places where you can install add-on packages (with or without additional cost). In some cases, the distribution may not use /opt at all, but this is one location where you will find third-party package data and their static configuration files.
- /proc
- This is a unique Linux directory. You won't store anything here, and in fact the operating system won't store anything here. This is the information center for the Linux kernel. All "files" in this directory are not ordinary files. They contain metrics about processes, memory, and other subsystems. These special files are like windows into the workings of the kernel.
- By simply reading the files in this directory, you can obtain some of the same data that other binaries obtain.
- /root
- This is another simple, intuitive directory. This is the root user's home directory. If you are logged into the system as the root user, you will find that your home directory is now /root instead of /home/root as expected. This is for security reasons in case /home is mounted on an inaccessible or worse, broken remote partition.
- /run
- This directory handles more startup and runtime information. Typically you will find the process ID or PID file in this location. These files describe where a process runs so that other programs can later find it and control or reference it.
- In addition, other temporary files can be placed here, such as lock files and socket information. This directory is intended to hold runtime information, not persistent data.
- /sbin
- Similar to /bin, the /sbin directory also contains executable binary files required by the system. The difference is that the binary files in this directory have special purposes.They are both specifically designed to perform administrator functions on the system. This means they are powerful enough to make significant modifications or maintenance to the operating system, so they are usually found here.
- You won't find binaries like echo or cat here. This directory is reserved for tools like fdisk or usermod.
- /srv
- This is another very general directory. This directory is used to store files that the system is responsible for "providing". For example, if the host was a web server, you might place all your HTML and image resources here.
- /sys
- Depending on the distribution you are using and its version, you may or may not have a /sys directory on your system. This directory is similar to the /proc directory in that it contains device and kernel information, but is presented in a more structured format.
- /tmp
- Another simple directory. This is a directory for temporary files. You can store almost anything you (or the program) like here, but you can't expect it to last forever. Especially between reboots.
- If you need to stage some unimportant data or check the output format of a certain file, putting it here is an option. An added bonus is that if you forget about it, it will probably disappear on its own.
- /usr
- This directory may require a special article to be introduced. According to the Linux Foundation's FHS specification, it is described as:
- "Shared, read-only data."
- This essentially means that it should be able to be easily transferred between hosts, and has the same unmodified structure and hierarchy. Normally, this directory does not contain any unique host data. The idea behind this is that the entirety of /usr can be mounted in read-only mode on another system without problems.
- However, in practice, this directory is indeed used to store arbitrary information. In some cases, you will find files in /usr/share or /usr/local. You will also find program compilations or custom scripts placed in /usr/local/bin.
- Generally speaking, it is recommended to store configuration or special data that does not fall into any of the previous categories in our next and last directory.
- /var
- This is the abbreviation of "variable", and this is where the variable data is saved.
- Here are some of the things traditionally kept here:
Printer spools
- Lock files
- Debian apt and other running program caches
- E-mail data
- Logs
The main purpose is to save any dynamic data used and modified by the system during operation in the /var directory middle. If you need to log or save dynamic .conf files, you've come to the right place.
Additionally, there is the /var/local directory, which in my experience often becomes a comprehensive storage directory for miscellaneous configuration files and other data that doesn't quite fit into other categories.
Summary
The hierarchical structure of the Linux file system is very complex and has a rich evolutionary history. Once you become familiar with the meaning behind these short titles, they start to become very intuitive. Taking the time to explore each directory and study the standard itself will make you more familiar with not only where you put your files, but also how Linux works on a fundamental level.
The above is the detailed content of Solving the mystery of Linux file placement: Where is the best place for files to end up?. For more information, please follow other related articles on the PHP Chinese website!