Linux管理员 - 基本的CentOS Linux命令

在学习CentOS Linux管理员的工具之前,重要的是要注意Linux管理命令行背后的理念.

Linux的设计基于Unix的"小",精确的工具链接在一起简化了更大的任务".从根本上说,Linux在很多时候都没有针对特定用途的大型单用途应用程序.相反,有数百个基本实用程序组合在一起提供了强大的功能,可以高效地完成大任务.

Linux哲学的例子

例如,如果管理员想要系统上所有当前用户的列表,则可以使用以下链式命令获取所有系统用户的列表.在执行命令时,系统上的用户按字母顺序列出.

[root@centosLocal centos]# cut /etc/passwrd -d":" -f1 | sort 
abrt 
adm 
avahi 
bin 
centos 
chrony 
colord 
daemon 
dbus


使用以下命令可以很容易地将此列表导出到文本文件中.

[root@localhost /]# cut /etc/passwd -d ":" -f1 > system_users.txt        
[root@localhost /]# cat ./system_users.txt | sort | wc –l 
40       
[root@localhost /]#


还可以将用户列表与导出进行比较以后的日期.

[root@centosLocal centos]#  cut /etc/passwd -d ":" -f1 > system_users002.txt && 
   cat system_users002.txt | sort | wc -l 
41 
[root@centosLocal centos]# diff ./system_users.txt ./system_users002.txt  
evilBackdoor [root@centosLocal centos]#


通过这种小工具的方法来完成更大的任务,制作脚本执行这些命令比在固定的时间间隔自动发送电子邮件更简单.

每个Linux管理员应该精通的基本命令是 :

  • vim

  • grep

  • more and less

  • tail

  • head

  • wc

  • sort

  • uniq

  • tee

  • cat

  • cut

  • sed

  • tr

  • paste

在Linux世界中,管理员每天使用过滤命令来解析日志,过滤命令输出并使用交互式shell执行操作脚本.如上所述,这些命令的强大之处在于它们能够通过一个名为 piping 的过程相互修改.

以下命令显示有多少单词以来自CentOS主要用户词典的字母a.

[root@centosLocal ~]# egrep '^a.*$' /usr/share/dict/words | wc -l 
25192 
[root@centosLocal ~]#