现在的位置: 首页 > 综合 > 正文

《Linux Shell脚本攻略》 笔记 第八章:磁盘、日志管理

2016年02月22日 ⁄ 综合 ⁄ 共 2085字 ⁄ 字号 评论关闭

《Linux Shell脚本攻略》 笔记
第八章:磁盘、日志管理
1、显示给定文件夹下的文件的磁盘适用情况
[root@localhost program_test]# du -a -h ./
320K    ./output.tar
96K     ./reslt_yang.txt
4.0K    ./curr_dir.md5
4.0K    ./sed_data.txt

2、总计磁盘大小使用统计 -c
[root@localhost program_test]# du -h -c ./
48K     ./main
4.0K    ./abc
16K     ./dd_test
544K    ./tar-file
404K    ./touch_more/test_unzip
984K    ./touch_more
2.9M    ./
2.9M    total
[root@localhost program_test]# du -s -h ./
2.9M    ./
3、按文件大小排序
[root@localhost program_test]# du -ak ./ | sort -nrk 1 | head -n 5
2876    ./
984     ./touch_more
544     ./tar-file
404     ./touch_more/test_unzip
320     ./tar-file/output.tar
//只比较文件最大的前三位.
[root@localhost program_test]# find ./ -type f -exec du -k {} \; | sort -nrk 1 | head -n 3
320     ./tar-file/output.tar
320     ./output.tar
212     ./11.txt
4、磁盘可用情况 df = disk free
[root@localhost program_test]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        18G  2.5G   15G  16% /
tmpfs           504M   80K  504M   1% /dev/shm
/dev/sda1       291M   33M  244M  12% /boot
5、获取当前用户的相关信息 who、w
[root@localhost pts]# who
yxy      tty1         2015-01-02 22:36 (:0)
yxy       pts/1        2015-01-02 22:37 (:0.0)
yxy        pts/2        2015-01-02 22:37 (192.168.119.1)
yxy       pts/3        2015-01-02 22:37 (192.168.119.1)
[root@localhost pts]# w
23:19:38 up 46 min,  4 users,  load average: 0.00, 0.02, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
6、提供系统登陆日志  last
[root@localhost pts]# last
ycy      pts/0        192.168.119.1    Fri Jan  2 23:21   still logged in 
7、获取登陆失败的回话信息 lastb //必须以超级管理员运行
[root@localhost pts]# lastb
centos   ssh:notty    192.168.119.128  Fri Jan  2 22:59 - 22:59  (00:00)    
centos   ssh:notty    192.168.119.128  Fri Jan  2 22:59 - 22:59  (00:00)    
centos   ssh:notty    192.168.119.128  Fri Jan  2 22:59 - 22:59  (00:00) 
8、统计最常用的10个命令
[root@localhost program_test]# cat top10_cmds.sh 
#!/bin/bash

printf "COMMAND\t COUNT\n"

cat ~/.bash_history | awk '{ list[$1]++ } \
END{
for(i in list)
{
printf("%s\t %d\n",i, list[i]); }
}' | sort -nrk 2 | head

//执行结果如下:
[root@localhost program_test]# ./top10_cmds.sh 
COMMAND  COUNT
vi       88
find     82
[root@localhost  75
echo     72
cat      72
ls       65
ll       28
sh       25
seq      22
./word_freq.sh   21

作者:铭毅天下

转载请标明出处,原文地址:http://blog.csdn.net/laoyang360/article/details/42364897

如果感觉本文对您有帮助,请点击支持一下,您的支持是我坚持写作最大的动力,谢谢!

抱歉!评论已关闭.