Prerequisites
Terminal access
Root or sudo privileges
Familiarity with the Linux shell and terminal
Introduction
The command line is one of the most powerful tools in a Linux user's arsenal. While the graphical interface might be more familiar to many, mastering the terminal unlocks a new level of efficiency and control over your system. Whether you're a seasoned sysadmin or a Linux newcomer, knowing the right commands can dramatically boost your productivity and make you feel more at home in the Linux environment.
In this post, we’ll introduce you to the top Linux commands you absolutely can't live without. From navigating your filesystem to managing processes and network connections, these essential commands will help you become a more proficient and confident Linux user. Ready to level up your terminal game? Let’s dive in!
General Structure of a Linux Command Line
command [options] [arguments]
65 Essential Linux Commands Every User Should Know
File Management Commands
ls - list directory contents
- ls -l
- long listing format
- ls -a
- shows hidden files
- ls -la
- gives you a long listing of all files including hidden files
cd - change directory
- cd ~
- changes to the user's home directory
- cd ..
- moves up one level to the parent directory of the current directory
- cd -
- switches to the previous directory that you were in
- cd /
- changes to the root directory
pwd - displays the full path of the current directory
cp - copy files and directories
- cp file1.txt /home/user/ (copies file1.txt to the specified directory)
mv - move or rename files and directories
rm - remove files or directories
shred - used to securely delete files
touch - used to create empty files
mkdir - make directories
rmdir - remove empty directories
find - search for files in a directory hierarchy
ln - used to create links between files
File Permission and Ownership Commands
chmod - change file permissions
chown - change file owner and group
System Information Commands
uname - used to display information about the system, such as the kernel version, the operating system, and other system details
neofetch - system information tool written in Bash that displays information about your system in a visually appealing way
hostnamectl - view the hostname
- hostnamectl set-hostname new-hostname
- change the hostname
df - report disk space usage
du - useful tool to analyze disk space usage
free - display memory usage
- free -h
- Stands for "human-readable," which converts the values into units like MB (megabytes), GB (gigabytes), etc.
top - display dynamic real-time system information
htop - an enhanced version of top
ps - report a snapshot of current processes
whoami - displays the current logged-in username
man - display manual pages for commands
history - show command history
which - helps you identify the exact location of a program or command
whatis - provides a short description of a command
who - when you need a simple list of users logged into the system
w - when you need more detailed information about what users are doing, how long they've been idle, and their resource usage
last - show the last login sessions
Network Commands
ping - used to check the network connectivity
rsync - used for file synchronization, backup, and data transfer
netstat - used to display network statistics
- netstat -tunlp
- -t: show tcp connections
- -u: show udp connections
- -n: show numerical addresses instead of resolving hostnames
- -l: show only listening sockets
- -p: show the PID and the name of the program to which each socket belongs
wget - download files from the web
ssh - secure shell (remote login)
Process Management Commands
kill - terminate processes by PID
Text Processing Commands
wc - used to count lines, words, and characters in a file or input provided to it
cat - used to display the contents of files
sort - used to sort lines of text in a file or input, based on various criteria
awk - used for pattern scanning, text manipulation, and data extraction
diff - used to compare two files line by line
cmp - used to check if two files are identical
less - used to view the content of a file one screen at a time
tail - used to display the last part of a file
head - used to display the beginning of a file
grep - search text using patterns
- grep -rnw "." -e "pattern"
- -r: recursive search
- -n: line number
- -w: word match
- It will only match the string if it appears as a whole word, not as a part of another word.
- -e: specifies that pattern you're search for
- ".": refers to the current directory
File Compression and Archiving Commands
zip - used to compress files into a ZIP archive format
unzip - used to extract files from a ZIP archive
User and Group Management Commands
useradd - preferred for advanced users or system administrators who need precise control over the user creation process
adduser - ideal for non-technical users or administrators who want a quick and interactive way to add users with default settings
id - display user and group information
su - switch to another user account
sudo - execute a command as superuser (root)
passwd - used to change a user's password
Text Editing Commands
nano - simple and user-friendly text editor
vim - text editor that is widely used for editing and creating text files
vi - traditional text editor, similar to vim but less feature-rich
emacs - used to launch the Emacs text editor
Shell Built-In Commands
alias - used to create shortcuts or custom commands
echo - used for outputting text to the terminal
source - used to execute a script or a file in the current shell environment
- source /path/to/script.sh
jobs - list background jobs
Terminal Management Commands
exit - exit the terminal or shell session
clear - clears the terminal screen
Final Thoughts
Mastering these essential Linux commands is a powerful way to enhance your efficiency and confidence in the terminal. Whether you’re a beginner or an experienced user, knowing these commands will make navigating your system faster and more intuitive. With practice, you'll soon be able to tackle any task in Linux with ease. So, take the time to familiarize yourself with these commands, and don't be afraid to experiment – your mastery of the terminal is just a command away!