1 .cat—查看一个文件的全部内容
[root@bogon ~]# cat -n -A we.txt
1 fxr$
2 181530106$
3 19990818$
4 5715$
5 192.168.1.1$
# 查看we.txt内容 ,-n 代表显示行数,-A 包括控制字符(换行符/制表符)
2 .head -n(查看前n行)
[root@bogon ~]# head -2 we.txt fxr 181530106 # 默认查看前两行
3.tail尾部
[root@linux-server ~]# tail /etc/passwd //默认查看文件的后十行
[root@linux-server ~]# tail -1 /etc/passwd //查看文件最后一行
[root@linux-server ~]# tail /var/log/messages
[root@linux-server ~]# tail -f /var/log/secure //-f 动态查看文件的尾部
[root@linux-server ~]# tailf /var/log/secure //功能同上
[root@bogon ~]# tail -2 we.txt 5715 192.168.1.1 # 查看倒数两行
4.grep过滤关键字 grep 针对文件内容进行过滤
[root@bogon ~]# grep -n "fxr" we.txt 1:fxr # 过滤带有fxr的行
[root@bogon ~]# grep -n "06$" we.txt 2:181530106 # 过滤以06结尾
[root@bogon ~]# grep -n "^19" we.txt 3:19990818 5:192.168.1.1 # 过滤以19开头的行
5.less --分页显示
空格键是翻页 回车键是翻行
上下箭头可以来回翻
/关键字 #搜索 (n按关键字往下翻 N按关键字往上翻)
快捷键:q -quit 退出
6.more --分页显示文件内容
[root@bogon ~]# more we.txt fxr 181530106 19990818 5715 192.168.1.1 # 空格键是翻页 回车键是翻行
作业
1、如何通过命令行重启linux操作系统?
reboot
2、如何删除/tmp下所有A开头的文件?
rm -rf /tmp/A*
3、如何删除/tmp下所有B结尾的文件?
rm -rf /tmp/B
4、如何创建/tmp/test.conf文件并向该文件内输入内容为“Hello world”?
touch /tmp/test.conf
echo “Hello world” >> /tmp/test.conf
5、如何最快的返回到当前账户的家目录?
cd
6、如何删除/tmp下所有的文件?
rm -rf /tmp/



