Skip to content

Instantly share code, notes, and snippets.

@PoplarYang
Last active November 22, 2019 02:09
Show Gist options
  • Save PoplarYang/4acf5671e9b5f922903ba8d56ecc8434 to your computer and use it in GitHub Desktop.
Save PoplarYang/4acf5671e9b5f922903ba8d56ecc8434 to your computer and use it in GitHub Desktop.
awk '{$5~/status/}{now=strftime("%T", $3/10000000);print now}' ky | sort | uniq -c | awk 'BEGIN{sum=0;count=0}{sum+=$1;count++}END{print sum/count}'
# 1 获取随机8位字符串
echo $RANDOM | md5sum | cut -c 1-8
openssl rand -base64 4
cat /proc/sys/kernel/random/uuid | cut -c 1-8
# 2 获取8位随机数字
# cksum:打印CRC效验和统计字节
echo $RANDOM | cksum | cut -c 1-8
cat /proc/sys/kernel/random/uuid | cksum | cut -c 1-8
# 3 设置密码
echo $PASS | passwd --stdin $USER &> /dev/null
# 4 判断状态码
curl -o /dev/null --connect-timeout 3 -w "%{http_code}" $IP
# 5 下载
wget -T 10 --tries 3 qq.com
# 6 抓包工具
tcpflow -ci all host rsf.qbox.me
# 7 非交互式生成 sshkey
ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''
# 8 创建临时文件或者目录
mktemp file.XX 文件
mktemp -d file.XX 目录
# 9 错误重定向
ls /usr/share/doc > out.txt 2>&1
ls /usr/share/doc &> out.txt
# 10
cp改变文件的属性(属主属主/时间戳)
mv改变文件的名称,不改变时间戳和inode
cat -b只给有文本的行加行号
# 11 systemctl
systemctl is-enabled servicename.service #查询服务是否开机启动
systemctl enable *.service               #开机运行服务
systemctl disable *.service             #取消开机运行
systemctl start *.service                #启动服务
systemctl stop *.service                 #停止服务
systemctl restart *.service              #重启服务
systemctl reload *.service             #重新加载服务配置文件
systemctl status *.service               #查询服务运行状态
systemctl --failed                       #显示启动失败的服务
# 12 base64
echo -n "str" | base64
将字符串str编码为base64字符串输出。注意与上面的差别
# 13 curl 代理
curl -x http://10.32.254.11:3128 -sSL https://get.daocloud.io/docker | sh
# 14 apt-get 代理
apt-get -o Acquire::http::proxy="http://10.32.254.11:3128/" update
# 15 命令行JSON格式化
~~~
curl ... | json_pp
curl ... | jq '.'
curl ... | python -m json.tool
~~~
# 16 pv
## 限速
pv -L 2m /media/himanshu/1AC2-A8E3/fNf.mkv > ./Desktop/fnf.mkv
## 测试网速
# 服务端
cat /dev/zero | pv | nc -l -p 2222
# 客户端
nc localhost 2222 | pv
# 17 ssh-keygen
ssh-keygen -f "/root/.ssh/known_hosts" -R 192.168.20.132
# 18 下载恢复
wget='wget -c '
# 19 删除当前目录下的文件和空目录
rm -d
# 删除横线开头的
rm -- -foo
rm ./-foo
# uuid
UUID=$(cat /proc/sys/kernel/random/uuid)
# 20 内存当成磁盘,或者使用 /dev/shm/
mount -t tmpfs -o size=1024m tmpfs /mnt/ram
sed 's/.$//'
awk '{sub(/.$/,"")}1'
iconnv -f gb2312 -t utf8 gb2312.txt > utf8.txt
enca 检测和转换编码
enca -L zh_CN cn.txt
enca -L zh_CN -x gb2312 cn.txt
# 查看生产厂家和序列号
dmidecode | grep "Product"
dmidecode -t1 | grep "Serial"
while : ; do : ; done &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment