Linux小推车Linux基础

Linux Day3: cat/nl/head/tail

2018-10-04  本文已影响21人  泥人吴

2.3 档案内容查阅

  • 直接检视档案内容可以使用 cat/tac/nl 这几个命令!

cat /etc/issue 
Ubuntu 16.04.3 LTS \n \l

给上面的例子加印行号:
用 -n查看:

 cat -n /etc/issue
     1  Ubuntu 16.04.3 LTS \n \l
     2  

用-b查看:

cat -b /etc/issue
     1  Ubuntu 16.04.3 LTS \n \l
  • cat配合more/less 效果更好。


$ nl /etc/issue
     1  Ubuntu 16.04.3 LTS \n \l
       
$ nl -b a /etc/issue
     1  Ubuntu 16.04.3 LTS \n \l
     2  
$ nl -b a -n rz /etc/issue
000001  Ubuntu 16.04.3 LTS \n \l
000002  
$ nl -b a -n rz -w3 /etc/issue
001 Ubuntu 16.04.3 LTS \n \l
002 
$ nl -b a -n rz -w2 /etc/issue
01  Ubuntu 16.04.3 LTS \n \l
02  

nl 可以将输出的档案内容自动的补上行号!其预设的结果与cat -n 有点不太一样 , nl 可以将行号做比较多的显示设计,包括位数与是否补齐 0 等等功能。


$ head /etc/inputrc 
# /etc/inputrc - global inputrc for libreadline
# See readline(3readline) and `info rluserman' for more information.

# Be 8 bit clean.
set input-meta on
set output-meta on

# To allow the use of 8bit-characters like the german umlauts, uncomment
# the line below. However this makes the meta key not work as a meta key,
# which is annoying to those which don't need to type in 8-bit characters.

若要显示前面20行,head -n 20 /etc/inputrc;

$ head -n 20 /etc/inputrc
# /etc/inputrc - global inputrc for libreadline
# See readline(3readline) and `info rluserman' for more information.

# Be 8 bit clean.
set input-meta on
set output-meta on

# To allow the use of 8bit-characters like the german umlauts, uncomment
# the line below. However this makes the meta key not work as a meta key,
# which is annoying to those which don't need to type in 8-bit characters.

# set convert-meta off

# try to enable the application keypad when it is called.  Some systems
# need this to enable the arrow keys.
# set enable-keypad on

# see /usr/share/doc/bash/inputrc.arrows for other codes of arrow keys

# do not bell on tab-completion

问题: 好像也没有20行?

2.后面100行如果不打印:head -n -100/etc/man.config(注意-100)。


tail(取出后面几行)
选项与参数:

  1. -n:后面数字,代表显示几行的意思。
  2. -f: 表示持续侦测后面所接的 档名,要等到按下【ctrl】-c 才会结束tail的侦测。
  3. 与head相比较记忆:tail -n +100 /etc/man.config代表从改档案100行以后都会被列出来。
  4. 我的tail与head有同样的问题存在样。
  • 需要显示 /etc/man.config 的11行到20行?
  • head -n 20 /etc/man.config l tail -n 10需要用到管道命令,后面学习。

od:非纯文本文件
选项或参数:

  1. -t: 后面可以接各种【类型(TYPE0】的输出,例如:
    a :利用默认的字符来输出;(有点多,显示不完)
    c :使用ASCⅡ字符来输出。
上一篇下一篇

猜你喜欢

热点阅读