-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathoneline_cmd
849 lines (759 loc) · 28.3 KB
/
oneline_cmd
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
################## networking ##################
# system route table
# Routing tables
#
# Internet:
# Destination Gateway Flags Refs Use Netif Expire
# default 192.168.1.1 UGSc 107 0 en0
# 127 127.0.0.1 UCS 0 0 lo0
# 127.0.0.1 127.0.0.1 UH 8 5362 lo0
# 169.254 link#4 UCS 0 0 en0
# 192.168.1 link#4 UCS 0 0 en0
# 192.168.1.1/32 link#4 UCS 1 0 en0
# 192.168.1.1 ec:88:8f:2d:d4:74 UHLWIir 110 24 en0 1169
# 192.168.1.106/32 link#4 UCS 0 0 en0
#
#
# Kernel IP routing table
# Destination Gateway Genmask Flags MSS Window irtt Iface
# 10.103.11.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
# 169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
# 10.0.0.0 10.103.11.254 255.0.0.0 UG 0 0 0 eth0
#
# Flags: U Indicates route is up;
# G Route is to a gateway;
# H Route is to a host and not a network;
# M Table entry is modified by ICMP redirect message;
# D Route was created dynamically or by ICMP redirect;
netstat -nr
# display network and route
ip route show
ip r
ip addr
ip ro add 10.0.0.0/8 via 10.11.11.254
# add default route
ip route add default via 192.168.1.254 dev eth1
# list rule table
ip rule l
# list rule main table
ip r l t main
# add 11.0.0.0/8 to lookup table 201
ip rule a from 11.0.0.0/8 lookup 201
ip r a 11.0.0.0/8 dev eth0 table 201
ip r a default via 11.17.12.1 table 201
# ip netns usage
sudo ip netns add ns1
sudo ip netns add ns2
sudo ip netns list
sudo ip netns exec ns1 ifconfig lo 127.0.0.1 up
sudo ip netns exec ns1 ifconfig -a
sudo ip netns exec ns2 ifconfig lo 127.0.0.1 up
sudo ip netns exec ns2 ifconfig -a
# create up link peer
sudo ip link add veth1.1 type veth peer name veth1.2
sudo ip link show
sudo ip link set veth1.1 netns ns1
sudo ip link set veth1.2 netns ns2
# rename veth* dev to eth0
sudo ip netns exec ns1 ip link set veth1.1 name eth0
sudo ip netns exec ns2 ip link set veth1.2 name eth0
# ifconfig eth0 ip
sudo ip netns exec ns1 ifconfig eth0 10.0.1.1/24 up
sudo ip netns exec ns2 ifconfig eth0 10.0.1.2/24 up
sudo ip netns exec ns1 ping 10.0.1.2
# add/del vip on local dev(lo:14)
/sbin/ifconfig lo:14 10.11.18.14 broadcast 10.11.18.14 netmask 0xffffffff up && /sbin/route add -host 10.11.18.14 dev lo:14
ip addr del 10.11.18.14/32 dev lo:14
ifconfig lo:14 down
#ifconfig
#ifconfig -a
#ifconfig eth0 up
#ifconfig eth0 down
#ifconfig eth0 172.16.25.125
#ifconfig eth0 netmask 255.255.255.224
#ifconfig eth0 broadcast 172.16.25.63
#ifconfig eth0 172.16.25.125 netmask 255.255.255.224 broadcast 172.16.25.63
#ifconfig eth0 mtu 1500
#ifconfig eth0 promisc
#ifconfig eth0 -promisc
#ifconfig eth0:0 172.16.25.127
#ifconfig eth0:0
#ifconfig eth0:0 down #remove network interface eth0:0
#ifconfig eth0 hw ether AA:BB:CC:DD:EE:FF #change mac address of network interface
#config initcwnd and initrwnd
ip route | while read p; do echo "ip route change $p initcwnd 10 initrwnd 10"; done
#delete bridge
ip link set docker0 down
brctl delbr docker0
#iptables
#iptables [-t table] command [match] [target/jump]
# -t --table: table(filter, nat, mangle, raw)
# -A -D -I -R: chain -L,--lsit,-F,--flush,-Z,-N,-X,-P,-E
# match regx: tcp,udp,icmp,limit,mac,mark,owner,state,tos,ttl
# -j target:(ACCEPT, DROP, REJECT)
iptables -A INPUT -p tcp --dport 80 -m time --timestart 09:00 --timestop 18:00 -j DROP
iptables -A INPUT -s 192.168.1.0/24 -p tcp --dport 22 -j ACCEPT
iptables -t filter -A INPUT -s 192.168.1.1 -j DROP
#------------- network monitoring --------------
#iptraf | tcpdump | tcpflow | ss | netstat
iptraf
#tcpdump
#tcpdump [ -AdDeflLnNOpqRStuUvxX ] [ -c count ]
# [ -C file_size ] [ -F file ]
# [ -i interface ] [ -m module ] [ -M secret ]
# [ -r file ] [ -s snaplen ] [ -T type ] [ -w file ]
# [ -W filecount ]
# [ -E spi@ipaddr algo:secret,... ]
# [ -y datalinktype ] [ -Z user ]
# [ expression ]
# expression (type:net,host,port) (dir:src,dst,src and dst, src or dst) (proto)
#
tcpdump tcp and src 192.168.0.1 and port 80
# 0x4745 : [GE]T -- 0x4854 : [HT]TP
tcpdump -XvvennSs 0 -i eth0 tcp[20:2]=0x4745 or tcp[20:2]=0x4854
tcpdump -XvvnnSs 0 -i any host 10.10.0.20 and port 389
tcpdump -i eth0 port 80 -w -
tcpdump -nnvXSs 0 -c2 icmp
# wireshark filter
# tcp.srcport == 54471 or tcp.dstport == 54471
# tcp.flags.reset == 1
#tcpflow
tcpflow -cp -i eth0 "port 80"
# one line cmd display tcp/ip info.
ss --options --extended --memory --processes --info
ss -an | grep "TIME-WAIT" | awk '{print $NF}' | grep -P "^(\d+\.){3}(\d+):\d+$" | grep -oP "(\d+\.){3}(\d+)" | sort | uniq -c
ss --info sport = :2112 dport = :4057
ss -tan 'sport = :80' | awk '{print $(NF)" "$(NF-1)}' | sed 's/:[^ ]*//g' | sort | uniq -c
# one line cmd for static state of tcp/ip.
netstat -tanl
netstat -pant | awk '/^tcp/ {++state[$6]} END {for(key in state) printf("%-10s\t%d\n", key,state[key])}'
# lookup which process used ip or port to connected.
netstat -antp | grep ip
netstat -antp | grep port
#check smp_affinity:
# Ethernet controller
# MSI-X: Enable+ Count=9 Masked- (Enable+ and Count > 1)
lspci -vvv | less
#check ring buffer
ethtool -g eth0
#check net interface offloading
ethtool -k eth0 #look option
ethtool -K eth0 tso off #set option
ethtool -K eth0 lro off
#dig command usage.
dig [@server] domain [query-type] [query-class] [+query-option] [-dig-option] [%comment]
#lookup dns use local dns service 8.8.8.8
dig www.google.com @8.8.8.8
#get version of bind
dig @8.8.8.8 version.bind chaos txt
dig @ns4.baidu.com txt version.bind chaos
#hide bind version option in named.conf
#option {
# version "I don't tell you my version.";
#};
nslookup [-option...] [host-to-find | - [server]]
named-checkconf [-jvz] [-t directory] [filename]
################## kernel compile ##################
# BIOS -> MBR
# grub -> kernel(bzImage) /boot/vmlinuz-3.2.0-74-generic-pae
# -> initrd.img /boot/initrd.img-3.2.0-74-generic-pae
# initrd.img: some drivers and kernel module
#### compile a new kernel from source code
#get a template .config file
cp config-3.2.0-74-generic-pae .config
#run make menuconfig need some package: ncurses-devel
#(ubuntu:sudo apt-get install libncurses5-dev)
#modify the .config file
make menuconfig
#compile the kernel
make bzImage
#compile the modules
make modules
make modules_install
#install kernel: cp arch/i386/boot/bzImage /boot/vmlinuz-xxx && mkinitrd /boot/initrd-xxx.img xxx && vi /boot/grub/grub.conf
make install
############# command ##################
# one line cmd display dir file.
ls -lR | grep -v total | awk 'BEGIN { OFS="\t"; ORS="\n-->"} {print $1,$3,$NF}'
# find failure of soft links
find . -type l | perl -lne 'print if ! -e'
# sort filename by column 1
sort -k1,1n filename
#static memory for process
ps -eo fname,rss | awk '{arr[$1]+=$2} END {for (i in arr) {print i,arr[i]}}' | sort -k2 -nr | column -t
ps aux | sort -rnk 3 | head -20
ps aux | sort -rnk 4 | head -20
#RAID0
mdadm -C /dev/md0 -a yes -l 0 -n 2 /dev/sdb /dev/sdc
mdadm -D --scan > /etc/mdadm.conf
mkfs.ext4 /dev/md0
mount /dev/md0 /mnt
#mdadm -C /dev/md0 -a yes -l 1 -n 2 /dev/sdb /dev/sdc
#mdadm -C /dev/md0 -a yes -l 5 -n 3 /dev/sdb /dev/sdc /dev/sdd
#mdadm -C /dev/md0 -a yes -l 5 -n 3 -x 1 /dev/sdb /dev/sdc /dev/sdd /dev/sde
#-x 1: /dev/sde is backup disk when error happen.
#mdadm -C /dev/md0 -a yes -l 6 -n 4 /dev/sdb /dev/sdc /dev/sdd /dev/sde
#mysql
#mysql -u* -h* -p -P3306 -e "show databases" | sed -n '2,$p' | xargs -l DB 'mysqldump DB > DB.sql';
#mysqldump --add-drop-table -uroot -p nowait > backupfile.sql
#mysql -uroot --default-character-set=utf8 -p
#
#./bin/mysqld --verbose --help | grep -A 1 'Default options'
#${CURDIR}/bin/mysqld_safe --basedir="${CURDIR}" --datadir="${CURDIR}/data/mysql"
#
#alter table ip add index idx_ip(ip);
#look for system perfermace.
#cmd interval count
vmstat 2 10
iostat 2 10
mpstat 2 10
slabtop
slabtop -o | grep -E '(^ OBJS|tw_sock_TCP|tcp_bind_bucket)'
iostat -dx 1 20
iotop
## perf usage
perf top
perf stat ./program
perf stat -e raw_syscalls:sys_enter ls
#### record and report
perf record –e cpu-clock -g ./program
perf report
perf record -e raw_syscalls:sys_enter ls
perf report
perf trace -p pid
#### four useful perf command. perf help commnd.
perf stat [-e <EVENT> | --event=EVENT] [-a] <command>
perf stat [-e <EVENT> | --event=EVENT] [-a] — <command> [<options>]
perf record [-e <EVENT> | --event=EVENT] [-l] [-a] <command>
perf record [-e <EVENT> | --event=EVENT] [-l] [-a] — <command> [<options>]
perf report [-i <file> | --input=file]
perf list [hw|sw|cache|tracepoint|pmu|event_glob]
#### FlameGraph https://github.com/brendangregg/FlameGraph
perf record -F 99 -a -g -- sleep 60
perf script | ./stackcollapse-perf.pl > out.perf-folded
./flamegraph.pl out.perf-folded > perf-kernel.svg
strace -T -r -c -p $PID
##### ltrace - a library call tracer
ltrace -cp $PID
tr -c "[:digit:]" " " < /dev/urandom | dd cbs=$COLUMNS conv=unblock | GREP_COLOR="1;32" grep --color "[^ ]"
#display one line '#' with screen width
printf "%`tput cols`s" | tr ' ' '#'
#install django use douban mirror.
pip install django --index-url http://pypi.douban.com/simple
# (?=exp) pre match
# (?!exp) pre not match
# (?<=exp) post match
# (?<!exp) post not match
# regx (?<=<(\w+)>).*(?=<\/\1>) for html tag
# checks to [192.168.32.208]: host [32.208 xuebao] not found
# match [xxx] and [xxx] content.
grep -Po '(?<=\[)[^]]+'
ifconfig | grep -oP '(?<=inet addr:).*(?= Bcast:)' | xargs -n 4
# awk usage
# pattern { action statements }
# function name(parameter list) { statements }
# awk '/pattern/ { action }' and '{if($1==pattern) action}'
# tail -f /var/log/apache2/access.log | awk -W interactive '!x[$1]++ {print $1}'
ps aux | awk '{if($1=="root") print $(NF-1)}'
# insert line before match line
sed -i '/ - git branch/i\ - git rev-parse HEAD' file
# append line after match line
sed -i '/ - git branch/a\ - git rev-parse HEAD' file
# delete lines between match line.
sed -i '/xxxxxx/,/yyyyyy/d' file
# match lines between (22 and 55)
awk '/22/{p=1}/55/{p=0}p' file
awk '/22/,/55/{if($0 !~ /55/) print $0}' urfile
# sed usage
# -i[SUFFIX]: backup extension.
# sed -i 's/100000/500000/' edit-filename
#
# match "cloud-u*" append next line to current line.
# cat l.resourse | grep -A 2 "^cloud" | grep -v total | sed '/cloud-u*/{N;s/,*\n/ /}' | grep -v -- '--' | awk '{print $1, $8}' | sort -k 1
#shopt -s histappend; history -a
#history -c ;>/root/.bash_history
# redis
#$./redis-cli --latency -h '127.0.0.1' -p '6379'
#$./redis-cli
#127.0.0.1:6379> info
#127.0.0.1:6379> info memory
#127.0.0.1:6379> slowlog get
#127.0.0.1:6379> config set slowlog-log-slower-than 5000
#127.0.0.1:6379> info clients
#127.0.0.1:6379> config set maxclients 10000
#127.0.0.1:6379> monitor
# rpm usage
# rpm -qa --nosignature | grep elastic # skip signature query
# rpm -e -vv --nosignature elasticsearch-1.5.2-1 # skip signature uninstall
# cd /var/lib/rpm && rm -rf __db* # rm lock file for rpm no respose.
# rpm -ivh -vv --force --nosignature elasticsearch-1.5.1.rpm
# rpm -qa | grep -i maria
# rpm -e maria.rpm
### mac install cocoapods
#pod guides: http://guides.cocoapods.org/
#gem install cocoapods
#pod install --verbose
################## git usage ##################
#git rollback version
$git reset --hard 931c6a6
## git reset author info.
$git commit --amend --reset-author
#look a file edit log for every commit.
$git log -p filename
#
#look a file commit log of every line.
$git blame
## git make patch file and apply patch
$git checkout Fix
# edit code and commit.
$git format-patch -M master
#
$git patch "git format-patch"
$git am filename.patch
## develop at ansible
$git clone https://github.com/soarpenguin/ansible.git ansible
$cd ansible && git remote add ansible https://github.com/ansible/ansible.git
$git checkout -b bugfix ansible/devel && git pull
# edit code and commit
$git push origin bugfix:bugfix
## delete local and remote branch
$git branch -D <branch_name> # git branch -d <branch_name>
$git push origin :<branch_name> # git push origin --delete <branch_name>
$git fetch --all --prune # clean branch when deleted on other machines
#github pull request
#git clone git recursive.
$git clone --recursive https://github.com/XiaoMi/open-falcon.git
$git pull --recurse-submodules
#
$git submodule add https://github.com/XiaoMi/open-falcon.git open-falcon
$git submodule update --init --recursive
#find top 5 max file in git mirror.
$git rev-list --objects --all | grep "$(git verify-pack -v .git/objects/pack/*.idx | sort -k 3 -n | tail -5 | awk '{print$1}')"
#rename last commit author.
$git commit --amend --author='soarpenguin <soarpenguin@gmail.com>'
#add and remove git global config
$git config --global --add configName configValue
$git config --global --unset configName
#http://danielkummer.github.io/git-flow-cheatsheet/
#install git flow: https://github.com/petervanderdoes/gitflow-avh
$git flow --help
#screen -c ~/.screenrc -D -RR screenname
#screen -drUA screenname
# remove and destroy a screen session.
#screen -wipe screenname
#vim use pointed vimrc.
# vim -u ~/vimrc filename
#vim cmd find symble of funcname and display all symble info.
#:cs find s funcname
#:cw
#cat json.txt | python -m json.tool
#python -m SimpleHTTPServer
#python -m py_compile *.py
#python -m compileall dirname
#python -m pdb *.py
#/usr/local/bin/inotifywait -mrq --timefmt %d/%m/%y %H:%M --format %T %w%f -e modify,delete,create,attrib /etc/sysctl.conf
#
#remove redundant zero of 010.105.028.072, get 10.105.28.72
#head ip.txt | perl -F'\.' -alne 'print join ".", map{sprintf "%d",$_}@F'
#
#nohup mesos-slave --master=zk://10.10.11.3:2181,10.103.11.4:2181,10.10.11.5:2181/mesos \
# --log_dir=/opt/mesos-slave/log --work_dir=/opt/mesos-slave/data \
# --appc_store_dir=/opt/mesos-slave/store/appc </dev/null >/dev/null 2>&1 &
#
#nohup mesos-master --zk=zk://10.10.11.3:2181,10.10.11.4:2181,10.10.11.5:2181/mesos \
# --log_dir=/opt/mesos-master/log --work_dir=/opt/mesos-master/data \
# --no-hostname_lookup --cluster="mesoscluster" --quorum=2 </dev/null >/dev/null 2>&1 &
#
#
#$ sudo apt install virtualenv
#$ cd dst/ && virtualenv ./env
#$ ./env/bin/pip install -r requirements.txt
#$ ./env/bin/pip install --upgrade git+https://github.com/mpetazzoni/kazoocli
#$ ./env/local/bin/kz
#
#$ pip install --download <DIR> -r requirements.txt
#$ pip install --no-index --find-links=[file://]<DIR> -r requirements.txt
#
# yum install download only
#yum install -y yum-plugin-downloadonly
#yum install --downloadonly --downloaddir=<directory> <package>
#
# update linux system time
# date -s "20160107 18:57"
# hwclock -w
#
# cut -d" " -f 1,2,42 /proc/*/stat | sort -n -k +3
#
# axel -n 99 http://42.62.11.196:81/openSUSE-Leap-42.1-DVD-x86_64.iso
#
# sudo brew install mtr
# sudo /usr/local/Cellar/mtr/0.86/sbin/mtr -h
# sudo /usr/local/Cellar/mtr/0.86/sbin/mtr --aslookup www.baidu.com
#
# # nc send file
# nc -l 1234 > filename.out
# nc host.example.com 1234 < filename.in
# # nc send dir
# tar -cf - * | nc -l 4444
# nc host.example.com 4444 | tar -xf -
#
# sh difference of '[' and '[['.
# http://mywiki.wooledge.org/BashFAQ/031
#
# trap '(read -p "[$BASH_SOURCE:$LINENO] $BASH_COMMAND?")' DEBUG
#dmidecode -t 1 | grep -iP "manu|product"
#last reboot
# nmap usage.
# sudo nmap -sS -sU -p 53 ns4.baidu.com
# nslookup usage.
# ➜ bash-scripts git:(master) ✗ nslookup
# > server ns4.youku.com
# Default server: ns4.youku.com
# Address: 60.217.254.9#53
# >
# >
# > zhifu.youku.com
# Server: ns4.youku.com
# Address: 60.217.254.9#53
#
# zhifu.youku.com canonical name = m6-yk-zhifu.youku.com.
# Name: m6-yk-zhifu.youku.com
# Address: 43.250.15.34
## govendor
# go get -u -v github.com/kardianos/govendor
# Setup your project.
# cd "my project in GOPATH"
# govendor init
## Add existing GOPATH files to vendor.
# govendor add +external
## View your work.
# govendor list
## Look at what is using a package
# govendor list -v fmt
## Specify a specific version or revision to fetch
# govendor fetch golang.org/x/net/context@a4bbce9fcae005b22ae5443f6af064d80a6f5a55
# govendor fetch golang.org/x/net/context@v1 # Get latest v1.*.* tag or branch.
# govendor fetch golang.org/x/net/context@=v1 # Get the tag or branch named "v1".
## Update a package to latest, given any prior version constraint
# govendor fetch golang.org/x/net/context
## Format your repository only
# govendor fmt +local
## Build everything in your repository only
# govendor install +local
## Test your repository only
# govendor test +local
#
# govendor list [options] ( +status or import-path-filter )
# govendor {add, update, remove} [options] ( +status or import-path-filter )
# govendor migrate [auto, godep, internal]
# govendor [fmt, build, install, clean, test, vet, generate] ( +status or import-path-filter )
#
# go list
# go list ...
# go list ...xml...
# go list -json hash
# go list -f '{{join .Deps " " }}' strconv
# go list -f '{{.ImportPath}} -> {{join .Imports " "}}' strconv
# godoc -http :8000
#
# # build current project
# go build ./...
# # print the commands build current project but do not run them.
# go build -n ./...
# go install -a -v ./...
# go get -v -u -x github.com/hyper-carrot/go_lib
# # disable inline and compile opt
# go build -gcflags "-N -l" -o test test.go
# # get asm code
# go build -gcflags -S test.go
# GOARCH=amd64 go tool compile -S -N -l defer.go
# # get asm code
# go tool objdump -s "runtime\.init\b" test
#
# go build -gcflags "-N" -o test test.go
# go tool objdump -S -s "main\.test" test
#
# #### go tool usage.
# go tool asm [options] file.s
# go tool cgo -- [compiler options] file.go ...
# go tool compile [options] file.go...
# go tool cover -html=c.out -o coverage.html
# go tool cover -mode=set -var=CoverageVariableName program.go
# go tool dist test
# go tool doc json
# go tool fix [-diff] [-r fixname,...] [-force fixname,...] [path ...]
# go tool link [options] main.o
# go tool nm [-n] [-size] [-sort order] [-type] file...
# go tool objdump [-s symregexp] binary [start end]
# go tool pack op file.a [name....]
# go tool pprof [options] [binary] <profile source> ...
# go tool tour
# go test -trace=trace.out pkg
# go tool vet [flags] directory...
# go tool vet [flags] files...
# go tool yacc [-o output] [-v parsetable] input
# go pprof usage
# ## import _ "net/http/pprof"
# ## http.ListenAndServe(":8080", nil)
# $ go tool pprof http://localhost:8080/debug/pprof/heap
# $ go tool pprof http://localhost:8080/debug/pprof/profile
# $ go tool pprof http://localhost:8080/debug/pprof/block
# $ go tool pprof cmd(program-name) http://localhost:8080/debug/pprof/heap
#
# $ brew install graphviz
# $ go tool pprof -svg elastic-ecm.prof.249944 > cpu-1.svg
# CPU
# ### example: write cpuprofile info to cprof.
# $ go test -run=none -bench=ClientServerParallel4 -cpuprofile=cprof net/http
# ###### the most useful ones are: --text, --web and --list
# $ go tool pprof --text http.test cprof
# $ go tool pprof --text mybin http://myserver:6060/debug/pprof/profile
#
# $ go tool cover -html=c.out
# $ go test -run=Coverage -coverprofile=c.out gopl.io/cn7/eval
# $ go test -v -run=Coverage gopl.io/cn7/eval
#
# $ go test -bench=.
# $ go test -bench=. -benchmem
# #### go-swagger usage
# $ go get -u github.com/go-swagger/go-swagger/cmd/swagger
# $ swagger generate model -f "./swagger.yml" -t "./apis" -m types
# $ swagger serve --host=0.0.0.0 --port=2399 --no-open ./docs/swagger.json
# $
# #### swag usage
# $ swag init
########
# Recovery rm -rf file
# ➜ sudo apt-get install extundelete
# ➜ df -Th
# Filesystem Type Size Used Avail Use% Mounted on
# udev devtmpfs 3.9G 4.0K 3.9G 1% /dev
# tmpfs tmpfs 791M 1.2M 790M 1% /run
# /dev/sda4 ext4 128G 27G 95G 22% /
# none tmpfs 4.0K 0 4.0K 0% /sys/fs/cgroup
# none tmpfs 5.0M 0 5.0M 0% /run/lock
# none tmpfs 3.9G 140K 3.9G 1% /run/shm
# none tmpfs 100M 28K 100M 1% /run/user
#
# ➜ sudo extundelete --restore-all /dev/sda4
#
#########
## create rootfs under ubuntu.
#Create the blank image file using dd; this example creates a 1GB image; use seek=3072 for 3GB or seek=2048 for 2GB etc.:
# dd if=/dev/zero of=ubuntu-arm.img bs=1MB count=0 seek=1024
#Create linux filesystem on the newly created image:
# mkfs.ext4 -F ubuntu-arm.img
#(You might want to pass some extra flags to mkfs to tweak the reserved blocks, labels, or other filesystem options.)
#Loop mount the new image:
# sudo mount -o loop ubuntu-arm.img /mnt
#Extract the rootfs tarball inside the mounted dir and umount:
# sudo tar -C /mnt -zxf armel-rootfs-200904151837.tgz
# sudo umount /mnt
#########
# apparmor usage: https://wiki.ubuntu.com/AppArmor
# Start : sudo /etc/init.d/apparmor start
# Stop : sudo /etc/init.d/apparmor stop
# reload: sudo /etc/init.d/apparmor reload
# Show status: sudo /etc/init.d/apparmor status
# Parser profile: sudo apparmor_parser -r /etc/apparmor.d/<profile>
# Generate profile: sudo genprof firefox
#
#List mounted filesystem under this system.
# $ lsblk -f
#
#########
# ipvsadm -C // clear vip table record.
# ipvsadm -L --timeout // Timeout (tcp tcpfin udp): 30 5 60
# // 查看超时时间1、tcp session时间 2、连接断开后保持时间 3、udp超时时间
# ipvsadm -L -n // 查看
# ipvsadm -C // 清空
# ipvsadm -L -n -t 10.10.5.0:3306 // 查看某一个VIP的链接数(注:一定要加端口)
# ipvsadm -L -n -t 10.10.5.0:3306 --stats // 查看某一个VIP连接数与流量
# ipvsadm -L -n -t 10.10.5.0:3305 --stats --exact // 查看某一个VIP的连接数(--exact参数作用是显示更为精准)
# ipvsadm --set 30 5 60 // Timeout (tcp tcpfin udp): 30 5 60
# ipvsadm -ln -c
#
# ///////// http://zh.linuxvirtualserver.org/node/5
# ipvsadm -A|E -t|u|f virutal-service-address:port [-s scheduler] [-p [timeout]] [-M netmask]
# ipvsadm -D -t|u|f virtual-service-address
# ipvsadm -C
# ipvsadm -R
# ipvsadm -S [-n]
# ipvsadm -a|e -t|u|f service-address:port -r real-server-address:port [-g|i|m] [-w weight]
# ipvsadm -d -t|u|f service-address -r server-address
# ipvsadm -L|l [options]
# ipvsadm -Z [-t|u|f service-address]
# ipvsadm --set tcp tcpfin udp
# ipvsadm --start-daemon state [--mcast-interface interface]
# ipvsadm --stop-daemon
# ipvsadm -h
#
### bonding
# $ modprobe --first-time bonding
# $ modinfo bonding
# $ cat > /etc/sysconfig/network-scripts/ifcfg-bond0 <EOF
# DEVICE=bond0
# BOOTPROTO=static
# ONBOOT=yes
# TYPE=Ethernet
# NETWORKING_IPV6=no
# HWMAC=xx:xx:xx:xx:xx
# EOF
# $ ifenslave bond0 eth1
#
# vconfig add eth0 6
# ifconfig eth0.6 10.10.6.51 netmask 255.255.255.0 up
# ifenslave bond0 eth1
# ip ro add 10.0.0.0/8 via 10.10.6.254
#
### make vlan tag
# 1. edit /etc/sysconfig/network-scripts/ifcfg-eth0
# IPADDR=
# 2. add tag
# vconfig add eth0 5
# ifconfig eth0.53 10.10.5.1 netmask 255.255.255.0
# 3. restart eth0 interface
# /etc/init.d/network restart; bash /etc/rc.local;
#
#Google grpc proto usage.
# protoc document:
# https://developers.google.com/protocol-buffers/docs/proto3
# https://developers.google.com/protocol-buffers/docs/reference/go-generated
#
# 1. install protoc cmd
# https://github.com/google/protobuf/releases
# 2. install golang protoc-gen-go cmd
# $ go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
# 3. protoc cmd usage, under proto files path.
# $ $GOPATH/bin/protoc --proto_path="~/golib/bin/protoc_include/" -I=./ --go_out=plugins=grpc:. *.proto
#
#centos 7 set hostname
# hostnamectl set-hostname a01.host.com --static
# hostnamectl set-hostname a01.host.com
# hostnamectl status
#
#Upstart service
$sudo /sbin/initctl stop strong-pm
$sudo rm /etc/init/strong-pm.conf
$sudo /sbin/initctl reload-configuration
$sudo rm -rf /var/lib/strong-pm
#
#Systemd service
$sudo /usr/bin/systemctl stop strong-pm.service
$sudo /usr/bin/systemctl disable strong-pm.service
$sudo rm /etc/systemd/system/strong-pm.service
$sudo /usr/bin/systemctl daemon-reload
$sudo rm -rf /var/lib/strong-pm
#
#List all ld library
$ ldd $(which /usr/local/nginx/sbin/nginx)
#
#Rsync from local src to dest.
rsync -av --itemize-changes "src/" "dest/"
rsync -vzrtopgu /Data/scripts/ /tmp/back_srcipt/
#
#Check port ":8080".
#check_tomcat=`(/usr/sbin/ss -ln4 sport = :8080; /usr/sbin/ss -ln6 sport = :8080) | grep -c ":8080"`
#
#mvn usage
$ mvn -v
$ mvn compile
$ mvn package
$ mvn install
$ mvn test
$ mvn dependency:tree
$ mvn clean compile install -Plocal
$ mvn spring-boot:run
$ mvn archetype:generate -DgroupId=com.yiibai -DartifactId=NumberGenerat -DinteractiveMode=false
$ mvn archetype:create -DgroupId=packageName -DartifactId=webappName -DarchetypeArtifactId=maven-archetype-webapp
$ mvn dependency:tree -Dverbose
#gradle usage
$gradle assemble
$gradle build
$gradle -m build #just run not real build
$gradle build -x test
$gradle build -x test --parallel
$gradle tasks
#
##java cmd option: 1) Standard 2) -X 3) -XX
$java -version #mixed mode
$java -Xint -version #interpreted mode
$java -Xcomp -version #compiled mode
$java -X #display all -X options
$java -XX:+<option>/-XX:-<option> -XX:<option>=<number> -XX:<option>=<string>
$java -XX:+PrintCommandLineFlags -version
$java -Xms128m -Xmx2g MyApp #set min/max heap size
$java -XX:InitialHeapSize=128m -XX:MaxHeapSize=2g MyApp
$java -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp/heapdump.hprof -XX:OnOutOfMemoryError ="sh ~/cleanup.sh" MyApp
$java -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:<file> MyApp #open gc log
$jps -m -l #show all process stats on jvm
$jps -v -l #show main class name and jvm parameter started.
$jinfo 21711
#
$ps -ef | grep mrf-center | grep -v grep
#root 21711 1 1 14:47 pts/3 00:02:10 java -jar mrf-center.jar
$printf "%x\n" 21711
$jstack 21711 | grep 54ee
#jstat [ generalOption | outputOptions vmid [interval[s|ms] [count]] ]
## vmid http://docs.oracle.com/javase/6/docs/technotes/tools/share/jstat.html
## Virtual machine identifier, a string indicating the target Java virtual machine (JVM). The general syntax is
## [protocol:][//]lvmid[@hostname[:port]/servername]
$jstat -class 10532
$jstat -gc 10532
$jstat -gccapacity 10532
$jstat -gcutil 10532
$jstat -gcutil 10532 250 7 #pid, 250 millisecond intervals, 7 samples
$jstat -gcnew -h3 10532 250
$jstat -gccause 10532
$jstat -gcnew 10532
$jstat -gcnewcapacity 10532
$jstat -gcold 10532
$jstat -gcoldcapacity 10532
$jstat -compiler 10532
$jstat -printcompilation 10532
#
$jmap -permstat pid
$jmap -heap 21711
$jmap -histo:live 21711 | more
$jmap -dump:format=b,file=/tmp/dump.dat 21711
$truncate -s 100M filename
$dd if=/dev/null of=test.log
#openstack
#https://github.com/int32bit/openstack-workflow
#ceph
#http://download.ceph.com/rpm/el6/x86_64/
## sleep 3 sec and kill current pid when timeout.
#$sleep 3 && kill -9 -- -$$ &
## mkdir dirname and cd to dirname
#$mkdir dirname && cd $_
$sudo -v && wget -nv -O- https://download.calibre-ebook.com/linux-installer.py | sudo python -c "import sys; main=lambda:sys.stderr.write('Download failed\n'); exec(sys.stdin.read()); main()"
$brew install autojump
## jq kill pkill pgrep ag nc
## vagrant usage
$ brew cask install vagrant
$ vagrant init
$ vagrant up
$ vagrant reload
$ vagrant ssh
$ vagrant halt vmname
$ vagrant status
$ vagrant destroy vmname
## asciinema https://asciinema.org/
## https://asciinema.org/docs/usage
$ brew install asciinema
$ asciinema rec # typing exit or hitting Ctrl-D
$ asciinema auth
## install muti version of gcc and g++, can update-alternatives.
$ sudo apt-get install gcc-4.8 g++-4.8
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8
$ sudo update-alternatives --config gcc
du -h -x --max-depth=1
dmesg_with_human_timestamps () {
$(type -P dmesg) "$@" | perl -w -e 'use strict;
my ($uptime) = do { local @ARGV="/proc/uptime";<>}; ($uptime) = ($uptime =~ /^(\d+)\./);
foreach my $line (<>) {
printf( ($line=~/^\[\s*(\d+)\.\d+\](.+)/) ? ( "[%s]%s\n", scalar localtime(time - $uptime + $1), $2 ) : $line )
}'
}
alias dmesg=dmesg_with_human_timestamps