Day 6 of 100 Days of DevOps: Exploring Essential Linux Commands 🐧

Welcome to Day 6! Today, we’re diving into core Linux commands that every DevOps professional should know. By the end of this post, you’ll have practiced file management, system navigation, and even some basic troubleshooting.

Ready? Let's get started! 💪


Part 1: File & Directory Management 📁

  1. Where am I?
    Use pwd to print your current working directory. This helps you know where you are in the Linux filesystem:

     pwd
    
  2. See it All!
    List everything (including hidden files) with ls -a. Hidden files can contain configurations or settings:

     ls -a
    
  3. Create Nested Directories
    Need to set up a folder structure? Create A/B/C/D/E in one go with the -p flag. Try it out:

     mkdir -p A/B/C/D/E
    
  4. Change Directories
    Move to a directory using cd. Let’s navigate to A/B/C:

     cd A/B/C
    
  5. Make and Break a Directory
    First, create a folder called TestDir:

     mkdir TestDir
    

    Then remove it using rmdir (only works if empty):

     rmdir TestDir
    
  6. Create a File
    Use touch to make an empty file named example.txt. This is handy for setting up new files or updating timestamps:

     touch example.txt
    
  7. Copy and Move Files
    Copy example.txt to a new file named example_copy.txt:

     cp example.txt example_copy.txt
    

    Then rename it using mv:

     mv example_copy.txt example_moved.txt
    

    Finally, delete it:

     rm example_moved.txt
    

Part 2: File Viewing & Editing 📄

  1. View File Content
    Use cat to display everything in example.txt:

     cat example.txt
    
  2. Need to Scroll?
    For larger files, less lets you scroll through content one page at a time:

     less example.txt
    
  3. Get a Sneak Peek
    Use head to show the first 10 lines or tail for the last 10:

     head example.txt
     tail example.txt
    
  4. Editing Time!
    Open example.txt with nano or vim, two popular text editors. You’ll get familiar with both over time:

     nano example.txt
     vim example.txt
    

Part 3: Permissions & Ownership 🔐

  1. Adjust Permissions
    Want to set permissions? chmod 744 gives the owner read, write, and execute permissions, and read-only for others:

     chmod 744 example.txt
    
  2. Change Owner
    Use chown to assign a new owner and group:

     chown user:group example.txt
    
  3. Detailed Listing
    Check out file permissions and ownership with ls -l:

     ls -l
    

Part 4: System Monitoring & Management 📊

  1. What’s Running?
    The top command shows live processes, sorted by usage. Use q to quit:

     top
    
  2. Detailed Process List
    ps aux provides more detailed info about all running processes:

     ps aux
    
  3. Disk and Directory Usage
    Check available disk space with df -h:

     df -h
    

    And use du -sh . to see the size of your current directory:

     du -sh .
    
  4. Memory and Uptime
    free -h shows memory usage in a human-readable format:

     free -h
    

    uptime lets you know how long the system has been running:

     uptime
    

Additional Handy Commands 🛠️

Here are a few more must-know commands to boost your productivity:

  1. Command Shortcuts
    Make shortcuts with alias. For example, turn ls -la into a quick ll:

     alias ll='ls -la'
    
  2. Search Within Files
    Look for specific text inside files using grep:

     grep "search_term" example.txt
    
  3. Find Files
    Locate files by name with find:

     find /path/to/search -name "filename"
    
  4. Archive Files
    Compress a directory with tar. This example creates a .tar.gz archive:

     tar -czvf archive.tar.gz /path/to/directory
    
  5. Download Files
    Grab files from the internet with wget:

     wget http://example.com/file.zip
    
  6. Data Transfer
    Fetch a file using curl:

     curl -O http://example.com/file.zip
    
  7. Get Help
    Not sure about a command? Check the manual with man:

     man ls
    

Conclusion

These commands are the backbone of Linux system management. Practicing them regularly will make you comfortable with navigating and managing your environment.

Keep sharing your progress and questions in the comments, and let’s continue learning together. Happy learning!