Linux commands cheatsheet

Always use man commandName to know what the command is before copy and paste.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Open a new shell with root, exit with "exit" or "ctrl+d"
sudo su -

# Show how to use a command
man command

# Find first excutable path
whichis command

# Find every excutable path
whereis command

# Use proxy
export http_proxy=http://server-ip:port/
export https_proxy=http://server-ip:port/

# Check CentOS version
rpm --query centos-release

# Read file
cat filename

# Write file (after excute, type content and ctrl+d to save)
cat > filename

# RPM install
rpm -ivh file.rpm

# switch to last directory
cd -

# Download file with wget -c=continue download
wget -c --header "Cookie: foo=bar" http://url/to/file`

# Force reboot immediately
reboot -f

# Rename files
rename <old name> <new name> <Regex match>

# Connect to openvpn
sudo openvpn --config client.ovpn

# List port listening
lsof -i :<port>

# kill process by id
kill PID

# List recent command history
history

# excute command from history
!<search text>
!vi # excute recent command contains vi