The Essential Linux Commands Everyone Should Know

The sudo command allows authorized users to perform tasks that require administrative rights. Prefixing a command with sudo grants temporary elevated permissions.

Mastering the Linux command line unlocks powerful capabilities for system navigation, file management, software installation, and system monitoring. Whether you're a beginner or an experienced user, understanding these essential commands is crucial. Here’s a structured guide to the fundamental Linux commands every user should know.

System Privileges and Permissions

sudo – Execute Commands with Superuser Privileges

The sudo command allows authorized users to perform tasks that require administrative rights. Prefixing a command with sudo grants temporary elevated permissions.

Example:

bash

CopyEdit

sudo apt update

To check if your user has sudo privileges:

bash

CopyEdit

groups <username>

Navigating the File System

pwd – Print Working Directory

Displays the full path of the current directory.

bash

CopyEdit

pwd

ls – List Directory Contents

Lists files and directories within the current directory.

Examples:

Basic listing:
bash
CopyEdit
ls

Detailed view with hidden files:
bash
CopyEdit
ls -lha

List specific file types (e.g., Python files):
bash
CopyEdit
ls *.py

cd – Change Directory

Navigates between directories.

Examples:

bash

CopyEdit

cd Downloads      # Move to a subdirectory

cd -              # Return to the previous directory

cd ~              # Go to the home directory

Viewing and Editing Files

cat – Concatenate and Display File Contents

Outputs the contents of a file to the terminal.

Examples:

bash

CopyEdit

cat filename.txt          # Display file

cat -n filename.txt       # Display with line numbers

less – View File Contents One Page at a Time

Allows scrolling through file contents.

bash

CopyEdit

less /var/log/syslog

grep – Search Text Using Patterns

Searches for specific patterns within files.

bash

CopyEdit

lscpu | grep "MHz"

nano – Simple Text Editor

A user-friendly command-line text editor.

Examples:

bash

CopyEdit

nano filename.txt         # Open or create file

  • Save: CTRL + O, then Enter
  • Exit: CTRL + X

File and Directory Management

mv – Move or Rename Files and Directories

Moves or renames files and directories.

Examples:

bash

CopyEdit

mv file.txt /destination/       # Move

mv oldname.txt newname.txt      # Rename

cp – Copy Files and Directories

Copies files or directories.

Examples:

bash

CopyEdit

cp file.txt /destination/       # Copy file

cp -r dir1/ dir2/               # Copy directory recursively

rm – Remove Files and Directories

Deletes files or directories.

Examples:

bash

CopyEdit

rm file.txt                     # Remove file

rm -r directory/                # Remove directory

mkdir – Create Directories

Creates new directories.

bash

CopyEdit

mkdir new_directory

Software Installation and Updates

apt – Package Management for Debian/Ubuntu Systems

Manages software packages.

Examples:

bash

CopyEdit

sudo apt update                # Update package lists

sudo apt install package_name # Install package

sudo apt upgrade               # Upgrade installed packages

Monitoring System Resources

htop – Interactive Process Viewer

Displays real-time system metrics and processes.

bash

CopyEdit

htop

free – Display Memory Usage

Shows available and used memory.

bash

CopyEdit

free -m

dmesg – Kernel Ring Buffer Messages

Displays system messages, useful for debugging hardware issues.

bash

CopyEdit

sudo dmesg

Network Connectivity

ping – Test Network Connectivity

Checks the reachability of a host.

Examples:

bash

CopyEdit

ping google.com

ping 8.8.8.8

hostname -I – Display IP Addresses

Shows the IP addresses assigned to the machine.

bash

CopyEdit

hostname -I

curl – Transfer Data from or to a Server

Downloads or uploads data using various protocols.

bash

CopyEdit

curl http://example.com/file.txt -o file.txt

Command History and Shortcuts

history – Show Command History

Lists previously executed commands.

bash

CopyEdit

history

Re-execute Commands

Runs a command from history using its number.

bash

CopyEdit

!117

Search Command History

Finds commands matching a pattern.

bash

CopyEdit

history | grep "apt"

Conclusion

Familiarity with these Linux commands enhances efficiency and control over your Linux environment. Regular use and practice will make these tools second nature, empowering you to leverage the full potential of the Linux command line.

Support.Com Can Help!

If you’re still having trouble, consider reaching out to Support.Com for a personalized solution to all technical support issues.