DEV Community

Shreyas Vithalkar
Shreyas Vithalkar

Posted on

πŸš€ Day 3 of My 90-Day DevOps Journey: Vim Editor and Linux File Types

Welcome back to Day 3 of my DevOps journey! Today, I explored the Vim editor and learned about the types of files in Linux. Let’s dive in!


πŸ–‹οΈ Vim Editor Basics

Vim is a highly efficient text editor that’s perfect for editing files in Linux. It operates in two primary modes:

  • Command Mode: For executing commands.

  • Insert Mode: For writing and editing text.

Image description

πŸ› οΈ Essential Vim Commands

  • Switching Modes:

    • Press i β†’ Enter Insert mode.

    • Press Esc β†’ Return to Command mode.

  • File Operations:

    :w     # Save the file  
    :q     # Quit Vim  
    :wq    # Save and quit  
    :q!    # Quit without saving
    
    • Text Navigation:

      • h β†’ Move left

      • l β†’ Move right

      • j β†’ Move down

      • k β†’ Move up

    • Editing:

      • x β†’ Delete a character

      • dd β†’ Delete a line

      • yy β†’ Copy a line

      • p β†’ Paste copied content

    • Search and Replace:

      /pattern      # Search for 'pattern'  
      :%s/old/new/g # Replace 'old' with 'new' globally 
      

πŸ“‚ Types of Files in Linux

Linux files come in various types, each serving a unique purpose. Here’s what I learned:

  1. Regular File:

    • Stores data like text, scripts, or binaries.

    • Command to check:

ls -l file.txt
Look for a `-` at the start of the permissions (`-rw-r--r--`).
  1. Directory:

    • Contains other files or directories.

    • Identified with a d in permissions (drwxr-xr-x).

  2. Link File:

    • A shortcut to another file. (This you can consider as a Desktop short for any file/application in Windows) Can be:

      • Hard Link: Points directly to the file's data.

        ln file.txt hardlink.txt
        
      • Soft Link: Points to the file's location.

        ln -s file.txt softlink.txt
        
    • Use unlink filename to unlink a file.

  3. Special File:

    • Represents devices like printers or disks, typically found in /dev.
  4. Socket:

    • Enables communication between processes, often used in networking.
  5. Block File:

    • Represents devices that transfer data in blocks (e.g., hard drives).

πŸ” Command to Identify File Types:

Use the file command to determine a file’s type:

file filename

Also a bonus thing, some options on our ls command

ls -l

The above command with -l option is long listing of files (Sorts Alphabetically)

ls -lt

Sort by Timestamp, (Latest first/ Last modified)

ls -ltr

The -r option is for reverse sorting. And in the above example, it will sort old modified files first.


✨ Key Takeaway

Today, I took a big step in strengthening my Linux foundation. Mastering the Vim editor and understanding file types are crucial skills for any DevOps engineer. πŸš€

Stay tuned for more as I continue my journey to DevOps mastery!

Top comments (0)