Day 13 – Linux Fundamentals and Troubleshooting

AkankshaAkanksha
4 min read

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

  1. 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.

  2. 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.

  3. 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

  1. Prompt symbols meaning

    • $ → Normal user prompt

    • # → Root user prompt (administrator)

    • ~ → Home directory path

  2. Navigating directories

    • cd .. → Move up one directory level

    • cd /home/ec2-user/ → Go directly to the given path

    • Absolute 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

  1. Copy files

    • cp file1.txt file2.txt → Copies content of file1 into file2

    • Useful for creating backups before editing.

  2. Move or rename files

    • mv oldname.txt newname.txt → Renames the file

    • Example: Used this to rename configuration files after modification.

  3. Remove non-empty directories

    • rm -rf dirname → Force remove a directory and its contents

    • Example: Cleared a temporary folder containing large log files.


4. Command History and Path Checks

  1. View previously executed commands

    • history → Lists commands with serial numbers for quick reference

    • Helpful in retracing steps during troubleshooting.

  2. Clear command history

    • history -c → Removes stored command history for privacy/security reasons.
  3. Find executable path

    • which command_name → Displays the absolute path of the executable

    • Example: Located the path of java for Jenkins setup.


5. Quick Utilities

  1. Calculator in Linux

    • Install: sudo yum install bc -y

    • Run: bc → Enter mathematical expressions directly

    • Example: Calculated memory usage percentages while checking server load.

  2. Hostname operations

    • hostname -i → Shows the IP address of the machine

    • sudo hostnamectl set-hostname server1 → Changes the hostname

  3. Check uptime

    • uptime → Displays how long the system has been running along with load averages.

6. Package Management

  1. List packages

    • yum list available → Shows all available packages for installation

    • dnf list installed → Lists all currently installed packages


7. Directory and File Listing

  1. List files with details

    • ls -l → Detailed list of files and directories

    • ls -lr → Reverse order listing

    • ls -al → Includes hidden files

    • ls -lh → Human-readable file sizes

  2. View contents

    • cat file.txt → Displays file content

    • tac file.txt → Displays content in reverse order


8. Sorting and Searching

  1. Sorting file contents

    • sort filename → Alphabetically sorts file contents

    • sort filename | uniq → Removes duplicate lines after sorting

  2. Finding files

    • find / -name target.txt → Searches entire system

    • find /root/ -name kiran.txt → Searches within /root

  3. GREP search

    • grep "keyword" filename → Searches for a specific word inside a file

    • Example: Used to locate a specific configuration parameter inside a large config file.


9. Working with File Sections

  1. View line numbers

    • cat -n file.txt → Displays file content with line numbers
  2. First and last lines

    • head file.txt → Shows first 10 lines by default

    • tail file.txt → Shows last 10 lines by default


10. Linux Directory Structure with Use Cases


Troubleshooting Scenarios Today

  1. Problem: Command not found while running a script
    Solution: Used which to verify binary location and updated the PATH variable.

  2. Problem: “Directory not empty” error while deleting
    Solution: Applied rm -rf after verifying the directory’s contents.

  3. Problem: Confusion between files with similar names
    Solution: Listed files with ls -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.

0
Subscribe to my newsletter

Read articles from Akanksha directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Akanksha
Akanksha