查看文件内容—cat/more/less/head/tail (只能查看文本文件)
cat
[root@localhost dict]# cat -n /etc/fstab
>>>查看行号并且会给每一行增加行号 (适用于文件内容较少)
[root@localhost etc]# cat /etc/redhat-release --查看系统的发行版信息
Red Hat Enterprise Linux Server release 7.1 (Maipo)
more/less(分页显示文件):
[root@localhost etc]# less /usr/share/dict/words
[root@localhost etc]# more /usr/share/dict/words
head/tail
[root@localhost etc]# head -n 3 /etc/passwd >>>默认查看文件前10行的内容
[root@localhost etc]# tail -n 3 /etc/passwd >>>默认查看文件后10行的内容
查看文件的类型:
[root@localhost etc]# file /etc/passwd
查看系统命令所在的目录
[root@localhost bin]# which ls
| 管道符 :>>>前面命令的结果作为参数传递到后面的命令
[root@localhost bin]# head -n 5 /home/oracle/.bashrc | tail -n 1
查找文件或目录 :
find 路径 查找方式
按文件名称查找:
[root@localhost etc]# find /etc/ -name "*.conf"
[root@localhost etc]# find /etc/ -name "*.conf" | wc -l
按文件大小查找:
[root@localhost etc]# find /etc/ -size +1M
>>>查看/etc/大于1M的文件 +表示大于 — 表示小于
按文件的修改时间查找:
[root@localhost etc]# find -mtime +7
>>>查看7天之前修改过的文件
[root@localhost etc]# find -mtime -7
>>>查看7天之内修改过的文件
按文件的类型查找:
[root@localhost ~]# find /dev/ -type l
[root@localhost ~]# find /etc/ -mtime -7 -a -size +100k
>>>查看7天之内修改过并且大于100k的文件 a:and 并且
[root@localhost test]# find /home/test/ -name "*.jgp" -exec rm -rf {} \;
>>>删除以jpg结尾的文件
[root@localhost test]# find /home/test/ -name "*.txt" -exec cp {} /home/test/huge/ \;
>>>找到以txt结尾的文件并复制到其他路径下