Show Menu
Cheatography
  • Building New PDFs

Linux Cheat Sheet (DRAFT) by

Linux and Some Tools

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Directory / Navigation

ls
List files and direct­ories
ls -a
List all files and direct­ories (shows hidden files)
ls -l
List files and direct­ories in long format (shows permis­sions)
ls -h
List the sizes in human readable
ls -r
Reverse Listing
ls -t
Sort by modified time
ls -S
Sort by file size (can be used with -r)
ls -R
Recursive listing
find .
Recursive listing
tree
Recursive listing
cd
Change Directory
cd ..
Move up one directory
cd ../..
Move up two direct­ories / or more
cd -
Change to previous directory
cd ~
Change directory to home
cd /
Change directory to root directory
pwd
Print working directory

Searching

find
Searches the file in current directory
find / -name "­fil­e"
Searches the file starting from root directory
find / -iname "­fil­e"
Searches the file starting from root directory regardless of case sensit­ivity
find -size +100M
See files and direct­ories larger than a specified size in a directory
locate
Searches the file in whole disk
updatedb
Updates locate's index
grep hello file.txt
Searches the term in a file
grep hello *.txt
Searches hello in every .txt file
which command
Search the command path in the $PATH enviro­nment variable
whereis command
Find the source, binary, and manual page for a command

System Management

uname -a
See kernel release inform­ation
uptime
Display how long the system has been running, including the load average
hostname
View system hostname.
date
See current time and date
timeda­tectl
See date and time zone
w
List logged-in users.
whoami
See which user you are using
finger
Show inform­ation about a particular use
shutdown [hh:mm]
Schedule a system shutdown
shutdown now
Shut down the system immedi­ately
reboot
Restart the OS
dmesg
Show bootup messages.
 

File Manipu­lation

cat
Show the contents of the file
cat -n
Number all output lines
mkdir
Create a new directory
mkdir -p dir/di­r/dir
Create a dir with child
mkdir -p parent­/{c­hild, child2}
Create a dir with childs
mkdir -p parent­/{d­ir1­/{c­hil­d1,­chi­ld2­},dir2
Create a parent dir with 2 dirs 2 childs
rm
Remove a file
rm -r
Remove a directory
rm -rf
Remove a directory without confir­mation
rm -rf .
Remove the current directory
cp file file
Copy content of the file to another file
cp -r dir dir
Copy content of the dir to another dir
mv file dir
Move or rename file or dirs
touch
Create a new file
cat file >>file
Append file contents to another file
>fi­le.txt
Truncates the content after ctrl+c. If not pressed and stay in contin­uation prompt, all input goes to the file like echo
head
Show the first ten lines of a file
tail
Show the last ten lines of a file
head/tail -n 5 file
Show the last/first five lines of a file
tail -f
Streams the last 10 lines
tail -f -s 2
Sleep for approx­imately 2 seconds
more
Display contents of a file page by page
less
Show the contents of a file with navigation
gpg -c file
Encrypt a file
gpg file.gpg
Decrypt an encrypted .gpg file
wc
Shows line, word and byte amount
wc -l
Shows number of lines
wc -w
Shows number of words
wc -c
Shows number of bytes (file byte)
cut
Learn the usage of this command
shred
Overwrite a file to prevent its recovery
shred -u
Overwrite a file to prevent its recovery, then delete it
shred -n 3
Overwrite a file 3 times to prevent its recovery
ls | tee list.txt / ls>­lis­t.txt | tee
List it and writes the output to list.txt
echo "­hel­lo"
Prints hello to terminal
echo "­hel­lo"> file.txt
Writes hello to the file.txt
echo "­wor­ld">­>fi­le.txt
Adds world to file.txt without removing the file content
 

Processes

ps
List active processes.
ps aux
List active processes in detail
pstree
Show processes in a treelike diagram.
top
See all running processes.
kill PID
Terminate a Linux process under a given ID
kill -9 PID
Force terminate a Linux process under a given ID
pkill [proce­ss_­name]
Terminate a process under a specific name
killall [proce­ss_­name]
Terminate all processes with a given label
pidof [proce­ss_­name]
Show the PID of a process.