Files
mkdocs/docs/Linux/links.md
2025-03-25 15:52:48 +01:00

103 lines
2.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Links
### soft link (symbolic link):
- ln -s
- contient le chemin du fichier original
- link des répertoires
```bash
~ mkdir link
~ touch link/hello.txt
~ ln -s link/hello.txt
~ ls
hello.txt link
```
#### Créer un lien symbolic
```bash
~ ln -s link/hello.txt hello_you.txt
~
$ ls
hello.txt link hello_you.txt
```
```bash
~/.local/bin
$ ln -s ~/Documents/Scripts/pihole/sync_pihole_lan.sh sync_pihole
```
```bash
~/.local/bin
$ ln -s ~/Documents/Scripts/bashbirds/bashbirds.sh bashbird
```
### hard link:
- ln
- contient le contenu du fichier original (le hardlink et le fichier original partagent le même inode)
- ne link pas des répertoires
#### Inode number
```bash
~ touch file_1 file_2
~ ls -i
43767553 file_1 43767554 file_2
```
```bash
~ ls -l
-rw-r--r-- 1 bruno staff 0 mai 6 18:29 file_1
-rw-r--r-- 1 bruno staff 0 mai 6 18:29 file_2
```
#### Créer un hard-link
```bash
~ ln file_1 hard_ln
```
```bash
~ ls -li
43767553 -rw-r--r-- 2 bruno staff 0 mai 6 18:29 file_1
43767554 -rw-r--r-- 1 bruno staff 0 mai 6 18:29 file_2
43767553 -rw-r--r-- 2 bruno staff 0 mai 6 18:29 hard_ln
43768356 lrwxr-xr-x 1 bruno staff 14 mai 6 18:46 hello.txt -> link/hello.txt
43768828 lrwxr-xr-x 1 bruno staff 14 mai 6 18:50 hello_you.txt -> link/hello.txt
43768326 drwxr-xr-x 3 bruno staff 96 mai 6 18:46 link
```
file_1 et hard_ln ont le même inode.
Si on supprime `file_1`, `hard_ln` conserve le même contenu.
#### Origine d'un lien
```bash
/opt/homebrew/share/zsh/site-functions stable
readlink -f _yq
/opt/homebrew/Cellar/yq/4.40.5/share/zsh/site-functions/_yq
```