Day 13 – Linux Fundamentals and Troubleshooting

Today’s focus was on building a strong foundation in Linux commands with an emphasis on active learning and troubleshooting techniques.
Each command was explored with real-world scenarios in mind to understand not only what it does, but why and when to use it.
1. Understanding the System
Check OS and distribution details
Command:
cat /etc/os-release
Purpose: Displays information about the operating system and its version.
Example: Before installing software, I confirmed the OS version to ensure compatibility.
View manual for a command
Command:
man command_name
Purpose: Opens the manual page for the specified command, providing usage, options, and examples.
Example: Used
man find
to understand advanced search patterns.
Find the location of a package
Command:
whereis package_name
Purpose: Shows the path where the package binary, source, and man pages are stored.
Example: Located the installation path of
python3
for use in scripts.
2. User and Path Awareness
Prompt symbols meaning
$
→ Normal user prompt#
→ Root user prompt (administrator)~
→ Home directory path
Navigating directories
cd ..
→ Move up one directory levelcd /home/ec2-user/
→ Go directly to the given pathAbsolute Path: Full path from root (e.g.,
/etc/nginx/nginx.conf
)Relative Path: Path based on current location (e.g.,
cd ../logs
)
3. File Operations
Copy files
cp file1.txt file2.txt
→ Copies content of file1 into file2Useful for creating backups before editing.
Move or rename files
mv oldname.txt newname.txt
→ Renames the fileExample: Used this to rename configuration files after modification.
Remove non-empty directories
rm -rf dirname
→ Force remove a directory and its contentsExample: Cleared a temporary folder containing large log files.
4. Command History and Path Checks
View previously executed commands
history
→ Lists commands with serial numbers for quick referenceHelpful in retracing steps during troubleshooting.
Clear command history
history -c
→ Removes stored command history for privacy/security reasons.
Find executable path
which command_name
→ Displays the absolute path of the executableExample: Located the path of
java
for Jenkins setup.
5. Quick Utilities
Calculator in Linux
Install:
sudo yum install bc -y
Run:
bc
→ Enter mathematical expressions directlyExample: Calculated memory usage percentages while checking server load.
Hostname operations
hostname -i
→ Shows the IP address of the machinesudo hostnamectl set-hostname server1
→ Changes the hostname
Check uptime
uptime
→ Displays how long the system has been running along with load averages.
6. Package Management
List packages
yum list available
→ Shows all available packages for installationdnf list installed
→ Lists all currently installed packages
7. Directory and File Listing
List files with details
ls -l
→ Detailed list of files and directoriesls -lr
→ Reverse order listingls -al
→ Includes hidden filesls -lh
→ Human-readable file sizes
View contents
cat file.txt
→ Displays file contenttac file.txt
→ Displays content in reverse order
8. Sorting and Searching
Sorting file contents
sort filename
→ Alphabetically sorts file contentssort filename | uniq
→ Removes duplicate lines after sorting
Finding files
find / -name target.txt
→ Searches entire systemfind /root/ -name kiran.txt
→ Searches within/root
GREP search
grep "keyword" filename
→ Searches for a specific word inside a fileExample: Used to locate a specific configuration parameter inside a large config file.
9. Working with File Sections
View line numbers
cat -n file.txt
→ Displays file content with line numbers
First and last lines
head file.txt
→ Shows first 10 lines by defaulttail file.txt
→ Shows last 10 lines by default
10. Linux Directory Structure with Use Cases
Troubleshooting Scenarios Today
Problem: Command not found while running a script
Solution: Usedwhich
to verify binary location and updated thePATH
variable.Problem: “Directory not empty” error while deleting
Solution: Appliedrm -rf
after verifying the directory’s contents.Problem: Confusion between files with similar names
Solution: Listed files withls -lh
and sorted by size for clarity.
Key Takeaway
The most valuable lesson was the importance of checking before acting.
Verifying paths, confirming package locations, and reviewing history before repeating commands not only saved time but also prevented errors.
Subscribe to my newsletter
Read articles from Akanksha directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
