-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic.sh
187 lines (162 loc) · 4.38 KB
/
basic.sh
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
echo 'basic aliases sourced'
#find strings in folder
alias srch='grep -rniI --exclude-dir={bundles,dist,node_modules,bower_components} . -e' # ex) srch "search term"
srchFilename() {
find . -iname "*$1*"
}
# Navigation
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias ......='cd ../../../../..'
alias back='cd $OLDPWD'
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
alias ll='ls -al'
alias l='ls -alrt'
alias g='git'
alias ga='git add'
alias gaa='git add -A :/'
alias gai='git add -i'
alias gd='git diff --color'
alias gds='git diff --staged'
alias gdisc='git diff --ignore-space-change'
alias gpom='git pull origin master'
alias gpum='git push origin master'
alias gc='git commit -v -m'
alias gst='git status'
alias gp='git push'
alias gpl='git pull'
alias gco='git checkout'
alias gcop='git checkout -p'
alias gcp="git cherry-pick"
alias gs='git stash'
alias gsa='git stash apply'
alias gcheckpoint='git stash && git stash apply'
alias gl='git prettylog'
alias glog='git log --oneline --decorate --graph'
alias glgp='git log --stat -p'
alias ggpush='git push origin "$(git_current_branch)"'
alias ggpull='git pull origin "$(git_current_branch)"'
alias m.tail-logs="tail $(ls -rt /var/log/ -I 'wtmp*' -I '*.gz' -I 'dpkg*gz' -I 'postgresql') -vf"
m.tail-logsf() {
tail $(ls -rt /var/log/ -I 'wtmp*' -I '*.gz' -I 'dpkg*gz' -I 'postgresql') -vf
}
# This handy tool tells you how much space you have left on a drive
alias df='df -h'
#alias du='du -h --max-depth=1'
alias dusort='du -sh * | sort -h'
zip-archive() {
# $1 destination archive name
# $2 archive folder
zip -r $1 $2
}
# Extract
zip-unarchive() {
if [ -f $1 ]; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "don't know how to extract '$1'..." ;;
esac
else
echo "'$1' is not a valid file!"
fi
}
alias sudo='sudo '
alias sv='sudo nvim'
#Networking
alias m.whatsmyip="curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//'"
# Location information functions
m.whereami_latlong() {
curl ipinfo.io/loc
}
m.whereami_country() {
curl ipinfo.io/country
}
m.whereami() {
curl ipinfo.io/json
}
# Layer 1: Physical - Is our physical interface up?
alias m.net1-interfaces='ip -br link show'
alias m.net1-interfaces-more='ifconfig'
m.net1-interface-up() {
#if down:
ip link set $1 up
}
m.net1-interface-more() {
#show additional stats like dropped packets
ip -s link show $1
}
# Layer 2: Data Link 'local Network'
alias m.net2-neighbors='ip neighbor show' # Check ARP Table
m.net2-neighbor-recheck() {
# args: IP dev interface
#force new ARP resolution by deleting the record
ip neighbor delete $1 $2 $3
}
# Layer 3: Network/Internet
alias m.net3-ip-address='ip -br address show' # 1st check local IP address; rules out DHCP or misconfig issues
m.net3-ping() {
# Start troubleshooting remote host resolution
ping $1
}
m.net3-traceroute() {
# Next check the route to the remote host with
traceroute $1
}
alias m.net3-gateway='ip route show' #check routing table for upstream gateways
m.net3-gateway-check() {
# check the route for a specific prefix:
#ip route show 10.0.0.0/8
ip route show $1
}
m.net3-dns-check() {
#DNS not L3 protocol
##nslookup www.google.com
nslookup $1
}
# Layer 4: Transport - TCP/UDP
#
alias m.net4-httpstat="httpstat" #check curl connection statistics
alias m.net4-ports-local='ss -tunlp4' #check local listening ports
# -t - Show TCP ports.
# -u - Show UDP ports.
# -n - Do not try to resolve hostnames.
# -l - Show only listening ports.
# -p - Show the processes that are using a particular socket.
# -4 - Show only IPv4 sockets.
alias m.net4-ports-local-process='sudo netstat -tulpn' #show process
m.net4-ports-remote() {
if [ -z "$1" ]; then
echo "Usage: $0 <ip/host>"
return 1
fi
sudo nmap -sTU -O $1
}
m.net4-port-connection-tcp() {
# telnet database.example.com 3306
# $1 ip/host
# $2 port
telnet $1 $2
}
m.net4-port-connection-udp() {
# Danger, uninstall after using nc
# nc 192.168.122.1 -u 80
# $1 ip/host
# $2 port
nc $1 -u $2
}
alias m.net-tshark="sudo tshark"
alias m.net-tshark-GET="sudo tshark -Y 'http.request.method == \"GET\"' "