Advanced Linux Commands
This guide covers advanced usage of common Linux commands with practical examples.
ls - List Directory Contents
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.
Output:2. Long Format Listing Provides detailed information including permissions, owner, size, and modification date.
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
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.
Output:2. Parent Directory Navigate up one level to the parent directory.
Output:pwd - Print Working Directory
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.
Output:2. In Subdirectory Show path when inside a subdirectory.
Output:cat - Concatenate Files
Connects and prints the content of files to standard output.
Demos
1. Display File Content View the contents of a text file.
Output:2. Create File Create a new file and add content (press Ctrl+D to save).
echo - Display Line of Text
Displays a line of text or variable value to standard output.
Demos
1. Print Text Print a simple string to the terminal.
Output:touch - Change File Timestamps
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.
mkdir - Make Directories
Create new directories.
Demos
1. Create Directory Create a single directory.
2. Create Nested Directories Create a directory structure with parent directories.
rm - Remove Files or Directories
Remove files or directories. Use with caution.
Demos
1. Remove File Delete a specific file.
2. Remove Directory Recursive Delete a directory and its contents.
rmdir - Remove Empty Directories
Remove empty directories.
Demos
1. Remove Directory Delete an empty directory.
cp - Copy Files
Copy files and directories.
Demos
1. Copy File Copy a file to a new location.
2. Copy Directory Copy a directory recursively.
mv - Move or Rename Files
Move or rename files and directories.
Demos
1. Rename File Rename a file in place.
2. Move File Move a file to a different directory.
head - Output First Part of File
Output the first part of files.
Demos
1. First 10 Lines Display the first 10 lines (default).
2. First N Lines Display the first 5 lines.
tail - Output Last Part of File
Output the last part of files.
Demos
1. Last 10 Lines Display the last 10 lines (default).
2. Follow File Output appended data as the file grows (useful for logs).
wc - Word, Line, Character Count
Print newline, word, and byte counts for each file.
Demos
1. Count Lines Count the number of lines in a file.
Output:grep - Print Lines Matching a Pattern
Search for specific patterns within files.
Demos
1. Basic Search Search for a string in a file.
2. Case Insensitive Search without regarding case.
sort - Sort Lines of Text Files
Sort lines of text files.
Demos
1. Alphabetical Sort Sort lines alphabetically.
2. Numeric Sort Sort lines numerically.
uniq - Report or Omit Repeated Lines
Filter adjacent matching lines.
Demos
1. Remove Duplicates Remove consecutive duplicate lines.
2. Count Occurrences Count the number of occurrences of each line.
rev - Reverse Lines
Reverse lines characterwise.
Demos
1. Reverse String Reverse the characters in each line.
Output:base64 - Base64 Encode/Decode
Base64 encode or decode data.
Demos
1. Encode Encode a string.
Output:2. Decode Decode a base64 string.
Output:strings - Print Printable Characters
Print the sequences of printable characters in files.
Demos
1. Extract Strings Find readable strings in a binary file.
xxd - Make a Hex Dump
Make a hexdump or do the reverse.
Demos
1. Hex Dump Create a hex dump of a file.
file - Determine File Type
Determine the type of a file.
Demos
1. Check File Type Identify the type of data in a file.
Output:stat - Display File Status
Display detailed file or file system status.
Demos
1. File Info Show detailed statistics about a file.
find - Search for Files
Search for files in a directory hierarchy.
Demos
1. Find by Name Find files with a specific name.
2. Find by Size Find files larger than 10MB.
tree - List Contents in Tree
List directory contents in a tree-like format.
Demos
1. Show Tree Display directory structure.
du - Disk Usage
Estimate file space usage.
Demos
1. Directory Size Show size of current directory in human-readable format.
which - Locate a Command
Locate a command.
Demos
1. Find Executable Show the full path of a shell command.
Output:whereis - Locate Binary, Source, and Manual
Locate the binary, source, and manual page files for a command.
Demos
1. Locate Command Info Find binary and man pages.
type - Describe a Command
Display information about command type.
Demos
1. Check Command See if a command is a built-in, alias, or executable.
Output:display - Display Image (ImageMagick)
Display an image or image sequence.
Demos
1. Open Image Open an image file in a GUI window.
evince - Document Viewer
View PDF, PostScript, chemical, DJVU, DVI and TIFF documents.
Demos
1. Open PDF Open a PDF file.
uname - Print System Information
Print system information.
Demos
1. Kernel Info Print all system information.
hostname - Show/Set System Name
Show or set the system's host name.
Demos
1. Show Hostname Display the current hostname.
id - Print User and Group IDs
Print user and group IDs.
Demos
1. User Info Show user ID, group ID, and groups.
uptime - Tell How Long System Has Been Running
Tell how long the system has been running.
Demos
1. Show Uptime Display system uptime and load average.
date - Print or Set System Date and Time
Print or set the system date and time.
Demos
1. Show Date Display current date and time.
cal - Display a Calendar
Display a calendar.
Demos
1. Current Month Show calendar for current month.
df - Report File System Disk Space Usage
Report file system disk space usage.
Demos
1. Disk Space Show disk usage in human-readable format.
free - Display Amount of Free and Used Memory
Display amount of free and used memory in the system.
Demos
1. Memory Usage Show memory usage in standard format.
ps - Report a Snapshot of the Current Processes
Report a snapshot of the current processes.
Demos
1. Active Processes Show all running processes.
env - Run a Program in a Modified Environment
Run a program in a modified environment or print environment variables.
Demos
1. Print Env Display all environment variables.
neofetch - System Information Tool
A command-line system information tool written in bash 3.2+.
Demos
1. Show Info Display system info with logo.
dmesg - Print or Control the Kernel Ring Buffer
Print or control the kernel ring buffer.
Demos
1. Kernel Logs Show kernel messages.
lsblk - List Block Devices
List information about all available or the specified block devices.
Demos
1. List Devices Show all block devices.
tty - Print File Name of Terminal Connected to Standard Input
Print the file name of the terminal connected to standard input.
Demos
1. Check TTY Display current terminal name.
w - Show Who Is Logged On and What They Are Doing
Show who is logged on and what they are doing.
Demos
1. User Activity Detailed info about currently logged-in users.
who - Show Who Is Logged On
Show who is logged on.
Demos
1. Users List currently logged-in users.
arch - Print Machine Architecture
Print machine architecture.
Demos
1. Architecture Show system architecture (e.g., x86_64).
nproc - Print Number of Processing Units
Print the number of processing units available.
Demos
1. CPU Count Show number of CPU cores.
ping - Send ICMP ECHO_REQUEST to Network Hosts
Send ICMP ECHO_REQUEST to network hosts.
Demos
1. Ping Host Check connectivity to a host.
2. Limit Count Send only 4 packets.
ifconfig - Configure a Network Interface
Configure a network interface.
Demos
1. Show Interfaces Display all network interfaces.
netstat - Print Network Connections
Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
Demos
1. Listening Ports Show all listening ports.
ss - Another Utility to Investigate Sockets
Another utility to investigate sockets.
Demos
1. All Sockets Display all TCP/UDP sockets.
nslookup - Query Internet Name Servers
Query Internet name servers interactively.
Demos
1. Lookup Domain Find IP address of a domain.
traceroute - Print the Route Packets Trace to Network Host
Print the route packets trace to network host.
Demos
1. Trace Route Show path to a host.
dig - DNS Lookup Utility
DNS lookup utility.
Demos
1. DNS Query Perform a DNS lookup.
clear - Clear the Terminal Screen
Clear the terminal screen.
Demos
1. Clear Screen Clear the text from the terminal window.
history - Display Command History
Display or manipulate the history list.
Demos
1. Show History List previously executed commands.
man - Interface to the System Reference Manuals
Interface to the system reference manuals.
Demos
1. Manual Page Read the manual for a command.
alias - Define or Display Aliases
Define or display aliases.
Demos
1. Create Alias Create a shortcut for a command.
expr - Evaluate Expressions
Evaluate expressions.
Demos
1. Math Perform integer arithmetic.
Output:seq - Print a Sequence of Numbers
Print a sequence of numbers.
Demos
1. Sequence Print numbers from 1 to 5.
Output:factor - Print Prime Factors
Print prime factors.
Demos
1. Factorize Find prime factors of a number.
Output:sleep - Delay for a Specified Amount of Time
Delay for a specified amount of time.
Demos
1. Pause Pause execution for 5 seconds.
bc - An Arbitrary Precision Calculator Language
An arbitrary precision calculator language.
Demos
1. Calculation Perform calculation.
Output:exit - Cause the Shell to Exit
Cause the shell to exit.
Demos
1. Close Shell Exit the current terminal session.
logout - Exit a Login Shell
Exit a login shell.
Demos
1. Logout Log out of the current session.
poweroff - Power Off the System
Power off the system.
Demos
1. Shutdown Turn off the computer immediately.
reboot - Reboot the System
Reboot the system.
Demos
1. Restart Restart the computer immediately.
halt - Stop the System
Stop the system.
Demos
1. Stop Halt the system immediately.
reset - Reset Terminal
Reset terminal.
Demos
1. Reset Reset terminal settings.
cowsay - Configurable Speaking Cow
Configurable speaking cow.
Demos
1. Say Hello Make the cow say something.
Output:fortune - Print a Random, Hopefully Interesting, Adage
Print a random, hopefully interesting, adage.
Demos
1. Tell Fortune Display a random quote.
cmatrix - Terminal Matrix Rain
Terminal Matrix rain.
Demos
1. Start Matrix Show the scrolling Matrix effect.
sl - Steam Locomotive
Steam Locomotive.
Demos
1. Run Train
Show an animation of a steam locomotive (often run by typo when meaning ls).
figlet - Display Large Characters
Display large characters.
Demos
1. Banner Create a text banner.
Output: