Linux文件查看与查找命令

Linux文件查看与查找命令

cat  查看一个文件

-E: 显示行结束符$

-n: 对显示出的每一行进行编号

-A:显示所有控制符

-b:非空行编号

-s:压缩连续的空行成一行

-T:显示制表符

常用:cat -An /etc/passwd

[root@linuxidc ~]# cat -An /etc/passwd 1 root:x:0:0:root:/root:/bin/bash$ 2 bin:x:1:1:bin:/bin:/sbin/nologin$ 3 daemon:x:2:2:daemon:/sbin:/sbin/nologin$ 4 adm:x:3:4:adm:/var/adm:/sbin/nologin$ 5 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin$ 6 sync:x:5:0:sync:/sbin:/bin/sync$ 7 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown$ 8 halt:x:7:0:halt:/sbin:/sbin/halt$ 9 mail:x:8:12:mail:/var/spool/mail:/sbin/nologin$

more 分页查看文件

文件内容较多时,用more命令查看,空格键下翻,b键上翻,Q退出

[root@linuxidc ~]# more install.log Installing libgcc-4.4.7-17.el6.x86_64 warning: libgcc-4.4.7-17.el6.x86_64: Header V3 RSA/SHA1 Signature, key ID c10 5b9de: NOKEY Installing fontpackages-filesystem-1.41-1.1.el6.noarch Installing m17n-db-1.5.5-1.1.el6.noarch Installing liberation-fonts-common-1.05.1.20090721-5.el6.noarch Installing setup-2.8.14-20.el6_4.1.noarch Installing xkeyboard-config-2.16-1.el6.noarch Installing xml-common-0.6.3-33.el6.noarch Installing iso-codes-3.16-2.el6.noarch Installing filesystem-2.4.30-3.el6.x86_64 Installing dejavu-fonts-common-2.33-1.el6.noarch Installing mozilla-filesystem-1.9-5.1.el6.x86_64 Installing control-center-filesystem-2.28.1-40.el6.x86_64 Installing paktype-fonts-common-2.0-8.el6.noarch Installing mesa-dri-filesystem-11.0.7-4.el6.x86_64

head 显示前十行内容

[root@linuxidc ~]# head install.log Installing libgcc-4.4.7-17.el6.x86_64 warning: libgcc-4.4.7-17.el6.x86_64: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY Installing fontpackages-filesystem-1.41-1.1.el6.noarch Installing m17n-db-1.5.5-1.1.el6.noarch Installing liberation-fonts-common-1.05.1.20090721-5.el6.noarch Installing setup-2.8.14-20.el6_4.1.noarch Installing xkeyboard-config-2.16-1.el6.noarch Installing xml-common-0.6.3-33.el6.noarch Installing iso-codes-3.16-2.el6.noarch Installing filesystem-2.4.30-3.el6.x86_64

-c#:指定获取前#个字节

[root@linuxidc ~]# head -c6 install.log Instal[root@linuxidc ~]#

-n#:指定获取前#行

[root@linuxidc ~]# head -n6 install.log Installing libgcc-4.4.7-17.el6.x86_64 warning: libgcc-4.4.7-17.el6.x86_64: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY Installing fontpackages-filesystem-1.41-1.1.el6.noarch Installing m17n-db-1.5.5-1.1.el6.noarch Installing liberation-fonts-common-1.05.1.20090721-5.el6.noarch Installing setup-2.8.14-20.el6_4.1.noarch

-#:指定行数

[root@linuxidc ~]# head -3 install.log Installing libgcc-4.4.7-17.el6.x86_64 warning: libgcc-4.4.7-17.el6.x86_64: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY Installing fontpackages-filesystem-1.41-1.1.el6.noarch

tail 默认显示文件后面10行的内容

[root@linuxidc ~]# tail install.log Installing iwl3945-firmware-15.32.2.9-4.el6.noarch Installing ql2200-firmware-2.02.08-3.1.el6.noarch Installing rt73usb-firmware-1.8-7.el6.noarch Installing ipw2100-firmware-1.3-11.el6.noarch Installing ql23xx-firmware-3.03.27-3.1.el6.noarch Installing ipw2200-firmware-3.1-4.el6.noarch Installing rootfiles-8.1-6.1.el6.noarch Installing man-pages-3.22-20.el6.noarch Installing words-3.0-17.el6.noarch *** FINISHED INSTALLING PACKAGES ***[root@linuxidc ~]#

-n#:指定获取后#行

[root@linuxidc ~]# tail -n2 install.log Installing words-3.0-17.el6.noarch *** FINISHED INSTALLING PACKAGES ***[root@linuxidc ~]#

-#:指定行数

[root@linuxidc ~]# tail -2 install.log Installing words-3.0-17.el6.noarch *** FINISHED INSTALLING PACKAGES ***[root@linuxidc ~]#

-f:实时查看文件的最新变化  用于排查故障的时候  等同于tailf

[root@linuxidc ~]# tailf install.log Installing iwl3945-firmware-15.32.2.9-4.el6.noarch Installing ql2200-firmware-2.02.08-3.1.el6.noarch Installing rt73usb-firmware-1.8-7.el6.noarch Installing ipw2100-firmware-1.3-11.el6.noarch Installing ql23xx-firmware-3.03.27-3.1.el6.noarch Installing ipw2200-firmware-3.1-4.el6.noarch Installing rootfiles-8.1-6.1.el6.noarch Installing man-pages-3.22-20.el6.noarch Installing words-3.0-17.el6.noarch *** FINISHED INSTALLING PACKAGES ***

cut:文本内容切割并按要求输出

-d:指明分隔符

-f:指明要取出的字段

如要取出此文件内容的第一段

[root@linuxidc ~]# cat /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync [root@linuxidc ~]# cut -d ":" -f1 /etc/passwd root bin daemon adm lp sync

wc:查看文件内容有多少字符,多少行,多少字节

[root@linuxidc ~]# wc /etc/passwd 35 54 1672 /etc/passwd

wc -l:统计行数    (常用)

[root@linuxidc ~]# wc -l /etc/passwd 35 /etc/passwd

sort:排序

-r 逆序

-n 按照数字大写

-f  忽略字符串大小写

-t “c” 以后面的字符作为分隔符

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/13935.html