Linux Directory structure in brief
Knowledge can only be enhanced and is thoroughly understood when it is put in practice. Did you know everything in Linux is a file? Yes, including network connections, processes, everything! How does it all work?
Navigating Linux directory structure helps understand what makes it so flexible and easier to access, just like BFF maintaining your ex’ list :P
Note: While Linux has a set of standards, you can put any file anywhere and make it work.
Some basic commands that will come handy while exploring Linux directories are
tree: Install it with sudo apt install tree
. It helps to visualise how directory/sub-directory/ files are placed.
cd: to navigate around
ls: to list folders/files in the directory
🐼/bin: This is where all basic magic happens. This contains all the binaries essential to run some program or application. Well, what magic was I talking about ?? Commands like ls, pwd, cat, chmod, etc. All these cute executable binaries are present here. As I write, I wonder what happens if chmod or such binary is deleted??
🐼/boot: I was curious about how does the system gets started! But I will keep it for another post. This folder contains all those files that connect the system together, such as connecting keyboard, mouse, webcam, style etc. This folder is slightly different from servers and your laptops. Why? Simply because servers don’t have a keyboard or mouse or any such external stuff. Don’t even try to mess any files here, you may not be able to run Linux, and it becomes difficult to repair.
🐼/dev: It contains all the essential files of devices. It is either generated at boot time or later such as pen drive, printer, USB. Device entries are done here on the fly. If you often have seen/dev/null, it is high time to know about it. /dev/null is like a void place where everything you send here has no existence. You can send all unwanted logs from every application to /dev/null.
🐼/etc: Popularly known as “et cetera”. It contains most of the system configuration such as user and their password etc/password
, contains the name of your system, names of the machines on your network, partitions of hard disk and so on.
🐼/home: Home is where every user lives. They’ll have their own little rooms like /home/ubuntu or /home/ashwini or /home/cakejar etc. So if you are creating a user, it is good practice to create a home directory for it like /home/user and maintain user-related stuff here.
🐼/lib: Its a special one. It contains all the important libraries. Applications refer to code snippets from here for their usage. They can be dependencies, third-party libraries, etc.
It also contains kernel modules to run webcam, video card, wifi, graphic cards, etc.
🐼/opt: Third-party software live here. Try installing an open-source code to see what happens here. It is accessible by all users.
🐼/proc: This folder is a beast in itself. It deserves its own post. Briefly, it contains everything related to running processes in Linux. i.e. files, pointers, file descriptors, CPU usage, limits and a lot more. Do not mess with this directory but heavily recommend to dig it through.
🐼/root: Home directory of the root user. Do not mess with superuser’s directory.
🐼/run: It holds some files that applications can put during runtime.. such as sockets, pid files, etc. Do not mess with this directory.
🐼/sbin: Contains binaries which can be only run by root/sudo users. Binaries like fdisk, route, iconfig, init, mkfs and so on.
🐼/usr: Also called as UserSharedResources. Files that live here is shared by applications and services. This can contain applications, libraries, patch, scripts, etc.
🐼/srv: Not in practice anymore, it used to host html files, javascript, etc. that are used by web-servers.
🐼/sys: Virtual directory just like /proc and /dev contains information about the devices connected to the computer or known to Linux kernel.
🐼/tmp: All temporary files are stored here, but these get deleted on the bootup. You can try storing your data here which you don’t want to have an account of.
🐼/var: All changeable files are stored here, hence the name variables. Example /var/logs register the events that happen on the system like kernel logs, firewall logs, printer jobs in the queue, database failed logs etc.
🐼/media: used to host CDs, floppy disks
🐼/mnt: Typically used for mounting external disks like pen drives
This is not an exhaustive list, ignoring a few unimportant ones.
Some of the directories like media, mnt, srv are no longer widely used.
Links: https://www.linux.com/training-tutorials/linux-filesystem-explained/