1.文本内容查看
(1)查看/etc/passwd文件的第六行
cat /etc/passwd | head -6 查看文件的前六行
(2)查看/etc/selinux/config以SELINUX开头的行
grep ^SELINUX /etc/selinux/config
(3)查找/etc/ssh/sshd_config的以no结尾的
grep no$ /etc/ssh/sshd_config
(4)过滤/etc/ssh/sshd_config包含数字的行
grep -v [0-9] /etc/ssh/sshd_config
2.查看/etc/passwd文件以“:”为分割符的第一列内容,并按照字母逆序排序写入/username文件统计/etc/passwd文件一共有几行,只有行数显示。
cut -d: -f1 /etc/passwd //查看以:为分隔符的第一行
cat /etc/passwd |cut -d: -f1 |sort -r |tee /etc/username //按照字母逆序排列
wc -l /etc/username 显示行数
3.统计系统执行频率最高的前十个命令
history |tr -s " " " " |cut -d " " -f 3|sort|uniq -c| sort -n| tail -10|tr -s " " " "|cut -d " " -f 3
课程总结:
echo 类似于printf
| tee -a file
vi/vim 命令模式
删除:dd 光标所在行
d+enter 光标及
i 插入在光标前
I 插入到光标行行首
o 光标的下一行插入
O 光标的上一行插入
echo 标准输入输出命令(打印命令)
$变量名 > >>
| 管道符 (前面命令输出结果通过管道连接通过后面命令进行处理--字符)
| tee (横向输出重定向到指定文件
less 打开阅读方式 vi
head
tail head -10 /etc/passwd | tail -3 显示前面十行后面三行
grep 关键字 文件名
-i 忽略大小写
-o
-n 过滤关键字显示他的行号
-c 行数统计
-w 单词进行过滤
^ $ ^$ [abc] [!abc]取反
cut 文本内容剪切命令
cut -c 1-3 /etc/passwd 把1-3字符剪切出来
cut -d ; -f 1 /etc/passwd
sort 排序命令
wc 行 单词数
history | tr -s " " " " | cut -d " " -f 3 | sort | uniq -c | sort -n | tail -3 | tr -s " " " "|
cp 复制
cp /root/file /test /test目录存在,把/root 的file 文件复制到该目录下
/test目录不存在,把/root的file文件复制到/目录下并改名test
/test是一个文本文件,把root的file文件复制到/目录下并改名为test