Skip to content

Instantly share code, notes, and snippets.

@xiazhibin
xiazhibin / t.md
Last active October 23, 2018 07:10
一些统计bash

cat /var/log/nginx/access.log | awk '{print $7}' | sort | uniq -c | sort -r -n |head -n 5

  • uniq 去取重复的行 -c, --count prefix lines by the number of occurrences
  • sort 排序 -r 以相反的顺序来排序 -n 依照数值的大小排序
  • head 显示开头 -n 显示的行数

wc -l 统计行数

du * -hs | sort -hr 查看文件夹大小

cat /dev/null > test.txt 清空文件

@xiazhibin
xiazhibin / common_bash.md
Last active October 14, 2018 14:46
常用bash命令

检测环境变量存不存在

if [ -z ${VAR+x} ]
then
    echo "VAR not exist"
else
    echo "$VAR"
fi
@xiazhibin
xiazhibin / nginx.md
Last active October 16, 2018 08:33
一些nginx的配置
location ~ \.(woff|woff2|ttf|dds|map|js|css|jpg|png|gif|lang|ico|mp4|json) {
        if ($request_uri ~* "^.*a\.js$ ") {
             add_header    Cache-Control  no-store;
        }
        root     /www-data/example1;
	    try_files $uri =404;
}
@xiazhibin
xiazhibin / redis_protocol.sh
Last active January 27, 2019 13:52
将redis cmd转化为redis协议
#!/bin/bash
while read CMD; do
# each command begins with *{number arguments in command}\r\n
XS=($CMD); printf "*${#XS[@]}\r\n"
# for each argument, we append ${length}\r\n{argument}\r\n
for X in $CMD; do printf "\$${#X}\r\n$X\r\n"; done
done < redis_commands.txt