每天学一点linux(8)--查看文件内容

来源:互联网 发布:端口23连接失败解决 编辑:程序博客网 时间:2024/06/15 08:21

查看文件内容

  • cat(concatenate) 连续显示文件内容
cat [-AbEnTv]-A 显示特殊字符,相当于-ETv-b 显示行号,空白行不显示-E 显示断行字符$-n 显示行号,空白行也显示-T 显示tab为^I-v 显示特殊字符e.g.:cat -n test.txt       1  cross every river                                                                                                                                                               2                                                                                                                                                                                  3  can you hear me I'm calling                                                                                                                                                     4  can you hear me I say                                                                                                                                                           5                                                                                                                                                                                  6  I would cross every river                                                                                                                                                       7  I would sail every sea                                                                                                                                                          8                                                                                                                                                                                  9  I would climb every mountain                                                                                                                                                   10  If it would bring you back to me  cat -n test.txt         1  cross every river                                                                                                                                                               2                                                                                                                                                                                  3  can you hear me I'm calling                                                                                                                                                     4  can you hear me I say                                                                                                                                                           5                                                                                                                                                                                  6  I would cross every river                                                                                                                                                       7  I would sail every sea                                                                                                                                                          8                                                                                                                                                                                  9  I would climb every mountain                                                                                                                                                   10  If it would bring you back to me   
  • tac 反向连续显示文件内容
tac test.txt                                                                                                                                                                                                                                                                                                      If it would bring you back to me                                                                                                                                                       I would climb every mountain                                                                                                                                                           I would sail every sea                                                                                                                                                                 I would cross every river                                                                                                                                                              can you hear me I say                                                                                                                                                                  can you hear me I'm calling                                                                                                                                                            cross every river           
  • nl 添加行号打印
nl [-bnw] 文件-----------b :指定行号显示的方式    -b a 显示行号,空行也不例外    -b t 显示行号,空行不显示-n :指定显示行号的方式    -n ln 显示在屏幕的最左边    -n rn 显示在屏幕的最右边,不加零    -n rz 显示在屏幕的最右边,加零-w :指定行号字段占的位数

可翻页查看文件内容

  • more 按页显示
more [-dlfpcsu] [-num] [+/pattern] [+linenum] [file ...]  ---------------------d 提示用户"[Press space to continue, 'q' to quit.]",当用户按下非法按键时,提示"[Press 'h' for instructions.]"-p 清空屏幕显示____________________命令:h或?显示命令空格:向下翻页enter:向下翻滚动一行= :显示当前行号/patten :搜索b:向前翻页q:退出:f :显示当前文件名和行号:n :去后面第K个文件,默认为1:p :去前面第k个文件,默认为1
  • less 按页显示,无需一次性读取整个文件,速度较快
less比more更加灵活

显示文件头尾(head、tail)

  • head 显示头几行
head [-n number]文件————————————————————————————————————参数解释-n 接数字代表行数,number 为负时,显示前(总行数-number)行
  • tail 显示结尾几行
tail [-n number] 文件number表示显示行数——————————————————————————————————————参数解释-n 接数字代表行数,*tail -n +20 文件名 //显示后(总行数-20)行-f 表示持续监测后面所接的文件,知道ctl-c才结束 //文件更改时,会及时显示在屏幕上

显示非纯文本文档

  • od
od [-t type]文件———————————————参数解释-t : 解各种类型    a 默认字符输出    c ASCII字符输出    d 十进制(decimal)输出数据    f 利用浮点数来输出数据    o 利用八进制输出数据    x 利用十六进制输出数据    

修改文件时间戳

  • touch 修改文件时间戳
    linux下记录的文件时间
    • modification time (mtime) 文件内容修改时,会更新该时间
    • status time (ctime) 文件状态改变时会更新该时间,如权限和属性
    • access time (atime) 文件内容被读取时会更新该时间。
touch [-acdmt] 文件__________________参数解释-a 仅修改access time-c 不创建新文件-d 接欲修订的日期,也可使用--date=“日期或时间”-m 仅修改mtime-t 接欲修订的时间
0 0
原创粉丝点击