Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2789204
  • 博文数量: 471
  • 博客积分: 7081
  • 博客等级: 少将
  • 技术积分: 5369
  • 用 户 组: 普通用户
  • 注册时间: 2012-01-04 21:55
文章分类

全部博文(471)

文章存档

2014年(90)

2013年(69)

2012年(312)

分类: LINUX

2012-12-24 20:37:47

1. 磁盘使用情况

du -h  查看当前用户每个文件的大小,格式化显示
df  -h  磁盘使用情况

点击(此处)折叠或打开

  1. [root@localhost mysql5]# du -h
  2. 339M
  3. [root@localhost mysql5]# ls
  4. MySQL-5.5.20-1.linux2.6.i386.tar
  5. MySQL-client-5.5.20-1.linux2.6.i386.rpm
  6. MySQL-devel-5.5.20-1.linux2.6.i386.rpm
  7. MySQL-embedded-5.5.20-1.linux2.6.i386.rpm
  8. MySQL-server-5.5.20-1.linux2.6.i386.rpm
  9. MySQL-shared-5.5.20-1.linux2.6.i386.rpm
  10. MySQL-test-5.5.20-1.linux2.6.i386.rpm
  11. [root@localhost mysql5]# du -h MySQL-client-5.5.20-1.linux2.6.i386.rpm
  12. 17M MySQL-client-5.5.20-1.linux2.6.i386.rpm
  13. [root@localhost mysql5]#

点击(此处)折叠或打开

  1. [root@localhost mysql5]# df -h
  2. 文件系统 容量 已用 可用 已用% 挂载点
  3. /dev/mapper/VolGroup00-LogVol00
  4.                        14G 6.4G 6.5G 50% /
  5. /dev/sda1 99M 12M 83M 13% /boot
  6. tmpfs 506M 0 506M 0% /dev/shm

2、常用文件操作命令
cat,显示文件内容。
cd,改变目录路径。
cp,复制文件。
find,查找文件。
grep,搜索、过滤信息。
ls,列出目录信息。
more,分页显示。
rm,删除文件或目录。
vi,调用vi文本编辑器

点击(此处)折叠或打开

  1. [root@localhost king]# cat abc1.txt |more

    //查找当前目录下以a开头的文件 
  2. [root@localhost king]# ls
  3. abc1.txt  abc2.txt  abc3.txt  king001  kingtest  new
  4. [root@localhost king]# find -name "a*"
  5. ./abc3.txt
  6. ./abc1.txt
  7. ./abc2.txt

  8. [root@localhost home]# find king -name "a*" 
  9. king/abc3.txt
  10. king/abc1.txt
  11. king/abc2.txt

    grep查找keyword的所在行的内容
  12. [root@localhost king]# more  abc1.txt|grep "1971"
  13. Federal Election Campaign Act of 1971 to provide bipartisan campaign 

ls统计文件个数:原理是ls -l列出多少行 再利用管道作为wc -l输入 以行来数的

点击(此处)折叠或打开

  1. [root@localhost king]# ls -l
  2. 总计 44
  3. -rwxrw-rw- 1 root root 2395 2012-05-26 abc1.txt
  4. -rwxrw-rw- 1 root root 2397 2012-05-26 abc2.txt
  5. -rwxrw-rw- 1 root root 1020 2012-05-26 abc3.txt
  6. drwxrwxr-x 2 king king 4096 2012-02-02 king001
  7. -rw-rw-r-- 1 king king 0 2012-02-02 kingtest
  8. -rw-r--r-- 1 root root 714 09-30 22:52 new
  9. [root@localhost king]# ls -l|wc -l
  10. 7
head  查看文件前20行 tail 查看后面10行

点击(此处)折叠或打开

  1. [root@localhost king]# head -20 abc1.txt 
  2. [Congressional Record Volume 148, Number 2 (Thursday, January 24, 2002)]
  3. [Daily Digest]
  4. [Page D12]
  5. From the Congressional Record Online through the Government Printing Office []





  6.                         House of Representatives


  7. Chamber Action
  8. Measures Introduced: 13 public bills, H.R. 3622-3634; 8 resolutions, H. 
  9. Con. Res. 302-308, and H. Res. 335 were introduced.
  10.   Page H78
  11. Reports Filed: No reports were filed today.
  12. Speaker Pro Tempore: Read a letter from the Speaker wherein he 
  13. appointed Representative Shimkus to act as Speaker pro tempore for 
  14. today.


  15. [root@localhost king]# tail -10 abc1.txt 
  16. Res. 203, providing for consideration of H.R. 2356, to amend the 
  17. Federal Election Campaign Act of 1971 to provide bipartisan campaign 
  18. reform, the motion was referred to the Calendar of Motions to Discharge 
  19. Committees.
  20.   Pages H76-77
  21. Senate Message: Message received from the Senate appears on page H39.
  22. Quorum Calls--Votes: One yea-and-nay vote developed during the 
  23. proceedings of the House today and appears on pages H47-48. There were 
  24. no quorum calls.
  25. Adjournment: The House met at 10 a.m. and adjourned at 3:38 p.m.
Linux命令经典面试题:统计文件中出现次数最多的前10个单词

使用linux命令或者shell实现:文件words存放英文单词,格式为每行一个英文单词(单词可以重复),统计这个文件中出现次数最多的前10个单词。

cat words.txt | sort | uniq -c | sort -k1,1nr | head -10

  主要考察对sort、uniq命令的使用,相关解释如下,命令及参数的详细说明请自行通过man查看,简单介绍下以上指令各部分的功能:

sort:  对单词进行排序

uniq -c:  显示唯一的行,并在每行行首加上本行在文件中出现的次数

sort -k1,1nr:  按照第一个字段,数值排序,且为逆序

head -10:  取前10行数据


点击(此处)折叠或打开

  1. [root@localhost king]# uniq -c word.txt|sort -k1
  2.       1 bye
  3.       1 good
  4.       1 see
  5.       1 tim
  6.       1 tim
  7.       1 you
  8.       2 jack
  9.       2 king

  10. [root@localhost king]# uniq -c word.txt|sort -r|head -2
  11.       2 king
  12.       2 jack

阅读(1634) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~