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

《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

//只显示统计 -s
[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

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


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

铭毅天下

和你一起,死磕Elastic!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值