Objective: Understand how files are organized in Unix
On a UNIX system, everything is a file ; if something is not a file, it is a process.
Machtelt Garrels
The followings are files:
This means that your keyboard is represented as a file within the OS.
This file system is organized as a tree. As you have seen, every folder has a parent folder except the / folder whose parent is itself.
Every file can be accessed by an absolute path starting at the root. Your user home folder can be accessed with the path /home/etudiant/. Go to your user home folder.
We can also access file with a relative path, using the special folder “..”. From your home folder, go to the ubuntu user home folder without passing by the root (we will see use of the “.” folder later).
As you may have guessed, every file type is not the same. We have already seen that common file and folder are different. Here are the list of file types:
To see the file type you can type the command
ls -laThe first column will tell you the type of the file (here we have only the type “-” and “d” ). We will come back on the other information later. An other less used command to get fine technical information on a file is the command stat [file_name]. Can you get the same information as ls -la with stat ?
From the root of the system (/), most of the Unix-like distribution will share the same folder arborescence. On macOS, the names will be different because when you sell the most advanced system in the world you need to rename things, with more advanced names.
/homeYou already know this one. You will find all your file and your configuration files here. Which configuration file can you identify in your home ?
/bootYou can find the Linux kernel and the boot manager there. What is the name of your boot manager (process by elimination) ?
You can see a new type of file here, the type “l”. What it the version of the vmlinuz kernel ?
/rootThe home directory of the super user, also called root (we will go back on him later). Can you check its configuration file ?
/bin, /sbin, /usr/bin and /optThe folder containing the programs used by the system and its users. Programs are simple file readable by a computer, these files are often in binary format which means that it’s extremely difficult for a human to read them.
What is the difference between /bin and /usr/bin ?
/sbin stand for system binary. What are the names of the programs to power off and restart your system ?
/opt is where you will find the installation of non-conventional programs (if you don’t follow the guide of good practice of the LBMC, you can put your bioinformatics tools with crapy installation procedure there).
/lib and /usr/libThose folder contains system libraries. Libraries are a collection of pieces of codes usable by programs.
What is the difference between /lib and /usr/lib.
Search information on the /lib/gnupg library on the net.
/etcThe place where system configuration file and default configuration file are. What is the name of the default configuration file for bash ?
/devContains every peripheric
What is the type of the file stdout (you will have to follow the links)?
With the command ls -l can you identify files of type “b” ?
Using less can you visualize the content of the file urandom ? What about the file random ?
What is the content of /dev/null?
/varStorage space for variables and temporary files, like system logs, locks, or file waiting to be printed…
In the file auth.log you can see the creation of the ubuntu and etudiantaccount. To visualize a file you can use the command
less [file_path]You can navigate the file with the navigation arrows. Which group the user ubuntu belongs to that the user etudiantdon’t ?
To close the less you can press Q. Try the opposite of less, what are the differences ?
What is the type of the file autofs.fifo-var-autofs-ifb in the run folder ? From fifo in the name, can you guess the function of the “p” file ?
There are few examples of the last type of file in the run folder, in which color the command ls -l color them ?
/tmpTemporary space. Erased at each shutdown of the system !
/procInformation on the system resources. This file system is virtual. What do we mean by that ?
One of the columns of the command ls -l show the size of the files. Try is on the /etc folder. You can add the -h option to have human readable file size.
What are the sizes of the files in the /proc folder ?
From the cpuinfo file get the brand of the cpu simulated by your VM.
From the meminfo file retrieve the total size of RAM
With the command ls -l we have seen some links, the command stat can give us more information on them
stat /var/run What is the kind of link for /var/run ?
Most of the time, when you are going to work with links, you will work with this kind of link. You can create a link with the command ln and the option -s for symbolic.
The first argument after the option of the ln command is the target of the link, the second argument is the link itself:
cd
ln -s .bash_history bash_history_slink
ls -laWhat are the differences between the two following commands ?
stat bash_history_slink
stat .bash_historySymbolic links can bridge across, file system, if the target of the link disappears the link will be broken.
You can delete a file with the command rm
There is no trash with the command rm double-check your command before pressing enter !
Delete your .bash_history file, what happened to the bash_history_slink ?
The command ln without the -s option create hard links. Try the following commands:
stat .bashrc
ln .bashrc bashrc_linka
stat .bashrc
ln .bashrc bashrc_linkbUse stat to also study bashrc_linka and bashrc_linkb.
What happen when you delete bashrc_linka ?
To understand the notion of Inode we need to know more about storage systems.
On a computer, the data are physically stored on a media (HDD, SSD, USB key, punch card…)
(Punched cards in storage at a U.S. Federal records center in 1959. All the data visible here would fit on a 4 GB flash drive.)
You cannot dump data directly into the disk, you need to organize things to be able to find them back.
Each media is divided into partition:
The media is divided into one or many partition, each of which have a file system type. Examples of file system type are:
The file system handle the physical position of each file on the media. The position of the file in the index of file is called Inode.
The action of attaching a given media to the Unix file system tree, is called mounting a partition or media. To have a complete list of information on what is mounted where, you can use the mountcommand without argument.
mountFind which disk is mounted at the root of the file tree.
We have seen the commands:
statto display information on a filelessto visualise the content of a filelnto create linkmountto list mount points