Linux Commands Cheat Sheet: Your Quick Reference to Mastering the Terminal

  • Post last modified:November 24, 2023
  • Post comments:0 Comments
You are currently viewing Linux Commands Cheat Sheet: Your Quick Reference to Mastering the Terminal

Dive into our comprehensive Linux Commands Cheat Sheet crafted for beginners and experts alike. This guide categorizes essential commands, making it effortless to find and execute the operations you need. Whether you’re managing files, users, or networking, this cheat sheet is your go-to reference to maneuver through the Linux terminal efficiently.

Basic Linux Commands

CommandDescription
lsDisplay the contents of the current directory
pwdShow the current directory path
touch filenameCreate a new empty file
mkdir dirnameCreate a new directory
rmdir dirnameRemove a directory
cp source destCopy files or directories
mv old newMove or rename files or directories
rm filenameRemove a file
cat filenameDisplay the contents of a file
head filenameShow the first 10 lines of a file
tail filenameShow the last 10 lines of a file
more filenameDisplay file contents page by page
less filenameDisplay file contents and allow scrolling
grep pattern fileSearch for a pattern within a file
find dir -name patternSearch for files under dir
whoShow who is logged on
whoamiDisplay current username
psShow current processes
kill pidTerminate process with given pid

File Permission Commands

CommandDescription
chmod permissions filenameChange file permissions
chown user:group filenameChange file ownership and group
chgrp group filenameChange file group
umaskSet default permissions for new files
getfacl filenameDisplay file permissions in ACL format
setfaclSet file permissions using ACLs
ls -lhDisplay permissions in human-readable format
stat filenameDisplay detailed file permissions

Environment Variables Commands

CommandDescription
export VARIABLE=valueSet a new environment variable
unset VARIABLERemove an environment variable
printenv VARIABLEDisplay the value of a variable
printenvDisplay all environment variables
setDisplay all environment variables and functions
envDisplay all environment variables
VARIABLE=value commandSet environment variable for the duration of the command

User Management Commands of Linux

CommandDescription
useradd usernameCreate a new user
passwd usernameSet or change user password
userdel usernameDelete a user account
groupadd groupnameCreate a new group
groupdel groupnameDelete a group
usermod -aG groupname usernameAdd user to a group
gpasswd -a username groupnameAdd user to a group
gpasswd -d username groupnameRemove user from a group
getent passwdList all users
getent groupList all groups
id usernameDisplay user and group IDs
wShow who is logged on and what they are doing

Networking Commands

CommandDescription
ifconfigDisplay network configuration
ip addr showDisplay IP addresses and network details
ping hostnameTest connectivity to a host
traceroute hostnameTrace the route to a host
netstatDisplay network connections, routing tables, and interface statistics
ssDisplay socket statistics
telnet hostnameConnect to a host via Telnet
ssh username@hostnameSecurely connect to a host via SSH
scp source_file user@host:destinationSecurely copy files over the network
ftp hostnameConnect to a FTP server
wget URLDownload files from the web
curl URLTransfer data to or from a server
nslookup domainQuery DNS lookup name
dig domainQuery DNS

Process Commands

CommandDescription
pstreeDisplay a tree of processes
pkill patternTerminate processes with names matching pattern
killall process_nameTerminate all processes with the given name
lsofList open files and the processes that opened them
vmstatDisplay virtual memory statistics
uptimeShow system uptime and load average
dmesgDisplay kernel ring buffer messages
systemctl status service_nameCheck the status of a system service
journalctlQuery the systemd journal
mpstatDisplay CPU statistics
iostatDisplay disk I/O statistics
sarCollect and report system activity information

VI Editing Commands

CommandDescription
vStart visual mode for text selection
yYank (copy) selected text
pPaste copied text
:%s/old/new/gReplace all occurrences of ‘old’ with ‘new’
:w filenameSave file as ‘filename’
:e filenameOpen file ‘filename’ for editing
:qQuit VI (without saving)
:q!Quit VI (without saving) and discard changes
:wqSave and quit VI
:set numberShow line numbers
:set spellTurn on spell checking
GGo to the end of file
ggGo to the beginning of file
:w !sudo tee %Save file when forgetting to open editor with sudo

Additional Insight: Understanding the Linux File Hierarchy

The Linux File Hierarchy Structure (FHS) defines the directory structure and directory contents in Unix and Unix-like operating systems.

/binEssential command binaries that are required to troubleshoot or recover the system
/bootStatic files of the boot loader
/devDevice files
/etcHost-specific system configuration
/homeUser home directories
/libEssential shared libraries and kernel modules
/mediaMount point for removable media
/mntMount point for temporarily mounted filesystems
/optOptional application software packages
/sbinEssential system binaries
/srvData for services provided by this system
/tmpTemporary files
/usrSecondary hierarchy for read-only user data; contains the majority of multi-user utilities and applications
/varVariable data including logs, spool files, and temporary e-mail files

More Information on Commands

To delve deeper and gather more information about any Linux command, you can use the man command followed by the name of the command you are interested in. For example:

man ls

This will display the manual page for the ls command, providing detailed explanations and options associated with the command. The man pages are a treasure trove of information, helping you explore the nuances and powerful features of Linux commands.

This Linux Commands Cheat Sheet is designed to be a handy reference, aiding you in your journey through the Linux environment. Whether you’re a newbie starting out or a seasoned professional, this cheat sheet is sure to become a valuable resource in your toolkit.

Keep exploring, and you’ll continue to uncover the boundless possibilities Linux commands unfold. Remember, mastering the terminal is the first step towards becoming proficient in the Linux world. Happy coding!

Leave a Reply