Linux ln Guide - ryzendew/Linux-Tips-and-Tricks GitHub Wiki
Linux ln Guide
Complete beginner-friendly guide to ln on Linux, covering Arch Linux, CachyOS, and other distributions including creating symbolic links, hard links, and link management.
Table of Contents
Understanding ln
What is ln?
ln (link) creates links to files.
Link types:
- Symbolic links: Point to file path
- Hard links: Direct file reference
Uses:
- Shortcuts: Create file shortcuts
- Organization: Organize files
- Multiple access: Access file from multiple locations
- System management: Manage system links
Symbolic Links
Create Symlink
Basic usage:
# Create symbolic link
ln -s target.txt link.txt
# -s = symbolic
Absolute vs Relative
Path types:
# Absolute path
ln -s /absolute/path/target.txt link.txt
# Relative path
ln -s ../target.txt link.txt
Hard Links
Create Hard Link
Basic usage:
# Create hard link
ln target.txt link.txt
# No -s flag = hard link
Hard Link Properties
Characteristics:
- Same inode: Shares inode with original
- No distinction: Original and link are equal
- File system: Must be on same filesystem
- Directory: Cannot hard link directories
Link Management
List Links
Find symlinks:
# Find symbolic links
find . -type l
# Or
ls -la | grep "^l"
Remove Links
Delete link:
# Remove link
rm link.txt
# Only removes link, not target
Troubleshooting
Broken Links
Fix broken symlinks:
# Find broken links
find . -type l ! -exec test -e {} \; -print
# Remove broken links
find . -type l ! -exec test -e {} \; -delete
Summary
This guide covered ln usage, symbolic/hard links, and link management for Arch Linux, CachyOS, and other distributions.
Next Steps
- ls Guide - List files and links
- readlink Guide - Read link targets
- File Management - Filesystem management
- ln Documentation:
man ln
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.