Skip to content
Snippets Groups Projects
Unverified Commit e7f4bea8 authored by Laurent Modolo's avatar Laurent Modolo
Browse files

finish 4.

parent e4068d08
No related branches found
No related tags found
No related merge requests found
---
title: Unix file system
title: GNU/Linux file system
---
# Unix file system
# GNU/Linux file system
[![cc_by_sa](/Users/laurent/Documents/formations/2020_08_UNIX/img/cc_by_sa.png)](http://creativecommons.org/licenses/by-sa/4.0/)
[![cc_by_sa](./img/cc_by_sa.png)](http://creativecommons.org/licenses/by-sa/4.0/)
Objective: Understand how files are organized in Unix
......@@ -19,14 +19,207 @@ The followings are files:
- a folder
- a keyboard
- a disk
- an usb key
- a USB key
- ...
This mean that your keyboard is represented as a file within the OS.
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 exept the `/` folder whose parent is itself.
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
```sh
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 **bin**ary 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](http://www.ens-lyon.fr/LBMC/intranet/services-communs/pole-bioinformatique/ressources/good_practice_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
```sh
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` files 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
```sh
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 **l**i**n**k with the command `ln` and the option `-s` for **s**ymbolic.
The first argument after the option of the `ln` command is the target of the link, the second argument is the link itself:
```sh
cd
ln -s .bash_history bash_history_slink
ls -la
```
What are the differences between the two following commands ?
```sh
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`
**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:
```sh
stat .bashrc
ln .bashrc bashrc_linka
stat .bashrc
ln .bashrc bashrc_linkb
```
Use `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.
## Disk and partition
On a computer, the data are physically stored on a media (HDD, SSD, USB key, punch card...)
![IBM_card_storage_NARA](./img/IBM_card_storage_NARA.jpg)
(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.
![disk](./img/disk.png)
Each media is divided into partition:
![partitions](./img/partition.png)
The media is divided into one or many partition, which each have a file system type. Examples of file system type are:
- fat32, exFAT
- ext3, ext4
- HFS+
- NTFS
- ...
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 `mount `command without argument.
```sh
mount
```
Find which disk is mounted at the root of the file tree.
[That’s all for the Unix file system, we will come back to it from time to time but for now you can head to the next section.](http://perso.ens-lyon.fr/laurent.modolo/unix/4_users_and_rights.html)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment