9 min read

🔠 1653 words

The Ultimate Linux Cheat Code Handbook

The Ultimate Linux Cheat Code Handbook

Basic System Commands

CommandDescription
catdisplays the contents of a file
pwddisplays the current working directory
cdchanges the current directory
lslists the contents of a directory
cpcopies files and directories
mvmoves or renames files and directories
rmremoves files and directories
mkdircreates a new directory
rmdirremoves an empty directory
chmodchanges the permissions of a file or directory
psdisplays information about running processes
topdisplays real-time information about system usage
killterminates a process
shutdownshuts down the system

File Commands

CommandDescription
lslists the files of a directory
ls -llists the files of a directory in long format
ls -alists all files of a directory, including hidden
pwddisplays the current working directory
cdchanges the current directory
cd ~changes the current directory to the home directory
cd ..changes the current directory to the parent
cd -changes the current directory to the previous
cd /changes the current directory to the root
mkdircreates a new directory with the specified name
rmdirremoves the directory with the specified name
touchcreates a new file with the specified name
cpcopies files and directories
mvmoves or renames files and directories
rmremoves files and directories
rm -rremoves files and directories recursively
rm -fremoves files and directories forcefully
rm -rfremoves files and directories forcefully recursively

File Permissions

CommandDescription
chmod 777 fileGives Read, Write and Execute permissions to everyone
chmod 755 fileGive read, write, and execute permission to owner, and read and execute permission to group and others
chmod 644 fileGive read and write permission to owner, and read permission to group and others
chown user filechanges the owner of a file
chown user:group filechanges the owner and group of a file
chmod u+x filegives execute permission to the owner
chmod g+x filegives execute permission to the group

Users and Groups

CommandDescription
iddisplays the user and group IDs
id userdisplays the user and group IDs for a specific user
whoamidisplays the current user
whodisplays who is logged on
who -adisplays who is logged on and what they are doing
lastdisplays the last logged in users
adduser useradds a new user
usermod -aG group useradds a user to a group
groupadd groupadds a new group
userdel userdeletes a user
usermodmodifies a user account
chgrp group filechanges the group ownership of a file

Package Management (Needs sudo)

CommandDescription
apt updateupdates the package lists
apt upgradeupgrades the installed packages
apt install packageinstalls a package
apt remove packageremoves a package
apt autoremoveremoves packages that are no longer needed
apt search packagesearches for a package
apt purge packageremoves a package and its configuration files
apt cleanremoves downloaded package files
apt autocleanremoves old downloaded package files

SSH

CommandDescription
ssh user@hostconnects to a remote host using SSH
ssh -p port user@hostconnects to a remote host using SSH on a specific port
ssh-keygengenerates a new SSH key pair
ssh-copy-id user@hostcopies the SSH key to the remote host
ssh -i key user@hostconnects to a remote host using a specific SSH key
scp file user@host:copies a file to a remote host

System Info

CommandDescription
unameprint system information
uname -adisplays all system information
uname -rdisplays the kernel release
uname -mdisplays the machine hardware name
uname -ndisplays the network node hostname
hostnamedisplays the network node hostname
hostname -Idisplays All IP address
uptimedisplays how long the system has been running
whoamidisplays the current user
dfdisplays the amount of disk space available
mandisplays manual page

Privilege Escalation

CommandDescription
sudoallows a user to execute a command as the superuser
suallows a user to execute a command as another user
sudo suallows a user to execute a command as the superuser
sudo -iallows a user to execute a command as the superuser
sudo -uallows a user to execute a command as another user
sudo -lallows a user to list the allowed commands

Archiving

CommandDescription
tar -cvf archive.tarcreates a new archive
tar -xvf archive.tarextracts files from an archive
tar -tvf archive.tarlists the contents of an archive
tar -cvzf archive.tar.gzcreates a new compressed archive
zip archive.zip filecreates a new archive in ZIP format
unzip archive.zipextracts files from an archive in ZIP format

Searching

CommandDescription
grep pattern filesearches for a pattern in a file
grep -r pattern dirsearches for a pattern in a directory recursively
grep -v pattern filesearches for all lines that do not contain a pattern
grep -i pattern filesearches case-insensitively for a pattern in a file
grep -l pattern filedisplays the names of files that contain a pattern
locate filesearches for a file in the database
find dir -name filesearches for a file in a directory
find .searches for files in the current directory
find / -name filesearches for a file in the entire system
find / -name file -type fsearches for a file in the entire system for file types

Process Management

CommandDescription
psdisplays your currently active processes
ps -efdisplays all processes
topdisplays all processes
kill pidkills the process with the specified process ID
killall processkills all processes with the specified name
bgList and resume stopped jobs in the background
fgBring the most recently suspended job to the foreground

Networking

CommandDescription
ifconfigdisplays the network interfaces
ifconfig -adisplays all network interfaces
ifconfig eth0displays the network interface eth0
iwconfigdisplays the wireless network interfaces
systemctl stop NetworkManagerstops the NetworkManager service
systemctl start NetworkManagerstarts the NetworkManager service
systemctl restart NetworkManagerrestarts the NetworkManager service
whois domaindisplays whois information for a domain
dig domainperforms DNS lookup for a domain
host domainperforms DNS lookup for a domain
nslookup domainperforms DNS lookup for a domain
ping domainpings a domain and displays the result

Keyboard Shortcuts

CommandDescription
Ctrl + CStops the current command
Ctrl + ZBackgrounds the current command
Ctrl + DLogs out the current user
Ctrl + AMoves the cursor to the beginning of the line
Ctrl + EMoves the cursor to the end of the line
Ctrl + LClears the terminal screen
Ctrl + Shift + CCopies the selected text
Ctrl + Shift + VPastes the selected text
Ctrl + Shift + TOpens a new tab in the current window
Ctrl + Shift + NOpens a new window in the current session
Ctrl + Shift + QCloses the current window
!!Repeats the previous command
exitExits the current shell