时间(date)

  • 获取当前的时间戳

    date +%s1570093753
  • 时间戳转化为可读时间

    date -d @1570093753 "+%Y%m%d %H:%M:%S"20191003 18:09:13
  • 时间偏移计算

    date -d "2019-10-03 30 days ago" "+%Y%m%d" 20190903
  • 获取当前是周几

    date +%u # day of week (1..7); 1 is Mondaydate +%w # day of week (0..6); 0 is Sunday4
  • 其他更详细的用法

    man date

排序(sort)

  • 主要用于小文件排序(sort lines of text files)

    sort -t ',' -k 2 -nr ./file_name #次将文件用,分割,对第2列(从1开始算),按照数字顺序(numeric-sort)将整行内容降序排列
  • 文件快速去重

    sort -u ./file_name
  • 其他更详细的用法

    man sort      

查找(find)

  • 找到文件夹中最大的文本

    find /path/to/file -name "*txt" | xargs ls -li|sort -k 6|tail -n 1
  • 找到文件夹中30天前修改的文件并打印/删除

    find /path/to/file -mindepth 1 -mtime +30 -printfind /path/to/file -mindepth 1 -mtime +30 -delete

curl

  • Get 请求

    curl -i -H "Accept: application/json" "www.baidu.com" | less
  • Post 请求(json)

    curl -X POST  -H "Accept: Application/json" -H "Content-Type: application/json" -d '{"id":"IDVALUE","name":"Mike"}' http://hostname/api
  • Post请求(data)

    curl --data "secret_key=sec&id=2&phone=1980000000" http://hostname/api
  • 获取http状态(比如200, 404)

    curl -sL -w "%{http_code}" "www.baidu.com" -o /dev/null
  • 发送钉钉报警(也是一个Post)

    message="dingtalk_message"curl -H "Content-type: application/json" -X POST -d '{"msgtype": "text","text": {"content": "'$message'"}}' $dingtalk_webhook