Linux Admin 简明教程
Linux Admin - Basic CentOS Linux Commands
在学习 CentOS Linux 管理员的工具之前,了解 Linux 管理命令行背后的理念非常重要。
Before learning the tools of a CentOS Linux Administrator, it is important to note the philosophy behind the Linux administration command line.
Linux 是根据“实现更大的任务时可将小型精确工具链接起来”的 Unix 理念而设计的。从根本上讲,Linux 很多时候并不会将大型单一用途应用程序与某个特定用途结合起来。相反,有数百个基本实用程序,在相结合时能够有效地为完成大型任务提供强大的功能。
Linux was designed based on the Unix philosophy of “small, precise tools chained together simplifying larger tasks”. Linux, at its root, does not have large single-purpose applications for one specific use a lot of the time. Instead, there are hundreds of basic utilities that when combined offer great power to accomplish big tasks with efficiency.
Examples of the Linux Philosophy
例如,如果管理员希望获取系统中所有当前用户的列表,可以使用以下连锁命令获取系统中所有用户的列表。在执行命令时,将按字母顺序列出系统中的用户。
For example, if an administrator wants a listing of all the current users on a system, the following chained commands can be used to get a list of all system users. On execution of the command, the users are on the system are listed in an alphabetical order.
[root@centosLocal centos]# cut /etc/passwd -d":" -f1 | sort
abrt
adm
avahi
bin
centos
chrony
colord
daemon
dbus
可以轻松地使用以下命令将此列表导出到文本文件中。
It is easy to export this list into a text file using the following command.
[root@localhost /]# cut /etc/passwd -d ":" -f1 > system_users.txt
[root@localhost /]# cat ./system_users.txt | sort | wc –l
40
[root@localhost /]#
还可以将用户列表与稍后导出的内容进行比较。
It is also possible to compare the user list with an export at a later date.
[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]#
已将新用户“evilBackdoor”添加到系统中。
A new user, “evilBackdoor", has been added to the system.
通过这种将小工具连接起来以完成更大任务的方法,编写一个执行这些命令的脚本比在固定时间间隔自动发送结果电子邮件更加简单。
With this approach of small tools chained to accomplish bigger tasks, it is simpler to make a script performing these commands, than automatically email results at regular time intervals.
每个 Linux 管理员都应该精通的基本命令如下:
Basic Commands every Linux Administrator should be proficient in are −
在 Linux 世界中,管理员每天使用 filtering 命令来分析日志、筛选命令输出以及使用交互式 shell 脚本执行操作。如前所述,这些命令的力量在于它们能够通过称为 piping 的过程相互修改。
In the Linux world, Administrators use filtering commands every day to parse logs, filter command output, and perform actions with interactive shell scripts. As mentioned, the power of these commands come in their ability to modify one another through a process called piping.
以下命令显示了 CentOS 主用户词典中有多少个单词以字母 a 开头。
The following command shows how many words begin with the letter a from the CentOS main user dictionary.
[root@centosLocal ~]# egrep '^a.*$' /usr/share/dict/words | wc -l
25192
[root@centosLocal ~]#