Show Menu

Bash Keyboard Shortcuts by

Simple Bash Commands

Cursur to start of line
Cursur to end of line
Repeat last Bash cmd
cd foldername
change director to foldername
cd ..
go up one folder
list services- shows files in current directory
man <cm­d>
shows manual for <cm­d>
clears terminal
resets terminal but doesn't restart service
Stops current running function
Same as RETURN
deletes backward from pointer
logs out of current session
cat 'filename'
prints file to std out on terminal
print working directory
wc 'filename'
word count of filename
echo 'string or filename'
prints string or filename on the terminal
cat > 'filename'
takes standard input into file
head 'filename'
prints first 10 lines of file
tail 'filename'
prints last 10 lines of file


cut -b
specific bytes
cut -b 1,2,3
bytes 1 2 and 3
cut -b 1-3,5-7
bytes 1-3 and 5-7
cut -b 1-
from first byte to end of line
cut -d
use a delimiter
cut -d " "
outputs from beginning of line to first space

Common Compil­ation commands

gcc 'filen­ame.c'
C files
chmod +x 'filen­'
Bash script files
g++ 'filen­ame.cpp'
CPP files
javac 'javafile'
python 'filename'
to run python scripts
gcc -o newname 'filen­ame.c'
change name of compiled program
g++ -o newname 'filen­ame.cpp'
change name of compiled program

Grep Commands

grep 'string' </d­ir/­fil­ena­me.l­og>
outputs all lines that match 'string'
grep 'string' filename1 filename2
output all lines that match 'string' in multiple files
grep -i 'string' filenmae
ignores case
grep [-options] 'string'
grep standard output
grep [-options] 'string' filename
grep the contents of a file
grep -A n 'string' filename
displays n lines after string
grep -B n 'string' filename
displays n lines before string
grep -v 'string' filename
returns all lines which don't match 'string'
grep -E
allows extended regular expres­sions
grep -E 'strin­g{n}'
get lines with n number of string in it
grep -c
count results
grep -n
show line number

Common Grep Cmds

grep -E '[0-9]­{1,­3}\.[0­-9]­{1,­3}\.[0­-9]­{1,­3}\.[0­-9]­{1,3}' 'filename'
Ip address
grep -srhw "­[[:­aln­um:­]]­\+@[­[:a­lnu­m:]­]\+­" 'filename'
email address

Common Grep Cmds

grep -E '[0-9]­{1,­3}\.[0­-9]­{1,­3}\.[0­-9]­{1,­3}\.[0­-9]­{1,3}' 'filename'
Ip address
grep -srhw "­[[:­aln­um:­]]­\+@[­[:a­lnu­m:]­]\+­" 'filename'
email address

Progra­m/S­cript commands

run cmdX if it fails then run cmdY
cmdX && cmdY
run cmdX if it doesn't fail run cmdY
cmd &
will push cmd to background
cmd & >/d­ev/null &
will put cmd to background and not display cmd outputs
typed after pushing cmd to background to disown cmd from current terminal
show disowned jobs


sed G
double space a file
sed 'G;G'
triple space a file
sed -n '$='
count lines
sed = filename | sed 'N; s/^/ /; s/ *\(.\{­6,­\}\)­\n/\1 /'
number each line of a file
sed 's/^[ \t]//;s/[ \t]$//'
delete both leading and trailing whitespace
sed 's/[ \t]*$//'
delete trailing whitespace
sed '/\n/!­G;s­/\(.\)­\(.*­\n­\)/­&­\2\1­/;/­/D;­s/.//'
reverse all characters on the line
sed 10q
print first 10 lines of file
sed q
print first line of file
sed -e :a -e '$q;N;­11,­$D;ba'
Last 10 lines of file
sed -n '/rege­xp/p'
print only line that matches regex
sed -n '8,12p'
print lines 8-12
sed '1,10d'
delete first 10 lines of a file

Regular Expres­sions

Matches any single character
number in 0-9
non number
"­wor­d" letters, digits and _
non word
non whitespace
0 or more repeti­tions of term
1 or more repeti­tions of term
0 or one instances of term
exactly n instances of term
atleast n instances of term
between x and n instances of term
term1 or term2

Common regex Cmds

matches any number
matches any letter
matches vowels
letters numbers and hyphens
European Date (eg. 21/3/2018 )
email addresses

File Redire­ction

> 'file'
create file or overwrite if existing
>> 'file'
append to the file
< 'file'
read from file
pipe X as input to Y


To use these commands just replace 'filename' or 'term' or 'cmd' with the file or regex or program that is to be used.

How to run Programs or scripts

for recently compiled program
bash script
name changed compiled program
'name of installed program'
eg. gedit, nano, vim


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

          Linux Command Line Cheat Sheet
          Bash/ZSH Shourtcuts Cheat Sheet
          bash Shortcuts Cheat Sheet