This Linux file cheat sheet covers the most important commands for managing files and directories in Linux. Use it as a fast reference whether you're a beginner or power user.
๐ File & Directory Basics
| Command | Description |
|---|---|
ls | List files and directories |
ls -l | Detailed list (permissions, size, date) |
ls -a | Show hidden files |
pwd | Show current directory |
cd dir | Change directory |
cd .. | Go up one level |
๐ Create & Manage Files
| Command | Description |
|---|---|
touch file.txt | Create empty file |
cp file1 file2 | Copy file |
mv file1 file2 | Move or rename file |
rm file.txt | Delete file |
rm -r folder | Delete folder recursively |
mkdir folder | Create directory |
๐ View File Contents
| Command | Description |
|---|---|
cat file.txt | Show full file |
less file.txt | Scroll through file |
head file.txt | First 10 lines |
tail file.txt | Last 10 lines |
tail -f file.txt | Live file updates |
๐ Search & Find Files
| Command | Description |
|---|---|
find / -name file.txt | Search by name |
grep "text" file.txt | Search text inside file |
locate file.txt | Fast search (indexed) |
๐ฆ File Compression & Archives
| Command | Description |
|---|---|
tar -cvf file.tar folder/ | Create archive |
tar -xvf file.tar | Extract archive |
gzip file.txt | Compress file |
gunzip file.txt.gz | Decompress file |
๐ Permissions & Ownership
| Command | Description |
|---|---|
chmod 755 file | Change permissions |
chmod +x script.sh | Make executable |
chown user file | Change owner |
chgrp group file | Change group |
๐ Links (Shortcuts)
| Command | Description |
|---|---|
ln file link | Create hard link |
ln -s file link | Create symbolic link |
๐ Disk Usage & File Info
| Command | Description |
|---|---|
df -h | Disk space usage |
du -sh folder | Folder size |
stat file.txt | Detailed file info |
file file.txt | Detect file type |
โก Useful Shortcuts
| Shortcut | Action |
|---|---|
Ctrl + C | Stop command |
Ctrl + Z | Pause command |
Tab | Auto-complete |
โ / โ | Command history |
๐ Real-World Examples
Copy a folder
cp -r myfolder backup/
Delete all .log files
rm *.log
Find large files
find / -size +100M
โ ๏ธ Common Mistakes
- โ Using
rm -rfwithout checking path - โ Overwriting files with
mvorcp - โ Forgetting permissions when running scripts
๐ Quick Summary
- Use
ls,cd,pwdfor navigation - Use
cp,mv,rmfor file management - Use
grep,findfor searching - Use
chmod,chownfor permissions
๐ฏ Final Thoughts
Mastering Linux file commands gives you full control over your system. With just a handful of commands, you can manage files faster than any graphical interface.