第1章 BashShell命令------------(stat、file、cat、more、less)

本文介绍了Bash Shell中的几个重要命令,包括stat用于查看文件统计数据,file用于识别文件类型,以及cat、more、less三个用于查看文件内容的命令。stat命令提供文件详细状态,file命令区分文本、可执行和数据文件,cat一次性显示所有内容,more每页显示并暂停,less则支持滚动和搜索功能。
摘要由CSDN通过智能技术生成

1.2.5 查看文件内容命令

1.查看文件统计数据(stat)

stat命令提供文件系统中文件状态的完整摘要,执行该命令的结果可以显示目标文件的所有信息,甚至包括存储文件的设备的主设备号和次级设备号。执行stat --h查看该命令的参数:

根据上述,执行stat实例的结果如下所示:

         

 2.查看文件类型(file)

file命令是一个方便的实用程序。它可以查看文件内部并确定文件类型。使用file --h查看file命令的使用参数:

        

file命令将文件分为以下3类:

Ø  文本文件:包含可打印字符的文件

Ø  可执行文件:可以在系统运行的文件

Ø  数据文件:包括不可打印的二进制字符的文件,但也不可以在系统运行。

file 命令不仅能确定该文件包含文本,而且能确定文本的字符码格式。示例如下图所示:

        

 3.查看整个文件内容(cat、more、less)

3.1 cat命令

cat是显示文本文件包含的所有内容的命令。通过cat --h查看该命令的参数列表:

       

根据上图所示,对cat命令使用的实例如下图所示:

         

3.2 more命令

cat命令主要缺点在于启动之后无法控制。未解决这个问题,开发人员创建了more,more命令显示文本文件,但是在显示完每页数据时停止。根据more --h查看more的参数使用说明:

        

根据上图所示,对more命令使用的实例以及对文本进行操作的命令如下图所示:

        

 3.3 less命令        

less命令用于向前或向后滚动文本文件,以及一些高级的搜索功能。less命令还可以在命令读完整个文件之前显示文件内容。cat和more没有这项功能,因而less可以轻松应付大型文件。less命令一次显示一屏幕的文本。通过less --h查看less的参数,由于参数太多,在这就不附图。 

         操作实例如下:

        

         less命令在提示符提供更多的信息,它显示了文件的总行数以及当前显示的行数范围。less命令的帮助手册文档内容如下:

LESS(1)                                                        General Commands Manual                                                       LESS(1)



NAME
       less - opposite of more

SYNOPSIS
       less -?
       less --help
       less -V
       less --version
       less [-[+]aABcCdeEfFgGiIJKLmMnNqQrRsSuUVwWX~]
            [-b space] [-h lines] [-j line] [-k keyfile]
            [-{oO} logfile] [-p pattern] [-P prompt] [-t tag]
            [-T tagsfile] [-x tab,...] [-y lines] [-[z] lines]
            [-# shift] [+[+]cmd] [--] [filename]...
       (See the OPTIONS section for alternate option syntax with long option names.)


DESCRIPTION
       Less  is  a program similar to more (1), but it has many more features.  Less does not have to read the entire input file before starting, so
       with large input files it starts up faster than text editors like vi (1).  Less uses termcap (or terminfo on some systems), so it can run  on
       a variety of terminals.  There is even limited support for hardcopy terminals.  (On a hardcopy terminal, lines which should be printed at the
       top of the screen are prefixed with a caret.)

       Commands are based on both more and vi.  Commands may be preceded by a decimal number, called N in the descriptions  below.   The  number  is
       used by some commands, as indicated.


COMMANDS
       In  the  following  descriptions,  ^X  means  control-X.   ESC  stands for the ESCAPE key; for example ESC-v means the two character sequence
       "ESCAPE", then "v".

       h or H Help: display a summary of these commands.  If you forget all the other commands, remember this one.

       SPACE or ^V or f or ^F
              Scroll forward N lines, default one window (see option -z below).  If N is more than the screen size, only the final screenful is dis‐
              played.  Warning: some systems use ^V as a special literalization character.

       z      Like SPACE, but if N is specified, it becomes the new window size.

       ESC-SPACE
              Like SPACE, but scrolls a full screenful, even if it reaches end-of-file in the process.

       ENTER or RETURN or ^N or e or ^E or j or ^J
              Scroll forward N lines, default 1.  The entire N lines are displayed, even if N is more than the screen size.

       d or ^D
              Scroll  forward  N  lines,  default one half of the screen size.  If N is specified, it becomes the new default for subsequent d and u
              commands.

       b or ^B or ESC-v
              Scroll backward N lines, default one window (see option -z below).  If N is more than the screen size, only  the  final  screenful  is
              displayed.

       w      Like ESC-v, but if N is specified, it becomes the new window size.

       y or ^Y or ^P or k or ^K
              Scroll  backward N lines, default 1.  The entire N lines are displayed, even if N is more than the screen size.  Warning: some systems
              use ^Y as a special job control character.

       u or ^U
              Scroll backward N lines, default one half of the screen size.  If N is specified, it becomes the new default for subsequent  d  and  u
              commands.

       ESC-) or RIGHTARROW
              Scroll horizontally right N characters, default half the screen width (see the -# option).  If a number N is specified, it becomes the
              default for future RIGHTARROW and LEFTARROW commands.  While the text is scrolled, it acts as though the -S option (chop  lines)  were
              in effect.

       ESC-( or LEFTARROW
              Scroll  horizontally left N characters, default half the screen width (see the -# option).  If a number N is specified, it becomes the
              default for future RIGHTARROW and LEFTARROW commands.

       r or ^R or ^L
              Repaint the screen.

       R      Repaint the screen, discarding any buffered input.  Useful if the file is changing while it is being viewed.

       F      Scroll forward, and keep trying to read when the end of file is reached.  Normally this command would be used when already at the  end
              of  the  file.   It is a way to monitor the tail of a file which is growing while it is being viewed.  (The behavior is similar to the
              "tail -f" command.)

       ESC-F  Like F, but as soon as a line is found which matches the last search pattern, the terminal bell is rung and forward scrolling stops.

       g or < or ESC-<
              Go to line N in the file, default 1 (beginning of file).  (Warning: this may be slow if N is large.)

       G or > or ESC->
              Go to line N in the file, default the end of the file.  (Warning: this may be slow if N is large, or if N is not specified  and  stan‐
              dard input, rather than a file, is being read.)

       p or % Go to a position N percent into the file.  N should be between 0 and 100, and may contain a decimal point.

       P      Go to the line containing byte offset N in the file.

       {      If  a  left  curly bracket appears in the top line displayed on the screen, the { command will go to the matching right curly bracket.
              The matching right curly bracket is positioned on the bottom line of the screen.  If there is more than one left curly bracket on  the
              top line, a number N may be used to specify the N-th bracket on the line.

       }      If a right curly bracket appears in the bottom line displayed on the screen, the } command will go to the matching left curly bracket.
              The matching left curly bracket is positioned on the top line of the screen.  If there is more than one right curly bracket on the top
              line, a number N may be used to specify the N-th bracket on the line.

       (      Like {, but applies to parentheses rather than curly brackets.

       )      Like }, but applies to parentheses rather than curly brackets.

       [      Like {, but applies to square brackets rather than curly brackets.

       ]      Like }, but applies to square brackets rather than curly brackets.

       ESC-^F Followed by two characters, acts like {, but uses the two characters as open and close brackets, respectively.  For example, "ESC ^F <
              >" could be used to go forward to the > which matches the < in the top displayed line.

       ESC-^B Followed by two characters, acts like }, but uses the two characters as open and close brackets, respectively.  For example, "ESC ^B <
              >" could be used to go backward to the < which matches the > in the bottom displayed line.

       m      Followed by any lowercase letter, marks the current position with that letter.

       '      (Single  quote.)  Followed by any lowercase letter, returns to the position which was previously marked with that letter.  Followed by
              another single quote, returns to the position at which the last "large" movement command was executed.  Followed by a ^ or $, jumps to
              the  beginning  or  end  of  the  file respectively.  Marks are preserved when a new file is examined, so the ' command can be used to
              switch between input files.

       ^X^X   Same as single quote.

       /pattern
              Search forward in the file for the N-th line containing the pattern.  N defaults to 1.  The pattern is a regular expression, as recog‐
              nized by the regular expression library supplied by your system.  The search starts at the first line displayed (but see the -a and -j
              options, which change this).

              Certain characters are special if entered at the beginning of the pattern; they modify the type of search rather than become  part  of
              the pattern:

              ^N or !
                     Search for lines which do NOT match the pattern.

              ^E or *
                     Search  multiple files.  That is, if the search reaches the END of the current file without finding a match, the search contin‐
                     ues in the next file in the command line list.

              ^F or @
                     Begin the search at the first line of the FIRST file in the command line list, regardless of what is currently displayed on the
                     screen or the settings of the -a or -j options.

              ^K     Highlight any text which matches the pattern on the current screen, but don't move to the first match (KEEP current position).

              ^R     Don't interpret regular expression metacharacters; that is, do a simple textual comparison.

       ?pattern
              Search  backward  in the file for the N-th line containing the pattern.  The search starts at the line immediately before the top line
              displayed.

              Certain characters are special as in the / command:

              ^N or !
                     Search for lines which do NOT match the pattern.

              ^E or *
                     Search multiple files.  That is, if the search reaches the beginning of the current file without finding a  match,  the  search
                     continues in the previous file in the command line list.

              ^F or @
                     Begin  the  search at the last line of the last file in the command line list, regardless of what is currently displayed on the
                     screen or the settings of the -a or -j options.

              ^K     As in forward searches.

              ^R     As in forward searches.

       ESC-/pattern
              Same as "/*".

       ESC-?pattern
              Same as "?*".

       n      Repeat previous search, for N-th line containing the last pattern.  If the previous search was modified by ^N, the search is made  for
              the  N-th  line NOT containing the pattern.  If the previous search was modified by ^E, the search continues in the next (or previous)
              file if not satisfied in the current file.  If the previous search was modified by ^R,  the  search  is  done  without  using  regular
              expressions.  There is no effect if the previous search was modified by ^F or ^K.

       N      Repeat previous search, but in the reverse direction.

       ESC-n  Repeat previous search, but crossing file boundaries.  The effect is as if the previous search were modified by *.

       ESC-N  Repeat previous search, but in the reverse direction and crossing file boundaries.

       ESC-u  Undo  search  highlighting.   Turn  off  highlighting  of strings matching the current search pattern.  If highlighting is already off
              because of a previous ESC-u command, turn highlighting back on.  Any search command will also turn highlighting back on.   (Highlight‐
              ing can also be disabled by toggling the -G option; in that case search commands do not turn highlighting back on.)

       &pattern
              Display  only lines which match the pattern; lines which do not match the pattern are not displayed.  If pattern is empty (if you type
              & immediately followed by ENTER), any filtering is turned off, and all lines are displayed.  While filtering is in effect,  an  amper‐
              sand is displayed at the beginning of the prompt, as a reminder that some lines in the file may be hidden.

              Certain characters are special as in the / command:

              ^N or !
                     Display only lines which do NOT match the pattern.

              ^R     Don't interpret regular expression metacharacters; that is, do a simple textual comparison.

       :e [filename]
              Examine  a  new file.  If the filename is missing, the "current" file (see the :n and :p commands below) from the list of files in the
              command line is re-examined.  A percent sign (%) in the filename is replaced by the name of the current file.  A  pound  sign  (#)  is
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

WEL测试

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值