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
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.
Hidden Files
ls -la
: Show all files, including hidden ones.Example:
ls -la
Delete Users and Groups
deluser
: Delete a user.delgroup
: Delete a group.
Vim Navigation and Editing
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.
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.
Saving and Quitting:
:w
: Save the file.:q
: Quit Vim.:wq
: Save and quit.:q!
: Quit without saving changes.
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.
Show IP Address
ip addr show
: Display network interfaces and their IP addresses.Example:
ip addr show
Traceroute
traceroute <hostname>
: Displays the route packets take to the destination.Example:
traceroute google.com
Netstat and SS
netstat -tuln
: Shows active network connections (TCP and UDP).ss -tuln
: Similar tonetstat
but faster.
Routing Table
route -n
: Displays the kernel routing table.Example:
route -n
DNS Lookup
dig <domain>
: Query DNS servers.Example:
dig google.com
nslookup <domain>
: Another DNS query tool.Example:
nslookup google.com
Iptables
Configure firewall rules.
Example: Allow incoming SSH (port 22).
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
Hostname
Display or set the hostname of the machine.
Example:
hostname
Practical Use Cases
Clearing the Screen
Ctrl + L
: Clears the terminal screen.
Moving to Specific Lines in Vim
3G
: Go to line 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! ๐
Subscribe to my newsletter
Read articles from Krishnat Ramchandra Hogale directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Krishnat Ramchandra Hogale
Krishnat Ramchandra Hogale
Hi! Iโm Krishnat, a Senior IT Associate specializing in Performance Engineering at NTT DATA SERVICES. With experience in cloud technologies, DevOps, and automation testing, I focus on optimizing CI/CD pipelines and enhancing infrastructure management. Currently, I'm expanding my expertise in DevOps and AWS Solutions Architecture, aiming to implement robust, scalable solutions that streamline deployment and operational workflows.