Linux Command Cheat Sheet

The following are useful Linux commands to master.

Command Description Example
pwd Print working directory pwd
cd Change directory cd ~/Desktop
cd /etc
cd ..
cd Castle/Cellar
ls List directory contents ls -al
ls -l
ls *.txt

Work with Files

Command Description Example
touch Create a file touch new.txt
mv Move or rename files and directories mv old_name.txt new_name.txt
mv *.txt ~/backups
cp Copy files and directories cp /etc/passwd ~/passwd
cp backups_* ~/old_backups
mkdir Make a directory mkdir test_files
rm Remove files or directories rm deleteme.txt
rm *.backup
rm backups_*
rm *student*
rm -rf dir_to_be_deleted
tar Create and extract archives tar -czvf my.tar.gz *.txt
tar -xvf file.tar.bz2
file View information about a file file file.tar.bz2
chmod Change file permissions chmod u+x program.sh
chmod -x program.sh
chmod 560 program.sh
nano Edit text files in easy mode nano config.txt
vim Edit text files in hard mode vim config.txt
> Output content to a file echo "test" > test.txt
ls backup* > backup_list.txt
>> Append content to a file echo "test" >> test.txt

Show File Content

Command Description Example
cat Print all file contents cat file.txt
head Print the first lines in a file head file.txt
head -n 5 file.txt
tail Print the last lines in a file tail file.txt
tail -n 4 file.txt
less Display a file in a navigable format less file.txt
more Display a file line by line or page by page more file.txt
Command Description Example
grep Find text inside files grep -i fail auth.log
grep -ir error ~/*
grep -il cash *
find Find directories and files find . -name "*log*"
find . -iname *cash*
find / -name "*.txt" -type f
find / -name "logs" -type d

System Management

Command Description Example
sudo apt udpate Updates the list of available packages sudo apt update
sudo apt upgrade Updates currently installed packages sudo apt upgrade
sudo apt install [x] Installs new packages sudo apt install nmap
alias Create an alias alias la='ls -A'
ps View running processes ps -A
kill Stop a process kill 634185
kill -s 9 6352671
kill -s TERM 633227 633123 633115
pstree View running processes as a tree pstree
top View running processes in real-time top
systemctl Manage services sudo systemctl start apache2
logger Manually create a log entry logger Backup started

Account Management

Command Description Example
whoami Prints current user whoami
sudo Superuser do: run a command as root sudo ls /root
su Switch users (default is root) sudo su
exit Exit the terminal or switched user exit
useradd Add a user sudo useradd chris
passwd Change a user's password sudo passwd chris

Download Files

Command Description Example
git Manage git source repositories git clone https://github.com/jimmarq/cyfunfiles
wget Download files from the internet wget https://some_site/file.zip
curl Download content from the internet curl https://www.google.com

Networking

Command Description Example
ifconfig View and change network information (old) ifconfig eth0
ip View and change network information (new) ip a
nmap Scan ports nmap scanme.nmap.org
nping Ping for enhanced network testing nping scanme.nmap.org -p 9929
tcpdump Capture network packets tcpdump -i eth0 -w telnet.pcap
telnet Connect to remote computers (unencrypted) telnet telehack.com
dig Query domain name information dig yahoo.com
ping Verify connectivity ping 192.168.1.1

Other

Command Description Example
man Show the manual for a command man ls
echo Print text to the terminal echo "hi"