Show Menu
Cheatography

Unix/Linux Command Reference Cheat Sheet (DRAFT) by

Revision before exams.

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

Bash Shortcuts

CTRL-c
Stop current command
CTRL-z
Sleep program
CTRL-a
Go to start of line
CTRL-e
Go to end of line
CTRL-u
Cut from start of line
CTRL-k
Cut to end of line
CTRL-r
Search history
!!
Repeat last command

Nano Shortcuts

Files
Ctrl-R
Read file
Ctrl-O
Save file
Ctrl-X
Close file
Cut and Paste
ALT-A
Start marking text
CTRL-K
Cut marked text or line
CTRL-U
Paste text
Navigate
ALT-/
End of file
CTRL-A
Beginning of line
CTRL-E
End of line
CTRL-C
Show line number
CTRL-_
Go to line number
Search File
CTRL-W
Find
ALT-W
Find next
CTRL-\
Search and replace

Basic Commands

man <Co­mma­nd>
Show manual for command
<Co­mma­nd> --help
Show manual for command
clear or reset
Clear the terminal

Directory Operations

pwd
Show current directory
cd <dir name>
Change directory to dir
cd ..
Go up a directory
mkdir <dir name>
Make directory dir
rmdir <dir name>
Delete empty direct­ories
ls <di­r>
List files of stated dir else current dir

ls Options

-a
Show all (including hidden)
-R
Recursive list
-r
Reverse order
-t
Sort by last modified
-S
Sort by file size
-l
Long listing format
-1
One file per line
-m
Comma-­­se­p­a­rated output
-Q
Quoted output

SSH

connect to host as user
ssh user@h­ost.com -p <po­rt>
connect to host on certain port as user

File Operations

touch <fi­len­ame>
Create file
cp file1 file2
Copy file1 to file2
mv file1 file2
Move file1 to file2
rm file1
Delete file1
file <filename>

Example:
file ./-file0* to get all the file type of ./file01, ./file02 etc
Get the type of file
cat <file>

Examples of how to print weird files:
1. cat < -
2. cat ./-
3. cat "­spaces in this filename"
4. cat spaces\ in\ this\ filename
5. cat .hidde­nfile
concat­enate files and print on the standard output

Search Files

find -options
Find files based on options
grep -options
Search for pattern in files

IO Redire­ction

cmd < file
Input of cmd from file
cmd1 < (cmd2)
Output of cmd2 as file input to cmd1
cmd > file
Standard output (stdout) of cmd to file
cmd > /dev/null
Discard stdout of cmd
cmd >> file
Append stdout to file
cmd 2> file
Error output (stderr) of cmd to file
cmd 1>&2
stdout to same place as stderr
cmd 2>&1
stderr to same place as stdout
cmd &> file
Every output of cmd to file
cmd refers to a command.