16. 命令: free

跟踪内存的使用和资源一样重要,就像管理员执行的任何其它任务,可以使用 'free' 命令来在这里救援。

当前内存使用状态Current Usage Status of Memory

  1. [avishek@tecmint ~]$ free 
  2. total       used       free     shared    buffers     cached 
  3. Mem:       2028240    1788272     239968          0      69468     363716 
  4. -/+ buffers/cache:    1355088     673152 
  5. Swap:      3905532     157076    3748456 

设置输出单位为KB,MB或GB

  1. [avishek@tecmint ~]$ free -b 
  2. total       used       free     shared    buffers     cached 
  3. Mem:    2076917760 1838272512  238645248          0   71348224  372670464 
  4. -/+ buffers/cache: 1394253824  682663936 
  5. Swap:   3999264768  160845824 3838418944 
  6. [avishek@tecmint ~]$ free -k 
  7. total       used       free     shared    buffers     cached 
  8. Mem:       2028240    1801484     226756          0      69948     363704 
  9. -/+ buffers/cache:    1367832     660408 
  10. Swap:      3905532     157076    3748456 
  11. [avishek@tecmint ~]$ free -m 
  12. total       used       free     shared    buffers     cached 
  13. Mem:          1980       1762        218          0         68        355 
  14. -/+ buffers/cache:       1338        641 
  15. Swap:         3813        153       3660 
  16. [avishek@tecmint ~]$ free -g 
  17. total       used       free     shared    buffers     cached 
  18. Mem:             1          1          0          0          0          0 
  19. -/+ buffers/cache:          1          0 
  20. Swap:            3          0          3 

以可读的格式显示,检查当前内存使用:

  1. [avishek@tecmint ~]$ free -h 
  2. total       used       free     shared    buffers     cached 
  3. Mem:          1.9G       1.7G       208M         0B        68M       355M 
  4. -/+ buffers/cache:       1.3G       632M 
  5. Swap:         3.7G       153M       3.6G 

设定 时间间隔 后 ,持续检查使用状态:

  1. [avishek@tecmint ~]$ free -s 3 
  2. total       used       free     shared    buffers     cached 
  3. Mem:       2028240    1824096     204144          0      70708     364180 
  4. -/+ buffers/cache:    1389208     639032 
  5. Swap:      3905532     157076    3748456 
  6. total       used       free     shared    buffers     cached 
  7. Mem:       2028240    1824192     204048          0      70716     364212 
  8. -/+ buffers/cache:    1389264     638976 
  9. Swap:      3905532     157076    3748456 

阅读更多10个Free命令使用实例。

17. mysqldump 命令

好了,现在你从名字上就能明白这个命令所代表的作用。mysqldump 命令会转储(备份)数据库的全部或特定一部分数据到一个给定的文件中。例如:

  1. [avishek@tecmint ~]$ mysqldump -u root -p --all-databases > /home/server/Desktop/backupfile.sql 

注意: mysqldump 需要 mysql 在运行中并且有正确的授权密码。我们在 用mysqldump命令备份数据库中讨论了一些有用的 “mysqldump” 命令用法。

18. mkpasswd 命令

根据指定的长度,产生一个难猜的随机密码。

  1. [avishek@tecmint ~]$ mkpasswd -l 10 
  2. zI4+Ybqfx9 
  3. [avishek@tecmint ~]$ mkpasswd -l 20 
  4. w0Pr7aqKk&hmbmqdrlmk 

注意: -l 10 产生一个10个字符的随机密码,而-l 20 产生 20个字符的密码,它可以设置为任意长度来取得所希望的结果。这个命令很有用,经常在脚本语言里使用来产生随机的密码。你可能需要 yum 或 apt ‘expect’ 包来使用这个命令。

  1. [avishek@tecmint ~]$ yum install expect 
  2. 或 
  3. [avishek@tecmint ~]$ apt-get install expect 

19. Command: paste

合并两个或多个文本文件,按行来进行合并。示例。如果 file1 的内容是:

  1. file2 是这样的: 
  2. <pre class="brush:shell">[avishek@tecmint ~]$ paste file1 file2 > file3</pre> 
  3. <br> 
  4. 结果file3将是: 
  5. 1    a 
  6. 2    b 
  7. 3    c 

20.Command: lsof

lsof 是"list open files("列表中打开的文件") 的缩写,显示您的系统当前已打开的所有文件。这是非常有用的对于想找出哪些进程使用某一特定文件,或显示为单个进程打开所有文件。一些有用的 10 个lsof 命令示例,你可能会感兴趣阅读。

  1. [avishek@tecmint ~]$ lsof 
  2. COMMAND     PID   TID            USER   FD      TYPE     DEVICE SIZE/OFF       NODE NAME 
  3. init          1                  root  cwd       DIR        8,1     4096          2 / 
  4. init          1                  root  rtd       DIR        8,1     4096          2 / 
  5. init          1                  root  txt       REG        8,1   227432     395571 /sbin/init 
  6. init          1                  root  mem       REG        8,1    47080     263023 /lib/i386-linux-gnu/libnss_files-2.17.so 
  7. init          1                  root  mem       REG        8,1    42672     270178 /lib/i386-linux-gnu/libnss_nis-2.17.so 
  8. init          1                  root  mem       REG        8,1    87940     270187 /lib/i386-linux-gnu/libnsl-2.17.so 
  9. init          1                  root  mem       REG        8,1    30560     263021 /lib/i386-linux-gnu/libnss_compat-2.17.so 
  10. init          1                  root  mem       REG        8,1   124637     270176 /lib/i386-linux-gnu/libpthread-2.17.so 
  11. init          1                  root  mem       REG        8,1  1770984     266166 /lib/i386-linux-gnu/libc-2.17.so 
  12. init          1                  root  mem       REG        8,1    30696     262824 /lib/i386-linux-gnu/librt-2.17.so 
  13. init          1                  root  mem       REG        8,1    34392     262867 /lib/i386-linux-gnu/libjson.so.0.1.0 
  14. init          1                  root  mem       REG        8,1   296792     262889 /lib/i386-linux-gnu/libdbus-1.so.3.7.2 
  15. init          1                  root  mem       REG        8,1    34168     262840 /lib/i386-linux-gnu/libnih-dbus.so.1.0.0 
  16. init          1                  root  mem       REG        8,1    95616     262848 /lib/i386-linux-gnu/libnih.so.1.0.0 
  17. init          1                  root  mem       REG        8,1   134376     270186 /lib/i386-linux-gnu/ld-2.17.so 
  18. init          1                  root    0u      CHR        1,3      0t0       1035 /dev/null 
  19. init          1                  root    1u      CHR        1,3      0t0       1035 /dev/null 
  20. init          1                  root    2u      CHR        1,3      0t0       1035 /dev/null 
  21. init          1                  root    3r     FIFO        0,8      0t0       1714 pipe 
  22. init          1                  root    4w     FIFO        0,8      0t0       1714 pipe 
  23. init          1                  root    5r     0000        0,9        0       6245 anon_inode 
  24. init          1                  root    6r     0000        0,9        0       6245 anon_inode 
  25. init          1                  root    7u     unix 0xf5e91f80      0t0       8192 @/com/ubuntu/upstart 
  26. init          1                  root    8w      REG        8,1     3916        394 /var/log/upstart/teamviewerd.log.1 (deleted) 

这里并没有结束,系统管理员会很多东西,为你提供漂亮的界面,服务于你的工作。系统管理实际上是学习和实现的一门优雅的艺术。我们会尽力给你介绍 linux 专业人员必须了解的知识以及一些其他必要东西,linux本身是基础的,简单的。深入理解是不断学习的过程。你的美言好词总是在不断鼓励我们写出更多的优秀,丰富的文章。“喜之以分享,助我来传播”。


相关内容