-
Laurent Modolo authoredLaurent Modolo authored
title: GNU/Linux file system
GNU/Linux file system
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:
- a text file
- an executable file
- a folder
- a keyboard
- a disk
- a USB key
- ...
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).
File Types
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:
- - common files
- d folders
- l links
- b disk
- c special files
- s socket
- p named pipes
To see the file type you can type the command
ls -la
The 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
?
Common Structure
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.
/home
You already know this one. You will find all your file and your configuration files here. Which configuration file can you identify in your home ?
/boot
You 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 ?
/root
The 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 /opt
The 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/lib
Those 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.
/etc
The place where system configuration file and default configuration file are. What is the name of the default configuration file for bash
?
/dev
Contains 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
?
/var
Storage 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 etudiant
account. 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 etudiant
don’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 ?
/tmp
Temporary space. Erased at each shutdown of the system !
/proc
Information 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
Links
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 -la
What are the differences between the two following commands ?
stat bash_history_slink
stat .bash_history
Symbolic 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