Mastering the Basics: Essential Linux Commands for Beginners

Ayiluri UshasriAyiluri Ushasri
11 min read

Linux

Knowing how to interact with Linux via the command line unlocks powerful capabilities and deeper control over your system.

Linux is the backbone of many modern systems, from servers and desktops to mobile devices and IoT.

In technical terms, Linux is the unseen engine behind so much of today's tech. Whether you're deploying a website, configuring a firewall, or tinkering with a Raspberry Pi, knowing the command line is like having admin-level superpowers.


pwd - Print Working Directory

You use it on systems like Linux or macOS to check where you are in the file structure. It shows the full path to your current folder when working in the terminal.

pwd

Example

Let’s say you're navigating through folders in a terminal:

cd /home/user/Documents/projects
pwd

output:

/home/user/Documents/projects

This tells you that you're currently inside the projects folder, which is located inside Documents, underuser , within the home directory of your system.


ls - List Directory Contents

ls stands for “list” and is used to display the contents of a directory.
It shows you all the files and folders in your current location (or in a specified location).

ls [options] [directory]

options: Modify how the output is displayed.

directory: Optional, specify a folder you want to look inside. If you skip this, it defaults to your current directory.

Example:

ls

Lists all files and folders in your current directory

  • List contents of another directory:

      ls /home/user/Documents
    

    Shows contents of the Documents folder even if you're not currently in it.

  • Show details (permissions, size, date, etc.)

      ls -l      # Detailed listing
      ls -a      # Includes hidden files
    

    Commonly Used Options:

OptionDescriptionExample
-lLong listing format (permissions, size, etc.)ls -l
-aShow all files including hidden ones (. prefix)ls -a
-hHuman-readable sizes (use with -l)ls -lh
-RRecursive – lists all subdirectories tools -R
-tSort by modification time (newest first)ls -lt
-rReverse order while sortingls -lr
-iShow inode number of filesls -i

cd - Change Directory

Change Directory is used to move from one folder (directory) to another in the terminal.

cd /home/user/Documents
cd ..      # Go up one level
cd ~       # Go to home directory
cd -       # go to previous directory

cd : Takes you directly to the Documents folder using the absolute path.

cd .. : Takes you up to the parent directory.

cd ~: Shortcut for going to your user's home directory (e.g., /home/user).

cd - : Switches you back to the last directory you were in.


Working with Files and Directories

touch - Create Empty Files

The touch command is primarily used to create empty files. You can also use it to update the access and modification timestamps of existing files without changing their content.

touch notes.txt

Creates notes.txt file if it doesn't exist. If it does, it updates its timestamp.

Create multiple files at once

touch file1.txt file2.txt file3.txt

Update timestamp of an existing file

touch existingfile.txt

mkdir - Make New Directory

It's a command you use in Linux or macOS terminals to create a new folder.

Just like right-clicking and choosing “New Folder” in a graphical interface, but faster.

mkdir foldername

That creates a folder named foldername in your current location.

Examples:

mkdir blog    #creates single folder
mkdir blog drafts images   #creates multiple folders at once
mkdir -p blog/assets/images   #creates nested folders

The -p option creates all levels at once—even if they don’t exist yet.


rm - Removes Files/Directories

It’s used to delete files and directories from the terminal. Unlike moving to the trash/recycle bin in graphical interfaces, rm permanently deletes the file. No "undo" unless you’ve got a backup or recovery system.

rm notes.txt  #Delete a single file
rm file1.txt file2.txt file3.txt  #Delete multiple files
rm -r foldername    #Delete a folder and its contents (recursively)
rm -f file.txt     #Force delete without prompts
rm -rf foldername   #Combine fore and recursive

NOTE: Avoid using rm -rf /⁣; this can delete your entire system.


cp - Copy Files/Directories

It's used to duplicate files or folders from one place to another in the terminal.

cp report.txt /home/user/Documents  #copy a file to another folder

Copies report.txt into the Documents folder.

cp report.txt final_report.txt  #Rename while Copying
cp file1.txt file2.txt /home/user/backup/  #Copying multiple files
cp -r project/ /home/user/archive/  #copy a direcotry

The -r option (recursive) copies everything inside project, including subfolders.


mv - Move or Rename

It’s used to relocate files and directories or rename them from the command line.

mv notes.txt /home/user/Documents/  #Moves a file to another folder
mv notes.txt todo.txt     #Rename a file
mv images/ /var/www/assets/    #Move a Directory

Viewing and Editing Files

cat - View File Content

cat stands for concatenate and display files.
It reads the contents of files and outputs them to the terminal.

  • Display file content

  • Combine multiple files into one

Create new files from the command line.

cat notes.txt  #Display contents of a file
cat intro.txt body.txt conclusion.txt > article.txt    #Combine files into one
cat > newfile.txt    #creates a new file
cat >> existing.txt   #Appending content to a exsisting file

less

command allows you to view text files page by page, rather than dumping the whole thing into your terminal at once.

less filename

vi - Text Editor

It runs entirely inside the terminal and allows you to view, edit, and write text files—like config files, code, or notes.

vi filename.txt
  • Opens filename.txt for editing.

  • If the file doesn’t exist, it will create one for you.

vi works in two main modes:

ModePurposeHow to Enter
NormalNavigate and issue commandsDefault mode when you open vi
InsertType/edit textPress i, a, or o from Normal mode
CommandSave, quit, searchPress : from Normal mode

vi notes.txt

  1. Press i to enter Insert mode.

  2. Type your text.

  3. Press Esc to exit Insert mode.

Type :wq and hit Enter to save and quit.


System Information

uname - System info

uname stands for "Unix name" and is used to display system information.
It can tell you about the operating system, kernel version, machine hardware, and more.

uname [options]

Without any options, it simply shows the kernel name (e.g., Linux, Darwin for macOS).

Common opotions:

OptionWhat It Shows
-aAll system info
-sKernel name
-nNetwork hostname
-rKernel release version
-vKernel version
-mMachine hardware name (architecture)
-pProcessor type (may show 'unknown')
-iHardware platform
-oOperating system name

top - Live System Monitoring

The top command is a powerful system monitoring tool used in Linux. It provides a real-time, dynamic view of your system’s performance and resource usage.

top

df - Disk Space Usage

It provides a real-time, dynamic view of your system’s performance and resource usage.

df            # Shows disk usage in 1K blocks (default)
df -h         # Human-readable format (e.g., MB, GB)
df -T         # Includes filesystem type (e.g., ext4, xfs)
df -i         # Shows inode usage instead of block usage
df /home      # Shows usage for the filesystem containing /home

Sample Output (df -h)

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        50G   20G   28G  42% /
tmpfs           2.0G     0  2.0G   0% /dev/shm

When you run df, it shows:

  • Filesystem: The name of the disk or partition

  • Size: Total space on the filesystem

  • Used: Space already used

  • Available: Free space left

  • Use%: Percentage of space used

Mounted on: Where the filesystem is attached in the directory tree.


free - Memory Usage

It is for checking system memory usage. It gives you a snapshot of how much RAM and swap space is being used, free, and available.

free            # Default output in kilobytes
free -h         # Human-readable format (e.g., MB, GB)
free -m         # Output in megabytes
free -g         # Output in gigabytes
free -s 5       # Refresh every 5 seconds
free -t         # Adds a total row

Sample Output (free -h):

              total        used        free      shared  buff/cache   available
Mem:           7.7G        2.5G        1.5G        479M        3.7G        4.4G
Swap:            0B          0B          0B

When you run free, you'll see two main sections:

  • Mem: Physical RAM stats

  • Swap: Virtual memory stats


User and Permission Management

whoami - Shows current user

It displays the effective username of the current user session in Linux.

whoami

chmod - Change file Permissions

The chmod command is used to change file and directory permissions. It stands for change mode, referring to the access mode of files.

Each file has three types of permissions for three categories of users:

  • User (u): The file owner

  • Group (g): Users in the same group

  • Others (o): Everyone else

Permissions:

  • r: Read

  • w: Write

  • x: Execute

Common Syntax

chmod [options] mode file

Modes can be symbolic or numeric:

Symbolic Mode

chmod u+x script.sh     # Add execute permission for user
chmod g-w file.txt      # Remove write permission for group
chmod o=r file.txt      # Set read-only for others
chmod a+rw file.txt     # Add read/write for all

Numeric Mode

Each permission has a value:

  • r = 4

  • w⁣ = 2

  • x = 1

Combine them:

  • chmod 755 file.shrwxr-xr-x

  • chmod 644 file.txtrw-r--r--

  • chmod 700 secret.txtrwx------

Recursive Changes

To apply permissions to all files and subdirectories:

chmod -R 755 my_folder/

Examples

CommandMeaning
chmod +x run.shMake script executable
chmod 600 config.cfgOnly owner can read/write
chmod 777 public.txtEveryone can read/write/execute (risky!)

chown - Change Ownership

The chown command for "change owner", and it lets you assign a new user and/or group to a file.

Basic Syntax

chown [OPTIONS] USER[:GROUP] FILE
  • USER: New owner of the file

  • GROUP: (Optional) New group

  • FILE: Target file or directory

Examples

CommandWhat It Does
chown alice file.txtChanges owner to alice
chown alice:devs file.txtChanges owner to alice and group to devs
chown :devs file.txtChanges only the group to devs

Common Options

OptionDescription
-RRecursive (includes subdirectories and files)
-vVerbose output (shows changes)
-cReports only when a change is made

Sample Use Case

chown -R bob:staff /var/www/

This command makes bob the owner and staff the group for everything inside /var/www/.


Package Management (Red-Hat based systems)

Red Hat-based Linux systems use a combination of RPM, YUM, and DNF for package management, each serving different roles depending on the system version and user needs.

Package Management Tools in Red Hat-based Systems

FeatureRPMYUMDNF
PurposeLow-level package managerHigh-level package managerModern high-level package manager
Dependency HandlingNo automatic resolutionResolves dependenciesImproved dependency resolution
Introduced InRHEL (original tool)RHEL 5–7RHEL 8+
Command Examplerpm -i nginx.rpmyum install nginxdnf install nginx
Upgrade Packagesrpm -U nginx.rpmyum updatednf upgrade
Remove Packagesrpm -e nginxyum remove nginxdnf remove nginx
List Packagesrpm -qayum list installeddnf list installed
Search Packagesrpm -q nginxyum search nginxdnf search nginx
Repo ManagementManual via .repo filesUses /etc/yum.repos.d/Same as YUM
Speed & PerformanceFast but limitedSlower, less efficientFaster, better dependency resolution
Plugin SupportNoYesYes (more robust)
Recommended ForManual package handlingLegacy systemsModern Red Hat systems


Networking Commands

ping - Check Connectivity

The ping command is a classic and essential tool for network troubleshooting. It checks whether a device (host) is reachable across an IP network and measures how long it takes for messages to travel back and forth.

Example

ping google.com        # Ping a website
ping 192.168.1.1       # Ping a local router
ping -c 4 example.com  # Send only 4 packets (Linux/macOS)
ping -n 4 example.com  # Send 4 packets (Windows)

Output:

PING google.com (142.250.72.14): 56 data bytes
64 bytes from 142.250.72.14: icmp_seq=0 ttl=115 time=20.3 ms
64 bytes from 142.250.72.14: icmp_seq=1 ttl=115 time=19.8 ms
--- google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms

Use Cases

  • Check if a server is online.

  • Diagnose slow or dropped connections.

  • Measure latency for gaming or video calls.

  • Verify DNS resolution (ping domain vs IP).

  • Test local network devices (router, printer).


ifconfig – Legacy Tool

  • Part of the net-tools package (often not installed by default on newer distros).

  • Displays IP addresses, MAC addresses, and interface status.

  • Can also be used to assign IPs, enable/disable interfaces, and change MAC addresses.

Example:

ifconfig

(ip a) – Modern Replacement

  • Part of the iproute2 suite.

  • More powerful and flexible than ifconfig.

  • Displays IPv4 and IPv6 addresses, interface states, and CIDR notation.

Example:

ip a

0
Subscribe to my newsletter

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

Written by

Ayiluri Ushasri
Ayiluri Ushasri