-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.snippet
107 lines (107 loc) · 18.2 KB
/
.snippet
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
wget -S # spider
/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -s # macOS WiFi
echo | nc 8.8.8.8 53 # test network by nc
du -d 1 -h .git/ # calc sizes in .git
du -d 1 -h -I ".git" . # calc sizes current exclude ".git"
curl -I localhost # curl only header
cat <<EOF > text.txt # redirect heredoc
tcpdump -nn src host 0.0.0.0 and not port 22 and not port 3306 # tcpdump 1
tcpdump -nn src port 80 or src port 443 # tcpdump 2
dig -x localhost # reverse w/ dig
rg foo -g '!*.min.js' # exclude w/ rg
rg foo -g '*.min.js' # include w/ rg
WAIT=$(( RANDOM %= 30 )) sleep $WAIT && echo "foo" # jitter
perl -i -pe 's/foo/bar/' text.txt # overwrite replacement by PCRE
cut -d' ' -f1,3 # cut
history | cut -d " " -f 4-11 # cut numbers of history
find . -type f -regextype posix-egrep -regex ".*.(csv|txt)" ! -regex ".*./ruby/2.0/.*" # find w/ regex
find . -type f | grep -e "\.txt$" # find w/ egrep
cat readme.md | awk '!/^$/' # remove empty lines by awk
[ -f `which yarn` ] && echo hoge # if by bash
if [ "" != `which yarn` ]; then echo 1; elif [ "" != `which npm` ]; then echo 2; else echo 3; fi # if-else by bash
tree -d -L 2 -I "node_modules" # tree w/ ignoring
ls | grep template | awk -F '.' '{print "."$2"."$3"."$4}' | xargs -I % -L 1 mv "template"% "tmpl"% # rename from 'template' to 'tmpl'
lt -L 2 -a -I 'node_*|.git|.circleci' # ls w/ tree by exa w/ --level and --ignore-glob option
eval $(aws ecr get-login --no-include-email --region ap-northeast-1) # docker login w/ ecr
perl -lnae 'print $F[1]' log.txt # parse file by default "white space" delimiter
perl -F, -lnae 'print $F[1]' log.txt # parse file by "comma" delimiter
perl -F/,/ -lane 'print @F[1,2]' data.csv # parse csv and print multi columns by "comma" delimiter
docker run -d ubuntu:16.04 tail -f /dev/null # run docker w/ ubuntu as deamon
for i in `seq 1 10`; do echo $i && sleep 1; done # seq and sleep
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes -subj "/C=GO/ST=AAA/L=AAA/O=AAA/OU=IT Department/CN=AAA.org" # create self signed certification
while true; do { echo -e 'HTTP/1.1 200 OK\r\n'; } | nc -l 8000; done # run dummy http server in 8000
ssh BASTION_SERVER -L 8080:DB_SERVER:3306 -N # -f (<= backgroud flag) # ssh forwarding (=8080=> local =22=> bastion =3306=> db)
tmux swap-window -t 1 # swap window on tmux
git branch | colrm 1 2 # list branch names
openssl rand -base64 24 # make random password easily
cat /dev/urandom | tr -dc "[:alnum:]" | fold -w 12 | head -n 10 # make random password
cat /dev/urandom | tr -dc "[:graph:]" | tr -d "1Il0O~^" | fold -w 12 | head -n 10 # make random password strongly
fd -0 | xargs -0 -I % echo % # use fd and null separate in xargs
netstat -antp # [GNU] show relationship of ip/port and process
gss | sed -e "s/^...\(.*\)$/'\1'/" |xargs rm -f # delete specific files in git by sed
curl -k -L -o /usr/local/bin/BINARY http://fqdn/BINARY # download binary from url by curl
shasum -a 256 /path/to/file # check sum by sha256
shasum -a 256 /path/to/file | cut -d" " -f1 | grep -c -E "^796d8b936bca76f3f344d105883e45fbfb755af313b66ad7c163ccca7d295a60$" # check sum by sha256 w/ cut and grep
aws iam get-role --role-name dumb-dummy-role --query "Role.RoleId" --output text # get IAM Role ID by awscli
dstat --top-cpu-adv # dstat: spiked cpu w/ PID
dstat --top-io --top-bio # dstat: spiked cpu, blocking io
dstat --top-cpu --top-cputime # dstat: spiked cpu
dstat --top-io-adv --top-bio-adv # dstat: io, blocking io w/ PID
echo {roleA,roleB,roleC} | xargs -L 1 -I % aws iam get-role --role-name % --query "Role.[RoleName,RoleId]" --output text # extract AWS RoleId and RoleName by xargs
echo 'abcde' | awk '{print substr($0, index($0, "b"))}' # substr w/ index(str, start, end) by awk
echo 'abcde' | awk '$0 ~ /b.*/' # match shorthand and print by awk
echo 'abcde' | awk 'match($0, /b.*/) {print RSTART, RLENGTH}' # match w/ ReservedVar of RSTART/RLENGTH by awk
echo 'abcde' | awk 'match($0, /b.*/) {print substr($0, RSTART, RLENGTH)}' # substr and match w/ ReservedVar of RSTART/RLENGTH by awk
echo 'abcde' | grep -o 'b.*' # extract matched string by grep
ccrypt -e filename # 暗号化 by ccrypt
ccrypt -c -d filename > decripted-file # 復号 by ccrypt
TZ=UTC date '+%Y%m%dT%H%M%SZ' # Print date as UTC timestamp
ffmpeg -i input.mov -r 30 output.gif # .mov to .gif in macOS by ffmpeg
sed -e 's/\x0/\n/g' /proc/%PID%/environ # visible proc environ
tcpdump -nn -l -i eth0 port 53 | tee 53.log # tcpdump w/ tee using `-l`
netstat -p udp # [BSD] show udp protocol
netstat -a -n -u # [BSD] show udp and ips as static adress
lsof -i:<PORT> # show process by pid
curl -s http://inet-ip.info # check my ip (1)
curl checkip.amazonaws.com # check my ip (2)
ip -r a # ip a (Linux only)
echo $PATH | /usr/bin/sed 's/:/\'$'\n/g' # print path
patch -p0 < diff.patch # apply patch at same dir
netstat -l # port check 1 / リッスンポートを一覧表示する
ss -lntu # port check 2 / リッスンポートを一覧表示する
sudo nmap -n -PN -sT -sU -p- localhost # port check 3 / リッスンポートを一覧表示する
sudo lsof -i # port check 4 / 使われているネットワークファルを一覧表示
tar zcvf backup.tar.gz filepath1 filepath2 # tar compress gzip
tar zxvf backup.tar.gz # tar decompress gzip
tar jcf backup.tar.bz2 filepath1 filepath2 # tar compress bzip2
tar jxf backup.tar.bz2 # tar decompress bzip2
openssl s_client -connect www.example.com:443 -tlsextdebug # debug openssl
openssl rand 107324 > test.txt # fill the file by random binaries (openssl / pseudo random)
dd if=/dev/urandom of=test.bin bs=1m count=1 # fill the file by random binaries (dd / real random)
dd if=/dev/zero of=test.bin bs=1m # fill the file by zero
fd chrome | fzy | xargs vim # fd and fzy
awk 'END{print NR}' filename # count file lines by awk (`wc -l` is count of \r\n )
date +%s # get unix timestamp
echo -e "\033[32m green \033[00m , \033[31m red \033[00m , \033[36m cyan \033[00m , \033[33m yellow \033[00m" # color code
diff -ybBw # useful diff
diff <(grep -v -E '^\s*#' a.txt | grep -v '^$') <(grep -v -E '^\s*#' b.txt | grep -v '^$') # diff ignoring comment out and white space
(grep -v -E '\s*#' a.txt | grep -v '^$') | (grep -v -E '\s*#' b.txt | grep -v '^$' | diff -b /dev/fd/3 - >./prediff 2>&1) 3<&0 # diff ignoring comment out and white space by POSIX
aws ec2 describe-instances --filter "Name=instance-state-name,Values=running" --query 'Reservations[].Instances[].{InstanceId:InstanceId,PublicIpAddress:PublicIpAddress,Tags:Tags[?Key==`Name`].Value|[0]}' --output text # custom describe-instances
aws ec2 describe-instances | jq -r '.Reservations[] | .Instances[] | select(.State.Name == "running") | [ .InstanceId, (.Tags[] | select(.Key == "Name")).Value ] | @csv' # custom describe-instances w/ jq
strace -c -e write,open,read,close -T -tt ./binary # strace / -c / -e / -T / -tt
git archive HEAD | docker build - # build with same case between gitignore and dockerignore
git show $REVISION:$FILENAME # How to get just one file from another branch
nc -u $HOSTNAME $PORT # check udp
nc -s $SRC_IP -p $SRC_PORT $DEST_HOSTNAME $DEST_PORT # check udp by specific ip and port
nc -lu 10000 # launch udp server by port:10000
strace -p $PORT; readlink /proc/$PORT/fd/$FD; netstat -ane | grep $SOCKET; # analyze network I/O blocking
go build -i # dependency caching at go build
go build -x # debugging at go build
mpstat -P ALL 1 # view multi cpu stat
pidstat 1 # view cpu stat per process
iostat -xz 1 # view I/O performance per block device
curl -s -L https://github.com/mruby/mruby/pull/605.patch | git am - # merge remote pull request from github by curl
curl -s -L https://github.com/masuidrive/mruby/commit/70b422a6f240a201993e75935b55a8dd497eb098.patch | git am - # cherry-pick remote pull request from github by curl
vim --startuptime /tmp/startuptime.txt
ssh-keygen -t ed25519 -f ~/.ssh/filename # generate ssh key
git checkout origin/master -- path/to/file # restore file or dir from a specific branch