Linux Command Line Mastery · Lezione

Creare e seguire i link simbolici

Impari a creare, ispezionare e gestire link simbolici e hard link per organizzare i file in modo flessibile senza copiare i dati.

Lezione 4 di 413 passaggi

Creare e seguire i link simbolici è una lezione Linux Command Line Mastery gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Linux Command Line Mastery, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Linux Command Line Mastery include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

What Is a Link

A link is a filesystem entry that points to another file. Links let one file appear in multiple places without duplicating its data, saving space and easing organization.

Linux has two kinds: symbolic links and hard links.

Creating a Symbolic Link

A symbolic link (symlink) is a small file holding a path to its target. Create one with ln -s: the target first, then the link name.

ln -s /var/log/app.log current.log

Inspecting Links

ls -l shows symlinks with an arrow pointing to their target, and the type character l at the start of the permissions.

ls -l current.log
# lrwxrwxrwx 1 user user 16 ... current.log -> /var/log/app.log

Following a Link

Reading or writing through a symlink transparently affects the target. Editing current.log edits /var/log/app.log.

cat current.log   # reads the target file's contents

Hard Links

A hard link is a second name for the exact same data on disk. Both names are equal; deleting one leaves the data until the last link is gone.

ln original.txt backup.txt   # no -s means hard link

Symbolic vs Hard

Key differences:

  • Symlinks can cross filesystems and link directories; hard links cannot.
  • A symlink breaks if its target moves; a hard link keeps the data alive.
  • Symlinks store a path; hard links share an inode.

Broken Links

If a symlink's target is deleted or moved, the link becomes dangling. Accessing it fails. ls often shows broken links in red.

rm /var/log/app.log
cat current.log   # error: No such file or directory

Finding the Target

Use readlink to print where a symlink points, and readlink -f to resolve the full real path through chained links.

readlink current.log
readlink -f current.log

Updating and Removing Links

To repoint a symlink, use ln -sf to force-replace it. To remove a link, rm deletes the link itself, never the target file.

ln -sf /var/log/new.log current.log   # repoint
rm current.log                        # remove the link only

Practical Uses

Symlinks shine for:

  • A stable current path pointing at the latest versioned release.
  • Putting config files in a dotfiles repo, linked into $HOME.
  • Sharing a dataset across projects without copies.

Listing All Links in a Directory

To audit existing links, combine ls with a filter. The find command can list every symlink under a path, helping you spot broken or stray ones.

find . -type l

Quick Check

Test your understanding of links.

Recap

You learned to work with links: create symlinks with ln -s, inspect them with ls -l and readlink, understand hard vs symbolic differences, recognize broken links, repoint with ln -sf, and apply them to releases, dotfiles, and shared data.

Gratis per iniziare

Impara Linux Command Line Mastery con un tutor IA — gratis

Scrivi ed esegui vero codice nel tuo browser, ricevi aiuto istantaneo da un tutor IA disponibile 24/7, e riprendi da dove hai lasciato sul web o nell'app.

Corsi
12
Lezioni
48

Domande Frequenti

La lezione «Creare e seguire i link simbolici» è gratuita?

Sì — il testo completo di «Creare e seguire i link simbolici» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Linux Command Line Mastery, passa a CoddyKit PRO. Il corso Linux Command Line Mastery include 4 lezioni in totale.

Cosa imparerò in «Creare e seguire i link simbolici»?

Impari a creare, ispezionare e gestire link simbolici e hard link per organizzare i file in modo flessibile senza copiare i dati. Eserciti Linux Command Line Mastery con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Linux Command Line Mastery?

Non è richiesta alcuna esperienza precedente. Linux Command Line Mastery su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.

Quanto tempo richiede la lezione «Creare e seguire i link simbolici»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Linux Command Line Mastery?

Sì. Ogni lezione Linux Command Line Mastery include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Visualizzazione del contenuto dei file: `cat`, `less`, `more`
  2. Ricerca nei file: `find` e `locate`
  3. Permessi e proprietà: `chmod`, `chown`
  4. Creare e seguire i link simbolici
← Torna a Linux Command Line Mastery