Linux CheatSheet
Linux Commands and User Management Cheat Sheet
If you prefer, you can check this repository.
This cheat sheet is based on the book "Linux Basics for Hackers" by OccupyTheWeb.
Warning: This list does not replace the book. It's a quick reminder of the most used commands. For more details, use
man
or--help
.
Recommended Reading: Amazon | Official Site
Keyboard Shortcuts
Ctrl + C
Interrupts a running command
Ctrl + Z
Suspends a process (puts it in background)
Ctrl + D
Closes current terminal session or ends text input
Ctrl + R
Searches previous commands in history (reverse search)
Ctrl + L
Clears the screen (like clear
)
Ctrl + A
Moves cursor to beginning of line
Ctrl + E
Moves cursor to end of line
↑ Arrow
Navigate to previous commands
↓ Arrow
Navigate to more recent commands
← → Arrows
Move cursor left or right
Basic Commands
pwd
Shows current directory
pwd
whoami
Shows current user
whoami
cd
Change directory
cd /path/to/directory
ls
List directory contents
ls -la
--help
Shows help for a command
ls --help
man
Shows manual for a command
man ls
locate
Search files by name
locate file
find
Search files recursively
find /path -name file
which
Shows path of a command
which ls
whatis
Briefly explains what a command does
whatis chmod
whereis
Shows location of binary, source code and manual
whereis ls
ps
Shows running processes
ps aux
cat
Shows file contents
cat file.txt
mkdir
Creates a new directory
mkdir new_directory
rm
Deletes files or folders
rm file.txt
rm -rf folder
rmdir
Deletes empty directories
rmdir empty_folder
mv
Moves or renames files
mv old.txt new.txt
touch
Creates empty files or updates date
touch new.txt
wget
Downloads files from the web
wget http://example.com/file.txt
Text Manipulation
head
Shows first lines
head -n 10 file.txt
tail
Shows last lines
tail -n 10 file.txt
nl
Numbers lines
nl file.txt
sed
Stream text editor
sed 's/old/new/g' file.txt
more
Shows files page by page
more file.txt
less
Same as more
, but better
less file.txt
System Management
ps
Shows active processes
ps
nice
Executes with adjusted priority
nice -n 10 command
kill
Terminates processes by PID
kill 1234
killall
Terminates processes by name
killall firefox
fg
Brings processes to foreground
fg %1
at
Schedules tasks
echo "command"
chown
Changes file owner
chown user:group file
chmod
Changes permissions
chmod 755 file
System Information
uname -a
Kernel and system info
uname -a
df -h
Disk usage
df -h
top
Real-time process monitor
top
htop
Same as top
but better (if installed)
htop
User and Group Management
adduser
Adds a new user
sudo adduser jose
deluser
Deletes a user
sudo deluser jose
groupadd
Creates a new group
sudo groupadd comercial
groupdel
Deletes a group
sudo groupdel comercial
usermod -aG
Adds a user to a group
sudo usermod -aG comercial jose
cat /etc/group
Shows all system groups
cat /etc/group
sudo su
Elevates to superuser (requires password)
sudo su
su user
Changes to specified user
su jose
id user
Shows user ID and groups
id jose
Practical Example:
Create a user and add them to a group:
sudo adduser jose
sudo groupadd comercial
sudo usermod -aG comercial jose
File Permissions and Ownership
chmod
Changes file or directory permissions
chmod 755 file
chown
Changes owner
chown user:group file
chgrp
Changes only the group of a file
chgrp comercial file
Useful Console Operators
&
Executes a command in background
ping google.com &
|
Passes output of one command as input to another
command1 | command2
>
Redirects output to a file (overwrites)
echo hello > output.txt
>>
Redirects output (appends to end)
echo another >> output.txt
<
Takes input from file
sort < file.txt
;
Executes multiple commands in sequence
cd /tmp; ls -l
&&
Executes second command only if first was successful
make && make install
Practice Recommendations
Bandit (capture the flag and challenges)
cmdChallenge (command challenges)
Terminus (graphic adventure)
LearnShell (theory and exercises)
LinuxCommand (theory and practice)
May the terminal always be by your side >.
Last updated