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

Hari Kiran BHari Kiran B
4 min read

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

๐ŸŽฏ Goal: Understand how to list files and sort them based on their last modification time.

  • Command:

      ls -alt
    
  • Explanation:

    • ls โ†’ List files and directories

    • -a โ†’ Show hidden files (files starting with .)

    • -l โ†’ Display detailed file information (permissions, owner, size, date modified, etc.)

    • -t โ†’ Sort by modification time (newest first)


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

๐ŸŽฏ Goal: Learn directory and file manipulation.

  • Commands:

      mkdir devops_challenge_Day1
      cd devops_challenge_Day1
      touch day1.txt
    
  • Explanation:

    • mkdir โ†’ Creates a new directory

    • cd โ†’ Navigates into that directory

    • touch โ†’ Creates an empty file


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

๐ŸŽฏ Goal: Learn how to check the disk usage of a specific directory.

  • Command:

      du -sh /var/log
    
  • Explanation:

    • du โ†’ Disk usage command

    • -s โ†’ Summarizes total size instead of showing individual files

    • -h โ†’ Displays output in a human-readable format (KB, MB, GB)


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

๐ŸŽฏ Goal: Learn how to manage users and grant administrative privileges.

  • Commands:

      sudo useradd -m devops_user
      sudo usermod -aG sudo devops_user
    
  • Explanation:

    • useradd -m โ†’ Creates a new user and assigns a home directory

    • usermod -aG โ†’ Adds the user to a specific group (sudo in this case)


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

๐ŸŽฏ Goal: Learn how to create user groups and manage group memberships.

  • Commands:

      sudo groupadd devops_team
      sudo usermod -aG devops_team devops_user
    
  • Explanation:

    • groupadd โ†’ Creates a new group

    • usermod -aG โ†’ Adds an existing user (devops_user) to the new group (devops_team)


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

๐ŸŽฏ Goal: Understand file permissions and how to modify them using chmod.

  • Command:

      chmod 600 day1.txt
    
  • Explanation:

    • 600 โ†’ Sets file permissions so that:

      • Owner โ†’ Read (r) and write (w)

      • Group & Others โ†’ No permissions (---)


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

๐ŸŽฏ Goal: Learn how to search for files based on modification time.

  • Command:

      find /etc -type f -mtime -7
    
  • Explanation:

    • find โ†’ Searches for files

    • -type f โ†’ Looks for regular files (not directories)

    • -mtime -7 โ†’ Finds 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.

๐ŸŽฏ Goal: Analyze and optimize your command-line usage.

  • Command:

      history | awk '{print $2}' | sort | uniq -c | sort -nr | head -5
    
  • Explanation:

    • history โ†’ Displays a list of previously executed commands

    • awk '{print $2}' โ†’ Extracts only the command name (ignores line numbers)

    • sort | uniq -c โ†’ Counts occurrences of each command

    • sort -nr โ†’ Sorts the list in descending order (most used first)

    • head -5 โ†’ Shows the top 5 most frequently used commands


Topics Covered Today

โœ… Basic Shell Commands โ€“ Navigating directories (cd), listing files (ls), viewing file contents (cat, touch).
โœ… Filesystem Hierarchy โ€“ Understanding Linux directory structures (/etc, /var, /home).
โœ… File Permissions โ€“ Using chmod, ls -l, and learning read, write, execute (rwx).
โœ… User & Group Management โ€“ Creating users (useradd), modifying groups (usermod, groupadd).
โœ… File & Directory Operations โ€“ Creating, modifying, and searching files (find, du, ls, awk, sort).
โœ… History & Command Usage โ€“ Analyzing shell history to improve workflow.

21
Subscribe to my newsletter

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

Written by

Hari Kiran B
Hari Kiran B