Day 1: Linux Basics - Commands, File System, Users & Permissions - Challenges

Day 1: Linux Basics - Commands, File System, Users & Permissions - Challenges


Learning points:

  • Basic Shell Commands - Navigate with cd, list files with ls, view file contents with cat, etc.

  • Filesystem Hierarchy - Understand the Linux directory structure (/etc, /var, /home, etc.).

  • File Permissions - Learn chmod, chown, ls -l and understand read, write, execute (rwx).

  • Users & Groups - Creating users, managing groups, and assigning permissions.


Initial Tasks:

  • ✅ Setup Task: If you’re on Windows, install a Linux VM or use WSL; on Mac/Linux, open the Terminal.

  • Challenge 1 : List all files (including hidden ones) in your home directory and sort them by modification time.

  • Challenge 2 : Create a directory named devops_challenge_day_1, navigate into it, and create an empty file named day1.txt .

  • Challenge 3 : Find the total disk usage of the /var/log directory in human-readable format.

  • Challenge 4 : Create a new user called devops_user and add them to the sudo group.

  • Challenge 5 : Create a group called devops_team and add devops_user to that group.

  • Challenge 6 : Change the permissions of day1.txt to allow only the owner to read and write, but no permissions for others.

  • Challenge 7 : Find all files in /etc that were modified in the last 7 days.

  • Challenge 8 : Write a one-liner command to find the most frequently used command in your shell history.


✅ Solutions

Challenge 1 : List all files (including hidden ones) in your home directory and sort them by modification time.

Answer :

Command :

ls -laht ~

Explanation:

  • ls → List files.

  • -l → Long format (detailed info).

  • -a → Show hidden files.

  • -h → Human-readable sizes.

  • -t → Sort by modification time (newest first).

  • ~ → Home directory.

OutPut :


✅ Challenge 2 : Create a directory named devops_challenge_day_1, navigate into it, and create an empty file named day1.txt.

Answer :

Command :

mkdir devops_challenge_day_1  
cd devops_challenge_day_1  
touch day1.txt

Explanation:

  • mkdir devops_challenge_day_1 → Creates the directory.

  • cd devops_challenge_day_1 → Moves into the directory.

  • touch day1.txt → Creates an empty file named day1.txt.

OutPut :


✅ Challenge 3: Find the total disk usage of the /var/log directory in human-readable format.

Answer :

Command :

du -sh /var/log

Explanation:

  • du → Disk usage command.

  • -s → Summary (total size only).

  • -h → Human-readable format (KB, MB, GB).

  • /var/log → Target directory.

OutPut :


✅ Challenge 4: Create a new user called devops_user and add them to the sudo group.

Answer :

Command :

sudo useradd -m -s /bin/bash devops_user  
sudo usermod -aG sudo devops_user
sudo passwd devops_user

Explanation:

  • sudo useradd -m -s /bin/bash devops_user → Creates devops_user with a home directory and Bash shell.

  • sudo usermod -aG sudo devops_user → Adds devops_user to the sudo group.

    Run the below command to verify it:

      id devops_user
    

    OutPut :


    ✅ Challenge 5: Create a group called devops_team and add devops_user to that group.Answer :

    Answer :

    Command :

      sudo groupadd devops_team  
      sudo usermod -aG devops_team devops_user
    

    Explanation:

  • sudo groupadd devops_team → Creates the devops_team group.

  • sudo usermod -aG devops_team devops_user → Adds devops_user to devops_team.

    Run the below command to verify it:

      groups devops_user
    

    OutPut :


    ✅ Challenge 6: Change the permissions of day1.txt to allow only the owner to read and write, but no permissions for others.

    Answer :

    Command :

      chmod 600 devops_challenge_day_1/day1.txt
    

    Explanation:

  • chmod 600 → Sets permissions to read & write for owner, no permissions for others.

  • devops_challenge_day_1/day1.txt → Target file.

    Run the below command to verify it:

      ls -l devops_challenge_day_1/day1.txt
    

    OutPut :

    Explanation:

Permission Level in numeric (octal) mode

Octal (Numeric)Symbolic (rwx)Description
000----------No permissions (no read, write, or execute)
100--x------Execute only for owner
200-w-------Write only for owner
300-wx------Write and execute for owner
400r--------Read only for owner
500r-x------Read and execute for owner
600rw-------Read and write for owner (commonly used for private files)
700rwx------Full access for owner
644rw-r--r--Read and write for owner, read-only for group and others (common for text files)
655rw-r-xr-xRead and write for owner, read and execute for group and others
660rw-rw----Read and write for owner and group, no access for others
664rw-rw-r--Read and write for owner and group, read-only for others
666rw-rw-rw-Read and write for everyone (not recommended for security reasons)
700rwx------Full access for owner, no access for others (common for private executables)
744rwxr--r--Full access for owner, read-only for group and others
755rwxr-xr-xFull access for owner, read and execute for group and others (common for scripts and executables)
770rwxrwx---Full access for owner and group, no access for others
775rwxrwxr-xFull access for owner and group, read and execute for others
777rwxrwxrwxFull access for everyone (very insecure, not recommended)

Key Points:

• First digit: Owner permissions

• Second digit: Group permissions

• Third digit: Others' permissions

• r (4) = Read permission

• w (2) = Write permission

• x (1) = Execute permission

• Sum of values (rwx = 4+2+1 = 7) = All allowed


Challenge 7: Find all files in /etc that were modified in the last 7 days.

Answer :

Command :

sudo find /etc -type f -mtime -7

OutPut :

Explanation:

  • sudo → For admin privilege

  • find /etc → Search in the /etc directory.

  • -type f → Look for files (not directories).

  • -mtime -7 → Find files modified in the last 7 days.


    Challenge 8: Write a one-liner command to find the most frequently used command in your shell history.

    Answer :

    Command :

      history | awk '{print $2}' | sort | uniq -c | sort -nr | head -1
    

    OutPut :

    Explanation:

    • history → Shows command history.

      • awk '{print $2}' → Extracts the command name.

      • sort → Sorts commands alphabetically.

      • uniq -c → Counts occurrences of each command.

      • sort -nr → Sorts by frequency (descending).

      • head -1 → Displays the most used command.


Thanks for your time. I hope you enjoy my blog, please follow me on LinkedIn for more updates.