Skip to content

Advanced Linux Commands

This guide covers advanced usage of common Linux commands with practical examples.

ls - List Directory Contents

ls command icon

Explore the Linux ls command and its practical applications for managing files and directories. Learn how to utilize various options to retrieve detailed file information and navigate directory structures effectively.

Demos

1. Basic Usage List files and folders in the current directory.

ls
Output:
file1.txt  file2.txt  folder1  folder2

2. Long Format Listing Provides detailed information including permissions, owner, size, and modification date.

ls -l
Output:
total 8
-rw-r--r-- 1 labex labex 0 Apr 12 12:34 file1.txt
-rw-r--r-- 1 labex labex 0 Apr 12 12:34 file2.txt
drwxr-xr-x 2 labex labex 4096 Apr 12 12:34 folder1
drwxr-xr-x 2 labex labex 4096 Apr 12 12:34 folder2


cd - Change Directory

cd command icon

Explore the Linux cd command, learn how to navigate the file system, and understand the difference between relative and absolute paths.

Demos

1. Absolute Path Navigate to a specific directory using its full path.

cd /home/labex/project
Output:
labex@ubuntu:/home/labex/project$

2. Parent Directory Navigate up one level to the parent directory.

cd ..
Output:
labex@ubuntu:/home/labex$


pwd - Print Working Directory

pwd command icon

Explore the Linux pwd command, its purpose, and practical examples of using it with other commands to manage files and directories.

Demos

1. Basic Usage Display the current working directory.

pwd
Output:
/home/labex/project

2. In Subdirectory Show path when inside a subdirectory.

pwd
Output:
/home/labex/project/subdirectory


cat - Concatenate Files

cat command icon

Connects and prints the content of files to standard output.

Demos

1. Display File Content View the contents of a text file.

cat filename.txt
Output:
This is the content of the file.

2. Create File Create a new file and add content (press Ctrl+D to save).

cat > newfile.txt


echo - Display Line of Text

echo command icon

Displays a line of text or variable value to standard output.

Demos

1. Print Text Print a simple string to the terminal.

echo "Hello World"
Output:
Hello World


touch - Change File Timestamps

touch command icon

Update the access and modification times of a file, or create an empty file if it doesn't exist.

Demos

1. Create Empty File Create a new empty file.

touch newfile.txt


mkdir - Make Directories

mkdir command icon

Create new directories.

Demos

1. Create Directory Create a single directory.

mkdir myfolder

2. Create Nested Directories Create a directory structure with parent directories.

mkdir -p parent/child/grandchild


rm - Remove Files or Directories

rm command icon

Remove files or directories. Use with caution.

Demos

1. Remove File Delete a specific file.

rm file.txt

2. Remove Directory Recursive Delete a directory and its contents.

rm -rf directory_name


rmdir - Remove Empty Directories

rmdir command icon

Remove empty directories.

Demos

1. Remove Directory Delete an empty directory.

rmdir empty_folder


cp - Copy Files

cp command icon

Copy files and directories.

Demos

1. Copy File Copy a file to a new location.

cp source.txt destination.txt

2. Copy Directory Copy a directory recursively.

cp -r source_dir destination_dir


mv - Move or Rename Files

mv command icon

Move or rename files and directories.

Demos

1. Rename File Rename a file in place.

mv oldname.txt newname.txt

2. Move File Move a file to a different directory.

mv file.txt /path/to/directory/


head - Output First Part of File

head command icon

Output the first part of files.

Demos

1. First 10 Lines Display the first 10 lines (default).

head file.txt

2. First N Lines Display the first 5 lines.

head -n 5 file.txt


tail - Output Last Part of File

tail command icon

Output the last part of files.

Demos

1. Last 10 Lines Display the last 10 lines (default).

tail file.txt

2. Follow File Output appended data as the file grows (useful for logs).

tail -f access.log


wc - Word, Line, Character Count

wc command icon

Print newline, word, and byte counts for each file.

Demos

1. Count Lines Count the number of lines in a file.

wc -l file.txt
Output:
125 file.txt


grep - Print Lines Matching a Pattern

grep command icon

Search for specific patterns within files.

Demos

1. Basic Search Search for a string in a file.

grep "error" log.txt

2. Case Insensitive Search without regarding case.

grep -i "error" log.txt


sort - Sort Lines of Text Files

sort command icon

Sort lines of text files.

Demos

1. Alphabetical Sort Sort lines alphabetically.

sort names.txt

2. Numeric Sort Sort lines numerically.

sort -n numbers.txt


uniq - Report or Omit Repeated Lines

uniq command icon

Filter adjacent matching lines.

Demos

1. Remove Duplicates Remove consecutive duplicate lines.

sort file.txt | uniq

2. Count Occurrences Count the number of occurrences of each line.

sort file.txt | uniq -c


rev - Reverse Lines

rev command icon

Reverse lines characterwise.

Demos

1. Reverse String Reverse the characters in each line.

echo "Hello" | rev
Output:
olleH


base64 - Base64 Encode/Decode

base64 command icon

Base64 encode or decode data.

Demos

1. Encode Encode a string.

echo "Linux" | base64
Output:
TGludXgK

2. Decode Decode a base64 string.

echo "TGludXgK" | base64 -d
Output:
Linux


strings - Print Printable Characters

strings command icon

Print the sequences of printable characters in files.

Demos

1. Extract Strings Find readable strings in a binary file.

strings /bin/ls | head


xxd - Make a Hex Dump

xxd command icon

Make a hexdump or do the reverse.

Demos

1. Hex Dump Create a hex dump of a file.

xxd file.txt


file - Determine File Type

file command icon

Determine the type of a file.

Demos

1. Check File Type Identify the type of data in a file.

file image.png
Output:
image.png: PNG image data, 800 x 600, 8-bit/color RGBA, non-interlaced


stat - Display File Status

stat command icon

Display detailed file or file system status.

Demos

1. File Info Show detailed statistics about a file.

stat file.txt


find - Search for Files

find command icon

Search for files in a directory hierarchy.

Demos

1. Find by Name Find files with a specific name.

find . -name "*.txt"

2. Find by Size Find files larger than 10MB.

find /var/log -size +10M


tree - List Contents in Tree

tree command icon

List directory contents in a tree-like format.

Demos

1. Show Tree Display directory structure.

tree


du - Disk Usage

du command icon

Estimate file space usage.

Demos

1. Directory Size Show size of current directory in human-readable format.

du -sh .


which - Locate a Command

which command icon

Locate a command.

Demos

1. Find Executable Show the full path of a shell command.

which python3
Output:
/usr/bin/python3


whereis - Locate Binary, Source, and Manual

whereis command icon

Locate the binary, source, and manual page files for a command.

Demos

1. Locate Command Info Find binary and man pages.

whereis ls


type - Describe a Command

type command icon

Display information about command type.

Demos

1. Check Command See if a command is a built-in, alias, or executable.

type cd
Output:
cd is a shell builtin


display - Display Image (ImageMagick)

display command icon

Display an image or image sequence.

Demos

1. Open Image Open an image file in a GUI window.

display image.png


evince - Document Viewer

evince command icon

View PDF, PostScript, chemical, DJVU, DVI and TIFF documents.

Demos

1. Open PDF Open a PDF file.

evince document.pdf


uname - Print System Information

uname command icon

Print system information.

Demos

1. Kernel Info Print all system information.

uname -a


hostname - Show/Set System Name

hostname command icon

Show or set the system's host name.

Demos

1. Show Hostname Display the current hostname.

hostname


id - Print User and Group IDs

id command icon

Print user and group IDs.

Demos

1. User Info Show user ID, group ID, and groups.

id


uptime - Tell How Long System Has Been Running

uptime command icon

Tell how long the system has been running.

Demos

1. Show Uptime Display system uptime and load average.

uptime


date - Print or Set System Date and Time

date command icon

Print or set the system date and time.

Demos

1. Show Date Display current date and time.

date


cal - Display a Calendar

cal command icon

Display a calendar.

Demos

1. Current Month Show calendar for current month.

cal


df - Report File System Disk Space Usage

df command icon

Report file system disk space usage.

Demos

1. Disk Space Show disk usage in human-readable format.

df -h


free - Display Amount of Free and Used Memory

free command icon

Display amount of free and used memory in the system.

Demos

1. Memory Usage Show memory usage in standard format.

free -h


ps - Report a Snapshot of the Current Processes

ps command icon

Report a snapshot of the current processes.

Demos

1. Active Processes Show all running processes.

ps aux


env - Run a Program in a Modified Environment

env command icon

Run a program in a modified environment or print environment variables.

Demos

1. Print Env Display all environment variables.

env


neofetch - System Information Tool

neofetch command icon

A command-line system information tool written in bash 3.2+.

Demos

1. Show Info Display system info with logo.

neofetch


dmesg - Print or Control the Kernel Ring Buffer

dmesg command icon

Print or control the kernel ring buffer.

Demos

1. Kernel Logs Show kernel messages.

dmesg | tail


lsblk - List Block Devices

lsblk command icon

List information about all available or the specified block devices.

Demos

1. List Devices Show all block devices.

lsblk


tty - Print File Name of Terminal Connected to Standard Input

tty command icon

Print the file name of the terminal connected to standard input.

Demos

1. Check TTY Display current terminal name.

tty


w - Show Who Is Logged On and What They Are Doing

w command icon

Show who is logged on and what they are doing.

Demos

1. User Activity Detailed info about currently logged-in users.

w


who - Show Who Is Logged On

who command icon

Show who is logged on.

Demos

1. Users List currently logged-in users.

who


arch - Print Machine Architecture

arch command icon

Print machine architecture.

Demos

1. Architecture Show system architecture (e.g., x86_64).

arch


nproc - Print Number of Processing Units

nproc command icon

Print the number of processing units available.

Demos

1. CPU Count Show number of CPU cores.

nproc


ping - Send ICMP ECHO_REQUEST to Network Hosts

ping command icon

Send ICMP ECHO_REQUEST to network hosts.

Demos

1. Ping Host Check connectivity to a host.

ping google.com

2. Limit Count Send only 4 packets.

ping -c 4 google.com


ifconfig - Configure a Network Interface

ifconfig command icon

Configure a network interface.

Demos

1. Show Interfaces Display all network interfaces.

ifconfig


netstat - Print Network Connections

netstat command icon

Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.

Demos

1. Listening Ports Show all listening ports.

netstat -tuln


ss - Another Utility to Investigate Sockets

ss command icon

Another utility to investigate sockets.

Demos

1. All Sockets Display all TCP/UDP sockets.

ss -tuln


nslookup - Query Internet Name Servers

nslookup command icon

Query Internet name servers interactively.

Demos

1. Lookup Domain Find IP address of a domain.

nslookup google.com


traceroute - Print the Route Packets Trace to Network Host

traceroute command icon

Print the route packets trace to network host.

Demos

1. Trace Route Show path to a host.

traceroute google.com


dig - DNS Lookup Utility

dig command icon

DNS lookup utility.

Demos

1. DNS Query Perform a DNS lookup.

dig google.com


clear - Clear the Terminal Screen

clear command icon

Clear the terminal screen.

Demos

1. Clear Screen Clear the text from the terminal window.

clear


history - Display Command History

history command icon

Display or manipulate the history list.

Demos

1. Show History List previously executed commands.

history


man - Interface to the System Reference Manuals

man command icon

Interface to the system reference manuals.

Demos

1. Manual Page Read the manual for a command.

man ls


alias - Define or Display Aliases

alias command icon

Define or display aliases.

Demos

1. Create Alias Create a shortcut for a command.

alias ll='ls -l'


expr - Evaluate Expressions

expr command icon

Evaluate expressions.

Demos

1. Math Perform integer arithmetic.

expr 10 + 20
Output:
30


seq - Print a Sequence of Numbers

seq command icon

Print a sequence of numbers.

Demos

1. Sequence Print numbers from 1 to 5.

seq 1 5
Output:
1
2
3
4
5


factor - Print Prime Factors

factor command icon

Print prime factors.

Demos

1. Factorize Find prime factors of a number.

factor 100
Output:
100: 2 2 5 5


sleep - Delay for a Specified Amount of Time

sleep command icon

Delay for a specified amount of time.

Demos

1. Pause Pause execution for 5 seconds.

sleep 5


bc - An Arbitrary Precision Calculator Language

bc command icon

An arbitrary precision calculator language.

Demos

1. Calculation Perform calculation.

echo "10 + 20" | bc
Output:
30


exit - Cause the Shell to Exit

exit command icon

Cause the shell to exit.

Demos

1. Close Shell Exit the current terminal session.

exit


logout - Exit a Login Shell

logout command icon

Exit a login shell.

Demos

1. Logout Log out of the current session.

logout


poweroff - Power Off the System

poweroff command icon

Power off the system.

Demos

1. Shutdown Turn off the computer immediately.

poweroff


reboot - Reboot the System

reboot command icon

Reboot the system.

Demos

1. Restart Restart the computer immediately.

reboot


halt - Stop the System

halt command icon

Stop the system.

Demos

1. Stop Halt the system immediately.

halt


reset - Reset Terminal

reset command icon

Reset terminal.

Demos

1. Reset Reset terminal settings.

reset


cowsay - Configurable Speaking Cow

cowsay command icon

Configurable speaking cow.

Demos

1. Say Hello Make the cow say something.

cowsay "Hello Linux"
Output:
 _____________
< Hello Linux >
 -------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||


fortune - Print a Random, Hopefully Interesting, Adage

fortune command icon

Print a random, hopefully interesting, adage.

Demos

1. Tell Fortune Display a random quote.

fortune


cmatrix - Terminal Matrix Rain

cmatrix command icon

Terminal Matrix rain.

Demos

1. Start Matrix Show the scrolling Matrix effect.

cmatrix


sl - Steam Locomotive

sl command icon

Steam Locomotive.

Demos

1. Run Train Show an animation of a steam locomotive (often run by typo when meaning ls).

sl


figlet - Display Large Characters

figlet command icon

Display large characters.

Demos

1. Banner Create a text banner.

figlet Linux
Output:
 _     _
| |   (_)_ __  _   ___  __
| |   | | '_ \| | | \ \/ /
| |___| | | | | |_| |>  <
|_____|_|_| |_|\__,_/_/\_\