Mastering basic Linux commands is the first step toward becoming proficient in system administration and DevOps. This comprehensive guide covers essential commands for navigation, file management, and daily operations with practical examples and best practices.
Essential Navigation Commands
Print Working Directory - Shows your current directory location
Example: pwd outputs /home/username
List Directory Contents - Shows files and directories
Common Options:
ls -l- Detailed listls -a- Show hidden filesls -la- Detailed list with hidden files
Change Directory - Move between directories
Common Uses:
cd /path/to/dir- Absolute pathcd ..- Go up one levelcd ~- Go to home directorycd -- Go to previous directory
File and Directory Management
Make Directory - Create new directories
Examples:
mkdir projects- Create single directorymkdir -p projects/{src,doc,bin}- Create nested directories
Create Empty File - Create new files or update timestamps
Examples:
touch file.txt- Create empty filetouch file1.txt file2.txt- Create multiple files
Remove Files/Directories - Delete files and directories
Common Options:
rm file.txt- Remove filerm -r directory- Remove directory recursivelyrm -f file- Force remove without confirmation
rm -rf / command can destroy your entire system! Always double-check what you're deleting, especially when using -r (recursive) and -f (force) options.
File Operations Commands
Copy Files/Directories - Duplicate files and directories
Examples:
cp file1.txt file2.txt- Copy filecp -r dir1 dir2- Copy directory recursivelycp -v file* backup/- Verbose copy with wildcard
Move/Rename Files - Move files or rename them
Examples:
mv old.txt new.txt- Rename filemv file.txt /new/location/- Move filemv *.txt documents/- Move multiple files
Concatenate and Display - View file contents
Common Uses:
cat file.txt- Display file contentcat file1.txt file2.txt- Concatenate filescat > newfile.txt- Create file from input
File Viewing and Editing Commands
Page Through Files - View files page by page
Navigation in less:
- Space - Next page
- b - Previous page
- q - Quit
- /pattern - Search
View File Beginnings/Endings - Show first/last lines
Examples:
head -n 10 file.log- First 10 linestail -f app.log- Follow log in real-timetail -n 20 file.log- Last 20 lines
Search Text - Find patterns in files
Examples:
grep "error" logfile.txt- Search for "error"grep -r "function" src/- Recursive searchgrep -i "warning" file.txt- Case-insensitive
tab key for auto-completion of file and directory names. Press tab twice to see available options when multiple matches exist.
Practical Command Examples
Navigate and Explore:
pwd - Check where you arels -la - See everything in current directorycd ~/Documents - Go to Documents folderFile Management:
mkdir myproject - Create project directorycd myproject - Enter the directorytouch script.sh README.md - Create project filescp script.sh backup/ - Backup your scriptContent Viewing:
cat README.md - Quick file viewless largefile.log - Page through large filetail -f /var/log/syslog - Monitor system logs
Quick Reference Cheat Sheet
Navigation
pwd- Show current directoryls- List filescd- Change directorycd ~- Go homecd ..- Go up
File Operations
touch- Create filecp- Copy filemv- Move/renamerm- Delete filemkdir- Create directory
Viewing Content
cat- Display fileless- Page throughhead- Show beginningtail- Show endgrep- Search text
Hands-On Practice Exercise
Try these commands in sequence to practice your skills:
# 1. Check your current location
pwd
# 2. Create a practice directory
mkdir linux_practice
cd linux_practice
# 3. Create some files
touch file1.txt file2.txt document.md
echo "Hello World" > greeting.txt
# 4. List files with details
ls -la
# 5. Create a subdirectory and move files
mkdir texts
mv *.txt texts/
# 6. View file contents
cat texts/greeting.txt
# 7. Copy a file
cp texts/greeting.txt backup_greeting.txt
# 8. Search for specific content
grep "Hello" texts/greeting.txt
# 9. Clean up (optional)
cd ..
rm -rf linux_practice
Key Takeaways
Mastering these basic Linux commands is essential for efficient system navigation and file management. Remember to practice regularly, use tab completion, and always double-check destructive commands like rm. These fundamentals form the foundation for more advanced Linux administration and DevOps tasks.
Next Step: Explore file permissions and ownership commands (chmod, chown, chgrp) to understand Linux security basics.