Skip to main content

Command Palette

Search for a command to run...

Mastering Essential Linux Commands

Updated
โ€ข8 min read
Mastering Essential Linux Commands

๐Ÿ“ File & Directory Management

CommandDescription
lsList directory contents.
ls -lLong listing format with permissions, size, and timestamp.
ls -aShow all files, including hidden ones.
cd [directory]Change to the specified directory.
cd ..Go one level up in the directory tree.
cd ~Navigate to the home directory.
pwdPrint the current working directory.
mkdir [directory]Create a new directory.
mkdir -p path/to/directoryCreate nested directories.
rmdir [directory]Remove an empty directory.
rm [file]Delete a file.
rm -r [directory]Recursively delete a directory and its contents.
rm -f [file]Force delete a file (no prompt).
cp [source] [destination]Copy files or directories.
cp -r [source] [destination]Recursively copy directories.
mv [source] [destination]Move or rename files/directories.
touch [file]Create a new file or update the timestamp.
stat [file]Display detailed information about a file.
basename [path]Get the file name from the path.
dirname [path]Get the directory name from the path.

๐Ÿ“„ File Viewing & Editing

CommandDescription
cat [file]Display file contents.
zcat [file.gz]View the contents of a compressed file.
more [file]View file contents one page at a time.
less [file]Similar to more, but with backward navigation and search support.
head [file]Display the first 10 lines of a file.
head -n 5 [file]Display the first 5 lines of a file.
tail [file]Display the last 10 lines of a file.
tail -f [file]Continuously monitor a file for new lines (commonly used for logs).
wc [file]Show line, word, and character counts for a file.
cut -b 1-4 [file]Display bytes from position 1 to 4 of each line.
cut -d ":" -f 1 [file]Cut fields using a delimiter (e.g., colon).
sort [file]Sort file content alphabetically.
uniq [file]Filter out repeated lines in a sorted file.
tee [file]Display output and write it to a file simultaneously.
diff [file1] [file2]Show the difference between the two files line by line.
cmp [file1] [file2]Compare two files byte by byte.
file [file]Identify the type of a file.
nano [file]Open a file in the Nano text editor.
vim [file] / vi [file]Open a file in the Vim/Vi text editor.
:wqSave and exit in Vim/Vi editor.
echo "text"Display text in the terminal.
echo "text" > [file]Write text to a file (overwrite).
echo "text" >> [file]Append text to a file.
ln -s [original_file] [symlink_name]Create a symbolic (soft) link. Acts like a shortcut and breaks when the original is deleted
ln [original_file] [hardlink_name]Create a hard link.
nohup [command]Run a command immune to hangups, output logged to nohup.out.

๐Ÿ” Permissions & Ownership

CommandDescription
chmod [permissions] [file]Change file permissions (e.g., chmod 777).
chown [owner]:[group] [file]Change the owner and group of a file.
chgrp [group] [file]Change group ownership.
umaskView default permission mask.
ls -lView file permissions.
lsattrList file attributes.
chattr +i [file]Make a file immutable.
getfacl [file]Get file access control list.
setfacl -m u:username:rwx [file]Set file permissions for a specific user.

โš™๏ธ System Monitoring & Management

CommandDescription
fuser .Show processes using a file/directory.
topReal-time process viewer.
htopEnhanced top (needs installation).
ps auxList all processes.
kill [PID]Terminate the process by ID.
kill -9 [PID]Force kill the process.
pkill [name]Kill the process by name.
uptimeShow system uptime and load.
df -hShow disk usage in human-readable format.
du -sh [directory]Show the size of the directory.
free -hShow memory usage.
vmstatShow virtual memory statistics.
vmstat -aShow active/inactive memory.
iostatDisplay CPU and device I/O stats.
whoShow logged-in users.
wShow active users.
hostnameShow system hostname.
uname -aShow system/kernel information.
dmesgView kernel ring buffer messages.
historyShow command history.
watch [command]Run a command repeatedly every 2 seconds.
time [command]Measure the execution time of a command.
strace [command]Debug command execution (syscalls).
lsofList open files.
dateDisplay current date and time.
whoamiShow current user.
which [command]Show command path.

๐Ÿ‘ฅ User & Group Management

CommandDescription
sudo [command]Run command with superuser privileges.
sudo suSwitch to root user.
useradd -m [user]Add a new user with home directory.
userdel [user]Delete a user.
passwd [user]Change/set a password.
su [user]Switch to another user.
groupadd [group]Create a new group.
groupdel [group]Delete a group.
cat /etc/passwdView user accounts.
cat /etc/groupView groups.
sudo gpasswd -a [user] [group]Add a user to a group.
sudo gpasswd -M [u1,u2] [group]Add multiple users to a group.
sudo usermod -aG docker $USERAdds docker to the group

๐Ÿ“ฆ Package Management

CommandDescription
apt / apt-getDebian/Ubuntu package manager.
sudo apt remove <package_name>Remove a package.
yumRHEL/CentOS package manager.
dnfFedora package manager.
pacmanArch Linux package manager.
portageGentoo package manager.
rpmInstall/manage RPM packages.

๐Ÿ“ฆ Archiving & Compression

CommandDescription
zip [file.zip] [file]Create a zip archive.
unzip [file.zip]Extract zip archive.
gzip [file]Compress file with gzip.
gunzip [file.gz]Decompress gzip file.
tar -cvf archive.tar filesCreate a tar archive.
tar -xvf archive.tarExtract a tar archive.
tar -czvf archive.tar.gz filesCreate a tar.gz archive.
tar -xzvf archive.tar.gzExtract tar.gz archive.

๐ŸŒ Networking

CommandDescription
ping [host]Test connectivity.
netstatShow network statistics.
ifconfigShow network interfaces.
traceroute [host]Trace route to a host.
tracepath [host]Alternative to traceroute.
mtr [host]Interactive traceroute.
nslookup [host]Query DNS.
dig [host]DNS lookup tool.
telnet [host port]Open telnet connection.
ip [options]IP address management.
iwconfigWireless config.
ssSocket statistics.
arp -aShow ARP cache.
nc [opts]Netcat (network debugging).
whois [domain]Domain whois info.
ifplugstatusShow network cable status.
curl [url]Transfer data from/to a server.
wget [url]Download files.
jqParse JSON responses.
iptablesManage firewall rules.
nmap [target]Network scanner.
route -nShow routing table.

๐Ÿ”Ž Text Processing

CommandDescription
grep [pattern] [file]Search text in files.
grep -iCase-insensitive search.
grep -nShow line numbers.
grep -rRecursive search.
grep -cCount matching lines.
grep -eMultiple patterns.
awk '{print $1}' [file]Process text fields.
sed 's/a/b/g' [file]Stream editor for replacements.

๐Ÿ”„ File Transfer & Sync

CommandDescription
scp [src] [user@host:/dest]Securely copy files between systems.
rsync -avz [src] [dest]Sync files between local/remote systems.

๐Ÿ’พ Storage & Volumes

CommandDescription
lsblkList block devices.
pvcreate [disk]Create a physical volume.
vgcreate [vg] [pv]Create a volume group.
vgsDisplay volume groups.
vgdisplayShow volume group details.
pvdisplayShow physical volume details.
lvcreate -L 5G -n lv vgCreate a logical volume.
lvsShow logical volumes.
lvdisplayShow LV details.
mkfs.ext4 [lv]Format as ext4.
mkfs -t ext4 [lv]Alternative format.
mount [device] [dir]Mount a filesystem.
umount [dir]Unmount a filesystem.
lvextend -L +2G [lv]Extend logical volume.