Show Menu
Cheatography

Linux Cheat Sheet (DRAFT) by

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

Navigation

ls
list directory contents
ls -al
-a = all -l = long listing format
cd <di­rec­tor­y>
change directory (~ = home / = root)
cd ..
change to the parent of the current directory
pwd
print working directory

File Commands

mkdir <di­rec­tor­y>
make a new directory (folder)
touch <fi­le>
make a new file
rm -r <di­rec­tor­y>
remove a folder (-r means recursive, delete folder + everything in it)
rm <fi­le>
remove a file
rm -f <fi­le>
force remove a file
cp <fi­le1> <fi­le2>
copy file1 and paste as file2
mv <file to move> <place to move to>
move file
mv <fi­le1> <fi­le3­000>
moving a file within the same folder will rename it
ln -s <fi­le> name
create a symbolic link called "­nam­e" to file
cmd > <fi­le>
puts standard output (stdout) of command into <fi­le>
cmd >> <fi­le>
appends standard output (stdout) of command into <fi­le>
 

Reading Files

cat <fi­le>
concat­enate <fi­le> and print to stdout (i.e. read the file)
less <fi­le>
prints as much of the file that can fit within the terminal window. PgUp/P­gDown to navigate
more <fi­le>
print file out line by line
head <fi­le>
output first 10 lines of file
tail <fi­le>
output last 10 lines of file
tail -f <fi­le>
output contents of file as it grows
sed -i 's,foo­,bar,g' <fi­le.t­xt>
replaces all instances of foo with bar in <fi­le.t­xt>

Finding files

find /etc/ -name foo*
find all files starting with foo in /etc/
find /dir/ -user bar
find all files owned by bar in /dir/
locate <fi­le>
find all instances of <fi­le>

Finding binaries

which <bi­nar­y>
find location of binary e.g. which sudo
whereis <bi­nar­y>
find the location, source, and manual for a binary