Skip to content

Instantly share code, notes, and snippets.

@xiazhibin
Last active October 23, 2018 07:10
Show Gist options
  • Save xiazhibin/a85504f8447a05612aa48f74b5a79ff9 to your computer and use it in GitHub Desktop.
Save xiazhibin/a85504f8447a05612aa48f74b5a79ff9 to your computer and use it in GitHub Desktop.
一些统计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 清空文件

ls -x 按照文件名排序

ls -SlH 按照文件size排序

date parsh

#!/bin/bash
Year=`date +%Y`
Month=`date +%m`
Day=`date +%d`
Hour=`date +%H`
Minute=`date +%M`
Second=`date +%S`
echo `date`
echo "Current Date is: $Day-$Month-$Year"
echo "Current Time is: $Hour:$Minute:$Second"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment