文件内容查看
概述
- cat 从开头开始显示文件内容
- tac 从最后一行开始显示,可以看成cat倒着写
- nl 显示行数
- more 可以翻页查看,但不能向上翻页,enter为一行一行翻页,空格直接翻页
- less 可以上下翻页,上下键翻页,n向上翻页,N向下翻页, /(字符)向下查询字符, ?(字符)向上查询字符,q离开less
- head 只看头几行
- tail 只看尾部几行
cat 从开头开始显示文件内容
- 参数
- -n 列出行数 (空白行也会标记行数,与-b相反)
[root@LuoKing etc]# cat -n csh.login
1 # /etc/csh.login
2
3 # System wide environment and startup programs, for login setup
4
5 if ( ! ${?PATH} ) then
6 if ( $uid == 0 ) then
7 setenv PATH "/usr/local/sbin:/usr/sbin:/usr/local/bin:/usr/bin"
8 else
9 setenv PATH "/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin"
10 endif
11 else
12 #add sbin directories to the path
13 foreach p ( /usr/local/sbin /usr/sbin )
14 switch (":${PATH}:")
15 case "*:${p}:*":
16 breaksw
17 default:
18 if ( $uid == 0 ) then
19 set path = ( ${p} ${path:q} )
20 else
21 set path = ( ${path:q} ${p} )
22 endif
23 breaksw
24 endsw
25 end
26 endif
27
28 setenv HOSTNAME `/usr/bin/hostname`
29 set history=1000
30
31 if ( -d /etc/profile.d ) then
32 set nonomatch
33 foreach i ( /etc/profile.d/*.csh /etc/profile.d/csh.local )
34 if ( -r "$i" ) then
35 if ($?prompt) then
36 source "$i"
37 else
38 source "$i" >& /dev/null
39 endif
40 endif
41 end
42 unset i nonomatch
43 endif
- -b(标记行数,不会标记空白行)
[root@LuoKing etc]# cat -b csh.login
1 # /etc/csh.login
2 # System wide environment and startup programs, for login setup
3 if ( ! ${?PATH} ) then
4 if ( $uid == 0 ) then
5 setenv PATH "/usr/local/sbin:/usr/sbin:/usr/local/bin:/usr/bin"
6 else
7 setenv PATH "/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin"
8 endif
9 else
10 #add sbin directories to the path
11 foreach p ( /usr/local/sbin /usr/sbin )
12 switch (":${PATH}:")
13 case "*:${p}:*":
14 breaksw
15 default:
16 if ( $uid == 0 ) then
17 set path = ( ${p} ${path:q} )
18 else
19 set path = ( ${path:q} ${p} )
20 endif
21 breaksw
22 endsw
23 end
24 endif
25 setenv HOSTNAME `/usr/bin/hostname`
26 set history=1000
27 if ( -d /etc/profile.d ) then
28 set nonomatch
29 foreach i ( /etc/profile.d/*.csh /etc/profile.d/csh.local )
30 if ( -r "$i" ) then
31 if ($?prompt) then
32 source "$i"
33 else
34 source "$i" >& /dev/null
35 endif
36 endif
37 end
38 unset i nonomatch
39 endif
tac 文件内容从最后一行开始显示
[root@LuoKing etc]# tac csh.login
endif
unset i nonomatch
end
endif
endif
source "$i" >& /dev/null
else
source "$i"
if ($?prompt) then
if ( -r "$i" ) then
foreach i ( /etc/profile.d/*.csh /etc/profile.d/csh.local )
set nonomatch
if ( -d /etc/profile.d ) then
set history=1000
setenv HOSTNAME `/usr/bin/hostname`
endif
end
endsw
breaksw
endif
set path = ( ${path:q} ${p} )
else
set path = ( ${p} ${path:q} )
if ( $uid == 0 ) then
default:
breaksw
case "*:${p}:*":
switch (":${PATH}:")
foreach p ( /usr/local/sbin /usr/sbin )
#add sbin directories to the path
else
endif
setenv PATH "/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin"
else
setenv PATH "/usr/local/sbin:/usr/sbin:/usr/local/bin:/usr/bin"
if ( $uid == 0 ) then
if ( ! ${?PATH} ) then
# System wide environment and startup programs, for login setup
# /etc/csh.login
nl 显示行数
选项与参数:
-
-b :指定行号指定的方式,主要有两种:-b a :表示不论是否为空行,也同样列出行号(类似 cat -n);-b t :如果有空行,空的那一行不要列出行号(默认值);
-
-n :列出行号表示的方法,主要有三种:-n ln :行号在荧幕的最左方显示;-n rn :行号在自己栏位的最右方显示,且不加 0 ;-n rz :行号在自己栏位的最右方显示,且加 0 ;
-
-w :行号栏位的占用的位数。
[root@LuoKing etc]# nl csh.login #默认空白行不显示行数
1 # /etc/csh.login
2 # System wide environment and startup programs, for login setup
3 if ( ! ${?PATH} ) then
4 if ( $uid == 0 ) then
5 setenv PATH "/usr/local/sbin:/usr/sbin:/usr/local/bin:/usr/bin"
6 else
7 setenv PATH "/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin"
8 endif
9 else
10 #add sbin directories to the path
11 foreach p ( /usr/local/sbin /usr/sbin )
12 switch (":${PATH}:")
13 case "*:${p}:*":
14 breaksw
15 default:
16 if ( $uid == 0 ) then
17 set path = ( ${p} ${path:q} )
18 else
19 set path = ( ${path:q} ${p} )
20 endif
21 breaksw
22 endsw
23 end
24 endif
25 setenv HOSTNAME `/usr/bin/hostname`
26 set history=1000
27 if ( -d /etc/profile.d ) then
28 set nonomatch
29 foreach i ( /etc/profile.d/*.csh /etc/profile.d/csh.local )
30 if ( -r "$i" ) then
31 if ($?prompt) then
32 source "$i"
33 else
34 source "$i" >& /dev/null
35 endif
36 endif
37 end
38 unset i nonomatch
39 endif
[root@LuoKing etc]# nl -b a csh.login # 空白行显示行数(all全部)
1 # /etc/csh.login
2
3 # System wide environment and startup programs, for login setup
4
5 if ( ! ${?PATH} ) then
6 if ( $uid == 0 ) then
7 setenv PATH "/usr/local/sbin:/usr/sbin:/usr/local/bin:/usr/bin"
8 else
9 setenv PATH "/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin"
10 endif
11 else
12 #add sbin directories to the path
13 foreach p ( /usr/local/sbin /usr/sbin )
14 switch (":${PATH}:")
15 case "*:${p}:*":
16 breaksw
17 default:
18 if ( $uid == 0 ) then
19 set path = ( ${p} ${path:q} )
20 else
21 set path = ( ${path:q} ${p} )
22 endif
23 breaksw
24 endsw
25 end
26 endif
27
28 setenv HOSTNAME `/usr/bin/hostname`
29 set history=1000
30
31 if ( -d /etc/profile.d ) then
32 set nonomatch
33 foreach i ( /etc/profile.d/*.csh /etc/profile.d/csh.local )
34 if ( -r "$i" ) then
35 if ($?prompt) then
36 source "$i"
37 else
38 source "$i" >& /dev/null
39 endif
40 endif
41 end
42 unset i nonomatch
43 endif
[root@LuoKing etc]# nl -b t csh.login # 空白行不显示行数
1 # /etc/csh.login
2 # System wide environment and startup programs, for login setup
3 if ( ! ${?PATH} ) then
4 if ( $uid == 0 ) then
5 setenv PATH "/usr/local/sbin:/usr/sbin:/usr/local/bin:/usr/bin"
6 else
7 setenv PATH "/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin"
8 endif
9 else
10 #add sbin directories to the path
11 foreach p ( /usr/local/sbin /usr/sbin )
12 switch (":${PATH}:")
13 case "*:${p}:*":
14 breaksw
15 default:
16 if ( $uid == 0 ) then
17 set path = ( ${p} ${path:q} )
18 else
19 set path = ( ${path:q} ${p} )
20 endif
21 breaksw
22 endsw
23 end
24 endif
25 setenv HOSTNAME `/usr/bin/hostname`
26 set history=1000
27 if ( -d /etc/profile.d ) then
28 set nonomatch
29 foreach i ( /etc/profile.d/*.csh /etc/profile.d/csh.local )
30 if ( -r "$i" ) then
31 if ($?prompt) then
32 source "$i"
33 else
34 source "$i" >& /dev/null
35 endif
36 endif
37 end
38 unset i nonomatch
39 endif
more 一页一页翻动页面
在 more 这个程序的运行过程中,你有几个按键可以按的:
-
空白键 (space):代表向下翻一页;
-
Enter :代表向下翻『一行』;
-
/字串 :代表在这个显示的内容当中,向下搜寻『字串』这个关键字;
-
:f :立刻显示出档名以及目前显示的行数;
-
q :代表立刻离开 more ,不再显示该文件内容。
-
b 或 [ctrl]-b :代表往回翻页,不过这动作只对文件有用,对管线无用。
[root@LuoKing etc]# more csh.login
# /etc/csh.login
# System wide environment and startup programs, for login setup
if ( ! ${?PATH} ) then
if ( $uid == 0 ) then
setenv PATH "/usr/local/sbin:/usr/sbin:/usr/local/bin:/usr/bin"
else
setenv PATH "/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin"
endif
else
#add sbin directories to the path
foreach p ( /usr/local/sbin /usr/sbin )
switch (":${PATH}:")
case "*:${p}:*":
breaksw
--More--(38%) # 光标在这等待命令
less 支持往回翻
less运行时可以输入的命令有:
-
空白键 :向下翻动一页;
-
[pagedown]:向下翻动一页;
-
[pageup] :向上翻动一页;
-
/字串 :向下搜寻『字串』的功能;
-
?字串 :向上搜寻『字串』的功能;
-
n :重复前一个搜寻 (与 / 或 ? 有关!)
-
N :反向的重复前一个搜寻 (与 / 或 ? 有关!)
-
q :离开 less 这个程序;
[root@LuoKing etc]# less csh.login
# /etc/csh.login
# System wide environment and startup programs, for login setup
if ( ! ${?PATH} ) then
if ( $uid == 0 ) then
setenv PATH "/usr/local/sbin:/usr/sbin:/usr/local/bin:/usr/bin"
else
setenv PATH "/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin"
endif
else
#add sbin directories to the path
foreach p ( /usr/local/sbin /usr/sbin )
switch (":${PATH}:")
case "*:${p}:*":
breaksw
default:
: # 光标在此等待命令
head 显示开头几行
选项与参数:
-n 后面接数字,代表显示几行的意思!(包括空行)
[root@LuoKing etc]# head -n 20 csh.login
# /etc/csh.login
# System wide environment and startup programs, for login setup
if ( ! ${?PATH} ) then
if ( $uid == 0 ) then
setenv PATH "/usr/local/sbin:/usr/sbin:/usr/local/bin:/usr/bin"
else
setenv PATH "/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin"
endif
else
#add sbin directories to the path
foreach p ( /usr/local/sbin /usr/sbin )
switch (":${PATH}:")
case "*:${p}:*":
breaksw
default:
if ( $uid == 0 ) then
set path = ( ${p} ${path:q} )
else
tail得到文件后几行
选项与参数:
-n 后面接数字,代表显示几行的意思!(包括空行)
[root@LuoKing etc]# head -n 20 csh.login
# /etc/csh.login
# System wide environment and startup programs, for login setup
if ( ! ${?PATH} ) then
if ( $uid == 0 ) then
setenv PATH "/usr/local/sbin:/usr/sbin:/usr/local/bin:/usr/bin"
else
setenv PATH "/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin"
endif
else
#add sbin directories to the path
foreach p ( /usr/local/sbin /usr/sbin )
switch (":${PATH}:")
case "*:${p}:*":
breaksw
default:
if ( $uid == 0 ) then
set path = ( ${p} ${path:q} )
else
[root@LuoKing etc]# tail -n 20 csh.login
endsw
end
endif
setenv HOSTNAME `/usr/bin/hostname`
set history=1000
if ( -d /etc/profile.d ) then
set nonomatch
foreach i ( /etc/profile.d/*.csh /etc/profile.d/csh.local )
if ( -r "$i" ) then
if ($?prompt) then
source "$i"
else
source "$i" >& /dev/null
endif
endif
end
unset i nonomatch
endif