Understanding Linux Filesystem, Command-Line Basics, and Network Commands

Linux is an open-source operating system widely used for personal, server, and cloud environments. Whether you're a beginner or an advanced user, understanding the Linux filesystem, command-line basics, and networking commands is essential.


The Linux Filesystem Hierarchy

The Linux filesystem follows a hierarchical structure starting with the root (/). Each directory has a specific purpose:

1. / (Root Directory)

  • The top-level directory in the filesystem hierarchy.

  • All files and directories are located under this root.

2. /bin (Binary)

  • Stores essential binary executables required for system recovery and repair.

  • Example: /bin/ls (lists directory contents).

3. /boot

  • Contains files needed for the initial boot process.

  • Example: vmlinuz (Linux kernel image).

4. /etc

  • Holds configuration files for tools and technologies installed on the system.

  • Example: /etc/ssh/sshd_config (SSH configuration file).

5. /home

  • User-specific directories.

  • Example: /home/user1 (directory for user1's files).

6. /lib

  • Contains essential shared libraries and kernel modules required for system booting and repair.

  • Example: /lib/modules (kernel modules).

7. /usr (Unique System Resources)

  • Contains user-specific data and additional programs.

  • Example: /usr/bin (user binary executables).

8. /var

  • Stores variable data such as logs and temporary files.

  • Example: /var/log/syslog (system logs).

9. /root

  • Home directory of the root (superuser).

10. /dev (Devices)

  • Contains device files representing hardware devices.

  • Example: /dev/sda (hard disk device).

11. /proc (Processes)

  • Virtual directory with information about system processes.

  • Example: /proc/<PID> (process-specific details).

12. /tmp

  • Temporary files generated by applications are stored here.

13. /opt

  • Optional software not managed by the package manager.

14. /mnt

  • Mount point for external storage systems.

  • Example: USB or additional hard drive.

15. /srv

  • Service-related files, often for web servers or FTP.

16. /sbin (System Binary)

  • Contains essential system binaries for administrative tasks, often used by the root user.

  • Example: /sbin/reboot.


Linux Terminal Basics

Linux supports multiple terminal environments, such as Bash and Shell. Below are commonly used commands:

File and Folder Commands

  1. List Files

    • ls -l: List files with details (permissions, owner, size, etc.).

    • Example:

        ls -l
      

      Output:

        drwxr-xr-x 3 user1 group 4096 Nov 20 10:00 folder1
      
    • Permissions: rwx (read, write, execute) for owner, group, and other users.

  2. Hidden Files

    • ls -la: Show all files, including hidden ones.

    • Example:

        ls -la
      
  3. Delete Users and Groups

    • deluser: Delete a user.

    • delgroup: Delete a group.

Vim Navigation and Editing

  1. Navigation:

    • gg: Go to the beginning of the file.

    • G: Go to the end of the file.

    • 0: Start of the current line.

    • $: End of the current line.

  2. Editing:

    • i: Insert before the cursor.

    • a: Append after the cursor.

    • o: Open a new line below the current line.

    • x: Delete the character under the cursor.

    • dd: Delete the current line.

  3. Saving and Quitting:

    • :w: Save the file.

    • :q: Quit Vim.

    • :wq: Save and quit.

    • :q!: Quit without saving changes.

  4. Searching and Replacing:

    • /searchpattern: Search for a pattern.

    • :%s/old/new/gc: Replace "old" with "new" with confirmation.


Networking Commands

Linux provides powerful networking utilities to manage and troubleshoot network connections.

  1. Show IP Address

    • ip addr show: Display network interfaces and their IP addresses.

    • Example:

        ip addr show
      
  2. Traceroute

    • traceroute <hostname>: Displays the route packets take to the destination.

    • Example:

        traceroute google.com
      
  3. Netstat and SS

    • netstat -tuln: Shows active network connections (TCP and UDP).

    • ss -tuln: Similar to netstat but faster.

  4. Routing Table

    • route -n: Displays the kernel routing table.

    • Example:

        route -n
      
  5. DNS Lookup

    • dig <domain>: Query DNS servers.

    • Example:

        dig google.com
      
    • nslookup <domain>: Another DNS query tool.

    • Example:

        nslookup google.com
      
  6. Iptables

    • Configure firewall rules.

    • Example: Allow incoming SSH (port 22).

        sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
      
  7. Hostname

    • Display or set the hostname of the machine.

    • Example:

        hostname
      

Practical Use Cases

  1. Clearing the Screen

    • Ctrl + L: Clears the terminal screen.
  2. Moving to Specific Lines in Vim

    • 3G: Go to line 3.
  3. Replacing Text in Vim

    • Replace "old" with "new" in the entire file:

        :%s/old/new/g
      

Feedback and Suggestions? Let me know in the comments! ๐ŸŒŸ

ย