Comprehensive Guide to the Most Used Linux Commands

TenithTenith
7 min read

๐Ÿš€ Hey Tech Wizards and Terminal Newbies! Ready to spice up your Linux game? Welcome to my ultimate guide to mastering the Linux command line. Think of this as your secret playbook for navigating the Linux universe.

In this snazzy post, I'm dissecting the most used Linux commands, making them as easy as pie. Whether you're a code guru or just starting, you'll be bossing around your Linux system in no time!

Here's a sneak peek at my command line extravaganza:

๐Ÿ—„๏ธ - File and Directory Management: Learn the fundamental commands for organizing and manipulating files and directories, paving your way to Linux expertise.

๐Ÿ“‚ - File Viewing and Editing: Dive into file manipulation with text editors and viewers, gaining the skills to view and modify files like a pro.

๐ŸŒ - Networking and Monitoring: Explore the world of network configuration and monitoring, granting you backstage access to the network scene.

๐Ÿ“ฆ - Package Management: Master the art of software installation and management, as if you wielded a magical wand for packages.

๐Ÿ–ฅ๏ธ - Process Management: Become a maestro of process management, juggling your system's tasks and processes seamlessly.

โ„น๏ธ - System Information: Transform into a digital detective, uncovering the mysteries of your machine by extracting crucial system information.

๐Ÿ‘ฅ - User and Group Management: Step into the role of a digital puppeteer, skillfully managing users and groups on your Linux system.

Get ready to embark on a thrilling ride through the command line cosmos. Itโ€™s not just about commands; itโ€™s about becoming the Linux hero you were destined to be. So, buckle up, and letโ€™s dive into this adventure!


1. File and Directory Management

1.1 ls (List)

Description: Displays contents of a directory. Example:

bashCopy code$ ls -l
total 4
drwxr-xr-x 2 user user 4096 Jul 8 12:00 Documents

1.2 pwd (Print Working Directory)

Description: Shows the current directory path. Example:

bashCopy code$ pwd
/home/user

1.3 cd (Change Directory)

Description: Changes the current directory. Example:

bashCopy code$ cd /var/www
$ pwd
/var/www

1.4 mkdir (Make Directory)

Description: Creates a new directory. Example:

bashCopy code$ mkdir new_folder
$ ls
new_folder

1.5 rmdir (Remove Directory)

Description: Deletes an empty directory. Example:

bashCopy code$ rmdir old_folder
$ ls

1.6 touch (Create Empty File)

Description: Creates an empty file or updates the timestamp of an existing file. Example:

bashCopy code$ touch new_file.txt
$ ls
new_file.txt

1.7 cp (Copy)

Description: Copies files and directories. Example:

bashCopy code$ cp source_file.txt destination_file.txt
$ ls
source_file.txt destination_file.txt

1.8 mv (Move)

Description: Moves or renames files and directories. Example:

bashCopy code$ mv old_name.txt new_name.txt
$ ls
new_name.txt

1.9 rm (Remove)

Description: Deletes files or directories. Example:

bashCopy code$ rm unwanted_file.txt
$ ls

2. File Viewing and Editing

2.1 cat (Concatenate and Display)

Description: Reads and displays file content. Example:

bashCopy code$ cat example.txt
This is the content of the file.

2.2 vim (Vi IMproved)

Description: A text editor for creating and modifying files. Example:

bashCopy code$ vim myfile.txt
# Inside vim, type and edit text, then save and exit with :wq

2.3 less (View File Content)

Description: Views file content in a scrollable window. Example:

bashCopy code$ less large_file.log
# Use arrow keys to navigate, type 'q' to quit

3. Networking and Monitoring

3.1 ifconfig (Interface Configuration)

Description: Configures or displays network interface settings. Example:

bashCopy code$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.101  netmask 255.255.255.0  broadcast 192.168.0.255

3.2 ss (Socket Statistics)

Description: Displays socket information. Example:

bashCopy code$ ss -tuln
State     Recv-Q    Send-Q        Local Address:Port       Peer Address:Port
LISTEN    0         128               0.0.0.0:22            0.0.0.0:*

4. Package Management

4.1 apt-get (APT Package Handling Utility)

Description: Used in Debian-based systems like Ubuntu for handling packages. Example:

bashCopy code$ sudo apt-get update
# Updates package lists

4.2 apt (Advanced Package Tool)

Description: A more user-friendly interface for handling packages in Debian-based systems. Example:

bashCopy code$ sudo apt install nginx
# Installs the nginx package

4.3 yum (Yellowdog Updater, Modified)

Description: Package manager for RedHat-based systems, used for managing RPM packages. Example:

bashCopy code$ sudo yum install git
# Installs the git package

4.4 dnf (Dandified YUM)

Description: Next-generation version of yum, used in Fedora and other RPM-based distributions. Example:

bashCopy code$ sudo dnf install python3
# Installs Python 3

4.5 rpm (RPM Package Manager)

Description: A package management system for installing, updating, and removing RPM packages. Example:

bashCopy code$ rpm -qa
# Lists all installed RPM packages

4.6 dpkg (Debian Package)

Description: Low-level tool for handling Debian (.deb) packages. Example:

bashCopy code$ dpkg -l
# Lists all Debian packages

4.7 snap (Snapcraft Package Manager)

Description: Universal package manager developed by Canonical, used for installing snap packages. Example:

bashCopy code$ snap install spotify
# Installs the Spotify snap package

4.8 zypper (Command Line Interface of ZYpp)

Description: Package manager for openSUSE, used for handling RPM packages. Example:

bashCopy code$ zypper install apache2
# Installs the Apache 2 web server

5. Process Management

5.1 ps (Process Status)

Description: Shows information about active processes. Example:

bashCopy code$ ps aux
# Displays detailed information about all running processes

5.2 top (Task Optimizer)

Description: Real-time display of running tasks and system status. Example:

bashCopy code$ top
# Displays an ongoing view of process activity

5.3 kill (Terminate Process)

Description: Sends a signal to terminate a process. Example:

bashCopy code$ kill 1234
# Terminates the process with PID 1234

5.4 killall (Kill Processes by Name)

Description: Terminates all processes with a given name. Example:

bashCopy code$ killall firefox
# Kills all instances of Firefox

5.5 pstree (Process Tree)

Description: Shows running processes as a tree. Example:

bashCopy code$ pstree
# Displays a tree of processes

5.6 htop (Interactive Process Viewer)

Description: An interactive process viewer, an improved version of top. Example:

bashCopy code$ htop
# Displays an interactive process management interface

6. System Information

6.1 uname (Unix Name)

Description: Displays system information. Example:

bashCopy code$ uname -a
# Displays all system information

6.2 df (Disk Free)

Description: Shows the amount of free disk space on file systems. Example:

bashCopy code$ df -h
# Displays disk space in a human-readable format

6.3 du (Disk Usage)

Description: Estimates file space usage. Example:

bashCopy code$ du -sh /var
# Shows the disk usage of the /var directory

6.4 free (Display Memory Usage)

Description: Displays the total amount of free and used physical and swap memory. Example:

bashCopy code$ free -h
# Displays memory usage in a human-readable format

6.5 lscpu (List CPU Information)

Description: Displays information about the CPU architecture. Example:

bashCopy code$ lscpu
# Shows detailed CPU information

6.6 lshw (List Hardware)

Description: Lists detailed information about all hardware. Example:

bashCopy code$ sudo lshw
# Outputs detailed hardware configuration

6.7 lsblk (List Block Devices)

Description: Lists information about all available block devices. Example:

bashCopy code$ lsblk
# Displays block device information

7. User and Group Management

7.1 passwd (Change User Password)

Description: Changes the password for a user account. Example:

bashCopy code$ passwd
# Changes the current user's password

7.2 groupadd (Add Group)

Description: Creates a new group. Example:

bashCopy code$ sudo groupadd newgroup
# Creates a new group named 'newgroup'

7.3 groupdel (Delete Group)

Description: Deletes a group. Example:

bashCopy code$ sudo groupdel oldgroup
# Deletes the group 'oldgroup'

7.4 userdel (Delete User)

Description: Deletes a user account. Example:

bashCopy code$ sudo userdel olduser
# Deletes the user 'olduser'

7.5 groups (Display Group Memberships)

Description: Shows the groups a user is a member of. Example:

bashCopy code$ groups username
# Displays the groups 'username' is part of

7.6 usermod (Modify User Account)

Description: Modifies a user account. Example:

bashCopy code$ sudo usermod -aG sudo newuser
# Adds 'newuser' to the sudo group

7.7 id (User Identity)

Description: Displays user identity information. Example:

bashCopy code$ id username
# Shows user ID and group IDs for 'username'

That's all, folks! ๐ŸŒŸ Go forth and conquer those Linux commands. Catch you on the flip side! ๐Ÿ’ฅ

0
Subscribe to my newsletter

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

Written by

Tenith
Tenith