File System Basics File Hierarchy Standard
File System Basics File Hierarchy Standard
The current working directory for the terminal on the left is your
workspace.
cd /
ls
The cd / switches you to the root directory, and the ls command lists the
contents of that directory.
Name Function
Binaries or executables that are
/bin
essential for functionality
Files needed to boot the system such
/boot
as the Linux kernel
Device files - interface with hardware
/dev
drivers
Host-specific system configuration -
/etc
editable text
/home User directories live under here
/lib Common libraries
/lib64 Common 64-bit libraries
/media Mount point for removable media
Mount point for mounting a
/mnt
filesystem temporarily
/opt Optional add on software
/proc Keeps track of running processes
/root Home directory for root user
/run Data relevant to running processes
System binaries or executables that
/sbin
are essential for functionality
Data for services provided by this
/srv system
A symbolic link to the kernel source
/sys
tree
Temporary files that won’t be
/tmp
persistent between reboots
Variable files - things that will change
/var as the operating system is being run
such as logs and cache files
The /bin directory
info
You can get more information about any of the commands above by
typing man and then the command name at the terminal prompt.
Try it out:
more -d prideandprejudice.txt
The exceptions are configuration files not needed at boot time and the map
installer. The operating system kernel must be located in / or /boot.
ls /boot
You will recognize some of the names such as console and stdout.
tree /dev
You should see something like this:
Notice that some files have a directory path listed to the right of them, these
are called symbolic links (symlink). A symlink is a type of file in Linux that
points to a different file or folder. Symlinks allow multiple access points to
a file without needing multiple copies.
The /etc directory
Configuration files are editable text files, executable files should not be
placed in this directory. The configuration files should be placed in
subdirectories of the /etc folder grouped by the application they serve.
Let’s first look at a list of directories that live under the /etc directory:
cd /etc
ls -d */
Next we’ll look at the configuration file for the vim editor which we
covered in the previous module. It is named vimrc and located in the vim
directory.
cd vim
more -d vimrc
First let’s take a look at the prideandprejudice.txt file before we make the
change to see that vim does not display line numbers by default.
vim /home/codio/workspace/prideandprejudice.txt
important
By default these system files are read only. You have “super user”
capabilities so you can modify the permissions for the file using the sudo -
“super user do” combined with the chmod command which allows you to
change file permissions.
The first command below will add write permission for all users for the file
vimrc. The second command will append the line “set number” to the file,
this tells vim to display line numbers.
Now let’s look at the file again and see that we have changed the behavior
for vim and now we see line numbers.
vim /home/codio/workspace/prideandprejudice.txt
The /home and /lib directories
Your user name is codio and you are the only user set up in the Linux
system you access from the terminal on the left.
pwd
ls
The /lib directory contains shared library images needed to boot the
system and run the commands in /bin and /sbin.
cd /lib
ls
You should see a listing similar to the one in the image below. The x86_64-
linux-gnu is circled to show that the contents of this directory are for the
version of GNU/Linux running in the terminal.
The x86 refers to the type of processor and the 64 means that it is a 64-bit
system (as opposed to a 32-bit).
The /media and /mnt directories
You will notice that these directories are empty. There are no devices
mounted to your Linux instance in the terminal.
cd /media
ls -a
cd /mnt
ls -a
The /media directory is used for removable media such as USB drives and
CD ROMS. This is typically used by the system. The /mnt directory is used
for temporarily mounted file systems, mostly for user-mounted items.
All files that are accessible in a Linux system are arranged in one
hierarchical tree that starts at the root /. The files accessible through the
root can be spread out over multiple devices. This differs from what you
see in a file system such as Windows where you will see a separate tree for
each device. For example in Windows, c: is the internal hard drive and if
you have partitioned your hard drive you would access the other partition
through d:. If you insert a USB stick you might get another drive f:.
You will learn more about mounting external devices in the Listing and
Mounting Hardware assignment in the Managing Devices module.
The /opt, /proc and /root directories
The /opt directory is reserved for the installation of add-on application
software packages. There is nothing installed in that directory in the
system running in your terminal.
cd /proc
ls -a
The /root directory is the root user’s home directory. As you will see if you
try it out below, you do not have permission to access the /root directory.
The /run directory
The /run directory contains system information about the system since it
was booted. This directory must be cleared at the beginning of the boot
process.
cd /run
ls -a
You will see files with the extension .pid. These are Processor identifier
files (PID). A PID file consists of a process identifier in ASCII-encoded
decimal, followed by a newline character. The directories you see may also
contain PID files and must also be cleared during the boot process.
Enter the top (table of processes) command. It will show you the list of
running processes. Type q to exit the display.
top
Now you have a list of the processes and if you list out one of the .pid files
you will see that the number matches the value in the table.
cat crond.pid
cd /sbin
ls -a
You can find more information about some of the other files you might
typically see in the /sbin directory here.
The /bin directory contains binaries (commands) that are for users as well
as items needed to bring the system up or repair it. The /sbin directory
contains binaries that the system uses for booting up. These are generally
not run by users, you need sudo privileges to be able to run them.
The /srv, /sys and /tmp directories
cd /sys
ls -a
Directory Description
bin Most user commands
lib Libraries
local Local hierarchy (empty after the initial installation)
sbin Non-vital system binaries
share Architecture-independent
Directory Description
games Games and educational binaries
include Header files included by C programs
libexec Binaries run by other programs
lib <qual> Alternate Format Libraries
src Source code
The /bin directory contains executable commands that are required by the
system and /usr/bin contains executable files that are not required.
info
Color Meaning
White Most files
Green Executable
Blue Directory
Cyan Symbolic link file
Yellow with black background Device
Magenta Graphic image file
Red Archive file
Red with black background Broken link
Take a look at the contents of /usr/bin, you can use the entries in the table
above to determine the types of files.
ls /usr/bin
whereis python3
Running this shows you all the locations of python3 related files.
The /sbin directory holds commands needed to boot the system. The
/usr/sbin direcory contains program binaries for system administration
which are not essential for the boot process.
Take a look at the contents of /usr/sbin, you can use the entries in the table
above to determine the types of files.
ls /usr/sbin
If you are curious about any of these executables, you can type in man
followed by the file name. As a reminder, use the letter q to exit the man
command.