シンボリックリンクを作成して使う
シンボリックリンクとハードリンクを作成、確認、管理し、データをコピーせずに柔軟にファイルを整理する方法を学びます。
「シンボリックリンクを作成して使う」はCoddyKit上の無料Linux Command Line Masteryレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはLinux Command Line Mastery学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Linux Command Line Masteryコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
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.logInspecting 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.logFollowing 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 contentsHard 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 linkSymbolic 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 directoryFinding 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.logUpdating 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 onlyPractical Uses
Symlinks shine for:
- A stable
currentpath 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 lQuick 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.
AI チューターと学ぶ Linux Command Line Mastery — 無料
ブラウザでリアルコードを書いて実行し、24/7 の AI チューターから瞬時にサポートを受け、ウェブまたはアプリで続きから学習できます。
- コース
- 12
- レッスン
- 48
よくある質問
「シンボリックリンクを作成して使う」レッスンは無料ですか?
はい。「シンボリックリンクを作成して使う」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Linux Command Line Masteryコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Linux Command Line Masteryコースには全4レッスンが含まれています。
「シンボリックリンクを作成して使う」で何を学びますか?
シンボリックリンクとハードリンクを作成、確認、管理し、データをコピーせずに柔軟にファイルを整理する方法を学びます。 ブラウザで直接実行するハンズオンコードでLinux Command Line Masteryを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Linux Command Line Masteryを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのLinux Command Line Masteryは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「シンボリックリンクを作成して使う」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このLinux Command Line Masteryレッスンでコードを書いて実行できますか?
はい。すべてのLinux Command Line Masteryレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。