linux查看文件内容

1.查看文件类型

file命令是一个可以探测文件内部并决定文案金类型的命令

2.查看整个文件

2.1 cat 命令

[xudongliu@sky python]$ cat -n test1  #n 给所有的行加上行号
     1  hello
     2  this is test file
     3  that we will
     4  use to 
     
[xudongliu@sky python]$ cat -b test1  #-b 给有文本的行加上行号

     1  hello
     2  this is test file
     3  that we will
     4  use to 

[xudongliu@sky python]$ cat -T test1   #替换制表符

hello
this is test file
that we will
use to 

2.2 more命令

more命令查看文件内容,分页查看,通过按空格或者回车键逐步向前的方式浏览文件。按q退出。

2.3 less 命令

less命令的操作和more的命令基本一样,一次显示一屏的文件内容。

3.查看部分文件

3.1 查看部分文件

3.1.1 tail 命令

tail命令会显示文件的后几行,默认情况下是十行。

[xudongliu@sky python]$ cat test2 
NAME
       ls - list directory contents
       --block-size=SIZE
              scale  sizes by SIZE before printing them; e.g., '--block-size=M'
              prints sizes in units of 1,048,576 bytes; see SIZE format below

       -B, --ignore-backups
              do not list implied entries ending with ~

       -c     with -lt: sort by, and show, ctime (time of last modification  of
              file  status  information); with -l: show ctime and sort by name;
              otherwise: sort by ctime, newest first

       -C     list entries by columns

       --color[=WHEN]
              colorize the output; WHEN can be 'always' (default  if  omitted),
              'auto', or 'never'; more info below

       -d, --directory
              list directories themselves, not their contents

       -D, --dired
              generate output designed for Emacs' dired mode

       -f     do not sort, enable -aU, disable -ls --color

       -F, --classify
              append indicator (one of */=>@|) to entries

       --file-type
              likewise, except do not append '*'

       --format=WORD
              across  -x,  commas -m, horizontal -x, long -l, single-column -1,
              verbose -l, vertical -C

[xudongliu@sky python]$ tail test2   #查看test2文件的后十行
       -F, --classify
              append indicator (one of */=>@|) to entries

       --file-type
              likewise, except do not append '*'

       --format=WORD
              across  -x,  commas -m, horizontal -x, long -l, single-column -1,
              verbose -l, vertical -C

[xudongliu@sky python]$ tail -n 2 test2  #查看后两行
              verbose -l, vertical -C

tail -n -f destination 其中-f 参数可以设定想要的数字来保证其显示几行。

3.1.2 head 命令

类似于tail命令,但是显示的是从头显示。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容