20个对Linux专家非常有用命令(1)(7)
16. 命令: free
跟踪内存的使用和资源一样重要,就像管理员执行的任何其它任务,可以使用 'free' 命令来在这里救援。
当前内存使用状态Current Usage Status of Memory
- [avishek@tecmint ~]$ free
- total used free shared buffers cached
- Mem: 2028240 1788272 239968 0 69468 363716
- -/+ buffers/cache: 1355088 673152
- Swap: 3905532 157076 3748456
设置输出单位为KB,MB或GB
- [avishek@tecmint ~]$ free -b
- total used free shared buffers cached
- Mem: 2076917760 1838272512 238645248 0 71348224 372670464
- -/+ buffers/cache: 1394253824 682663936
- Swap: 3999264768 160845824 3838418944
- [avishek@tecmint ~]$ free -k
- total used free shared buffers cached
- Mem: 2028240 1801484 226756 0 69948 363704
- -/+ buffers/cache: 1367832 660408
- Swap: 3905532 157076 3748456
- [avishek@tecmint ~]$ free -m
- total used free shared buffers cached
- Mem: 1980 1762 218 0 68 355
- -/+ buffers/cache: 1338 641
- Swap: 3813 153 3660
- [avishek@tecmint ~]$ free -g
- 3
- total used free shared buffers cached
- Mem: 1 1 0 0 0 0
- -/+ buffers/cache: 1 0
- Swap: 3 0 3
以可读的格式显示,检查当前内存使用:
- [avishek@tecmint ~]$ free -h
- total used free shared buffers cached
- Mem: 1.9G 1.7G 208M 0B 68M 355M
- -/+ buffers/cache: 1.3G 632M
- Swap: 3.7G 153M 3.6G
设定 时间间隔 后 ,持续检查使用状态:
- [avishek@tecmint ~]$ free -s 3
- total used free shared buffers cached
- Mem: 2028240 1824096 204144 0 70708 364180
- -/+ buffers/cache: 1389208 639032
- Swap: 3905532 157076 3748456
- total used free shared buffers cached
- Mem: 2028240 1824192 204048 0 70716 364212
- -/+ buffers/cache: 1389264 638976
- Swap: 3905532 157076 3748456
阅读更多10个Free命令使用实例。
17. mysqldump 命令
好了,现在你从名字上就能明白这个命令所代表的作用。mysqldump 命令会转储(备份)数据库的全部或特定一部分数据到一个给定的文件中。例如:
- [avishek@tecmint ~]$ mysqldump -u root -p --all-databases > /home/server/Desktop/backupfile.sql
注意: mysqldump 需要 mysql 在运行中并且有正确的授权密码。我们在 用mysqldump命令备份数据库中讨论了一些有用的 “mysqldump” 命令用法。
18. mkpasswd 命令
根据指定的长度,产生一个难猜的随机密码。
- [avishek@tecmint ~]$ mkpasswd -l 10
- zI4+Ybqfx9
- [avishek@tecmint ~]$ mkpasswd -l 20
- w0Pr7aqKk&hmbmqdrlmk
注意: -l 10 产生一个10个字符的随机密码,而-l 20 产生 20个字符的密码,它可以设置为任意长度来取得所希望的结果。这个命令很有用,经常在脚本语言里使用来产生随机的密码。你可能需要 yum 或 apt ‘expect’ 包来使用这个命令。
- [avishek@tecmint ~]$ yum install expect
- 或
- [avishek@tecmint ~]$ apt-get install expect
19. Command: paste
合并两个或多个文本文件,按行来进行合并。示例。如果 file1 的内容是:
- 1
- 2
- 3
- file2 是这样的:
- a
- b
- c
- d
- <pre class="brush:shell">[avishek@tecmint ~]$ paste file1 file2 > file3</pre>
- <br>
- 结果file3将是:
- 1 a
- 2 b
- 3 c
- d
20.Command: lsof
lsof 是"list open files("列表中打开的文件") 的缩写,显示您的系统当前已打开的所有文件。这是非常有用的对于想找出哪些进程使用某一特定文件,或显示为单个进程打开所有文件。一些有用的 10 个lsof 命令示例,你可能会感兴趣阅读。
- [avishek@tecmint ~]$ lsof
- COMMAND PID TID USER FD TYPE DEVICE SIZE/OFF NODE NAME
- init 1 root cwd DIR 8,1 4096 2 /
- init 1 root rtd DIR 8,1 4096 2 /
- init 1 root txt REG 8,1 227432 395571 /sbin/init
- init 1 root mem REG 8,1 47080 263023 /lib/i386-linux-gnu/libnss_files-2.17.so
- init 1 root mem REG 8,1 42672 270178 /lib/i386-linux-gnu/libnss_nis-2.17.so
- init 1 root mem REG 8,1 87940 270187 /lib/i386-linux-gnu/libnsl-2.17.so
- init 1 root mem REG 8,1 30560 263021 /lib/i386-linux-gnu/libnss_compat-2.17.so
- init 1 root mem REG 8,1 124637 270176 /lib/i386-linux-gnu/libpthread-2.17.so
- init 1 root mem REG 8,1 1770984 266166 /lib/i386-linux-gnu/libc-2.17.so
- init 1 root mem REG 8,1 30696 262824 /lib/i386-linux-gnu/librt-2.17.so
- init 1 root mem REG 8,1 34392 262867 /lib/i386-linux-gnu/libjson.so.0.1.0
- init 1 root mem REG 8,1 296792 262889 /lib/i386-linux-gnu/libdbus-1.so.3.7.2
- init 1 root mem REG 8,1 34168 262840 /lib/i386-linux-gnu/libnih-dbus.so.1.0.0
- init 1 root mem REG 8,1 95616 262848 /lib/i386-linux-gnu/libnih.so.1.0.0
- init 1 root mem REG 8,1 134376 270186 /lib/i386-linux-gnu/ld-2.17.so
- init 1 root 0u CHR 1,3 0t0 1035 /dev/null
- init 1 root 1u CHR 1,3 0t0 1035 /dev/null
- init 1 root 2u CHR 1,3 0t0 1035 /dev/null
- init 1 root 3r FIFO 0,8 0t0 1714 pipe
- init 1 root 4w FIFO 0,8 0t0 1714 pipe
- init 1 root 5r 0000 0,9 0 6245 anon_inode
- init 1 root 6r 0000 0,9 0 6245 anon_inode
- init 1 root 7u unix 0xf5e91f80 0t0 8192 @/com/ubuntu/upstart
- init 1 root 8w REG 8,1 3916 394 /var/log/upstart/teamviewerd.log.1 (deleted)
这里并没有结束,系统管理员会很多东西,为你提供漂亮的界面,服务于你的工作。系统管理实际上是学习和实现的一门优雅的艺术。我们会尽力给你介绍 linux 专业人员必须了解的知识以及一些其他必要东西,linux本身是基础的,简单的。深入理解是不断学习的过程。你的美言好词总是在不断鼓励我们写出更多的优秀,丰富的文章。“喜之以分享,助我来传播”。
评论暂时关闭