Linux / Bash
Beginner
1 min read
Links, Archives, and Disk Usage
Example
# Create a hard link
ln original.txt hardlink.txt
ls -li original.txt hardlink.txt # Same inode number
# Create a symbolic link
ln -s /etc/nginx/nginx.conf nginx.conf
ls -la nginx.conf
# lrwxrwxrwx 1 alice alice 22 Apr 10 09:00 nginx.conf -> /etc/nginx/nginx.conf
# Remove a symbolic link (not the target)
rm nginx.conf
# ---- tar archives ----
# Create a .tar.gz archive
tar -czvf backup.tar.gz /etc/nginx/
# List contents of an archive
tar -tzvf backup.tar.gz
# Extract an archive to current directory
tar -xzvf backup.tar.gz
# Extract to a specific directory
tar -xzvf backup.tar.gz -C /tmp/restore/
# Create .tar.bz2 (better compression, slower)
tar -cjvf backup.tar.bz2 projects/
# Create .tar.xz (best compression)
tar -cJvf backup.tar.xz projects/
# ---- zip ----
zip -r archive.zip projects/
unzip archive.zip -d /tmp/projects_restored/
# ---- disk usage ----
df -h # Free space per filesystem
du -sh /var/log/ # Size of a directory
du -sh /var/log/* | sort -h # Sorted sizes of subdirectories
du -sh /* 2>/dev/null | sort -rh | head -10 # Top 10 biggest root dirs
Related Resources
Linux / Bash Reference
Complete tag & property list
Linux / Bash How-To Guides
Step-by-step practical guides
Linux / Bash Exercises
Practice what you've learned
More in Linux / Bash