File Structure
Linux uses the filesystem hierarchy standard which defines the way directories/folders are laid out. It’s important to understand this structure to understand how the operating system works. The top most directory is called the root directory(/). Since the file system is organised in a hierarchy, every file and folder is located under the root directory. Here’s the most common layout of the root directory:
- /bin - contains programs in the form of binary files that user can run
- /boot - contains the files needed to start the system
- /dev - used to represent devices(mostly virtual) that correspond to particular functions
- /etc - contain configuration files for services on a computer and some system files
- /usr - contain executable files(programs) for most system programs
- /home - contains home directories for personal users
- /lib - contain libraries(which contain extra functions) that are used by executable files in the /bin directories
- /var - mostly contain files that store information about how services run(also known as log files)
- /proc - contains information about processes running on the system
- /mnt - used to mount file systems. Mounts are usually used when users want to access other file systems on their system
- /opt - contains optional software
- /media - contains removable hardware e.g. USB
- /tmp - contains temporary files. This folder is usually cleared on reboot so doesn’t store persistent files
- /root - contains files created by the super user(more on this later)
Now that we have a brief explanation about the file structure, let’s dive straight in. To learn basic commands, we’ll assume the scenario of what an attacker would do if they gain access to a linux system
The first thing an attacker would do is gain access to the system. This can be done in many different ways, but the most common way is using a shell. A shell is used to run system commands(it can also be thought of as the terminal or as the actual command line). Shells are also programs and the most common shells are: