Show Menu
Cheatography

Terminal Linux Commands Cheat Sheet by

It contains all the Unix Terminal Commands

Bash Commands

date
Show system date
uptime
Show uptime
uname -a
Show system and kernel
whoami
Show your username
finger user
Display inform­ation about user
cat /proc/­cpuinfo
Cpu inform­ation
cat /proc/­meminfo
Memory inform­ation
head -n1 /etc/issue
Show distri­bution
mount
Show mounted filesy­stems
man command
Show manual for command
export NAME=value
Set $NAME to value
$PATH
Executable search path
$HOME
Home Directory
$SHELL
Current Shell

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

ssh user@host
Connect to host as user
ssh -p port user@host
Connect to host on port as user
ssh-co­py-id user@host
Add your key to host for user to enable a keyed or passwo­rdless login

Process Management

ps
Show snapshot of processes
top
Show real time processes
kill pid
Kill process with id pid
pkill name
Kill process with name name
killall name
Kill all processes with names beginning with name
fg
Brings the most recent job to foreground
fg -n
Brings job n to the foreground

IO Redire­ction

cmd < file
Input of cmd from file
cmd < (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
cmd2 > file
Error output (stderr) of cmd to file
cmd1 > &2
stdout to same place as stderr
cmd2 > &1
stderr to same place as stdout
cmd &> file
Every output of cmd to file

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
!abc
Run last command starting with abc
!abcp
Print last command starting with abc
!$
Last argument of previous command
ALT-.
Last argument of previous command
!*
All arguments of previous command
abc123
Run previous command, replacing abc with 123
 

Directory Commands

pwd
Show current directory
mkdir dir
Make directory dir
cd dir
Change directory to dir
cd ..
Go up a directory
ls
List files
ls -al
Formatted listing with hidden files
rm file
Delete file
cp file1 file2
Copy file1 to file2
cp -r dir1 dir2
Copy dir1 to dir2; create dir2 if it doesn't exist
mv file1 file2
Rename or move file1 to file2 if file2 is an existing directory, moves file1 into directory file2
touch
Create or update file
cat
View file contents
more
Output the contents of file
head
Output the first 10 lines of file
tail
Output the last 10 lines of file
tail -f
Output the contents of file as it grows, starting with the last 10 lines

Searching

grep pattern files
Search for pattern in files
grep -r pattern dir
Search recurs­ively for pattern in dir
grep -i
Case insens­itive search
grep -r
Recursive search
grep -v
Inverted search
grep -o
Show matched part of file only
locate file
Find all instances of file
find /dir/ -user name
Find files owned by name in dir
find /dir/ -mmin num
Find files modified less than num minutes ago in dir
whereis command
Find binary / source / manual for command

File Permis­sions

chmod 775 file
Change mode of file to 775
chmod -R 600 folder
Recurs­­ively chmod folder to 600
chown user.group file
Change file owner to user and group to group
First digit is owner permis­­sion, second is group and third is everyone.
Calculate permission digits by adding numbers below.
4
read (r)
2
write (w)
1
execute (x)

Network

ping host
Ping host and output results
whois domain
Get whois inform­ation for domain
dig domain
Get DNS inform­ation for domain
dig -x host
Reverse lookup host
wget file
Download file
wget -c file
Continue a stopped download

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 File
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
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          tmux the terminal multiplexer Cheat Sheet
          Tmux Cheat Sheet
          Command Line and Terminal navigation Cheat Sheet