Linux文件管理命令(cat)

先看官方命令帮助

[root@luoqiu ~]# cat --help 
Usage: cat [OPTION]... [FILE]...
Concatenate FILE(s), or standard input, to standard output.

  -A, --show-all           equivalent to -vET
  -b, --number-nonblank    number nonempty output lines, overrides -n
  -e                       equivalent to -vE
  -E, --show-ends          display $ at end of each line
  -n, --number             number all output lines
  -s, --squeeze-blank      suppress repeated empty output lines
  -t                       equivalent to -vT
  -T, --show-tabs          display TAB characters as ^I
  -u                       (ignored)
  -v, --show-nonprinting   use ^ and M- notation, except for LFD and TAB
      --help     display this help and exit
      --version  output version information and exit

With no FILE, or when FILE is -, read standard input.

Examples:
  cat f - g  Output f's contents, then standard input, then g's contents.
  cat        Copy standard input to standard output.

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'cat invocation'

可选的选项

-A, --show-all 相当于 -vET
-b, --number-nonblank 非空数字输出行,覆盖 -n
-e 相当于 -vE
-E, --show-ends 在每行末尾显示 $
-n, --number 所有输出行的编号
-s, --squeeze-blank 抑制重复的空输出行
-t 相当于 -vT
-T, --show-tabs 将制表符显示为 ^I
-u(忽略)
-v, --show-nonprinting 使用 ^ 和 M- 表示法,LFD 和 TAB 除外
   --help 显示此帮助并退出
   --version 输出版本信息并退出
   没有 FILE 或 FILE 为 - 时,读取标准输入。

举例

例子:
# 注意 - 和 g之间有一个空格
   cat f - g 输出 f 的内容,然后是标准输入,然后是 g 的内容。
   cat 将标准输入复制到标准输出。
# 查看一个文件的时候同时在内容的前面加上行号 -n ,如果希望空行没有行号使用 -b
[root@luoqiu ~]# cat nginx.conf -n
     1
     2  #user  nobody;
     3  worker_processes  1;
     4
     5  #error_log  logs/error.log;
     6  #error_log  logs/error.log  notice;
     7  #error_log  logs/error.log  info;
     8
     9  #pid        logs/nginx.pid;
     10 ......
[root@luoqiu ~]# cat -b nginx.conf # 选项 -b 和 -n 在文件名称前面后面都可以

     1  #user  nobody;
     2  worker_processes  1;

     3  #error_log  logs/error.log;
     4  #error_log  logs/error.log  notice;
     5  #error_log  logs/error.log  info;

     6  #pid        logs/nginx.pid;


     7  events {
   
     8      worker_connections  1024;
     9  }
# 当遇到一个文件中有2行及以上的连续空行时,使用 -s 参数将不显示多余的空行,可以搭配-n或者-b使用
[root@luoqiu ~]# cat -n nginx2.conf 
     1  a
     2
     3
     4  b
     5
     6
     7
     8  c
[root@luoqiu ~]# cat -ns nginx2.conf 
     1  a
     2
     3  b
     4
     5  c
[root@luoqiu ~]# 
# 清空文件内容
[root@luoqiu ~]# cat /dev/null > nginx3.conf 
[root@luoqiu ~]# cat nginx3.conf 

cat 也可以用来制作镜像文件。例如要制作软盘的镜像文件,将软盘放好后输入:

cat /dev/fd0 > OUTFILE

相反的,如果想把 image file 写到软盘,输入:

cat IMG_FILE > /dev/fd0

    1. OUTFILE 指输出的镜像文件名。
    1. IMG_FILE 指镜像文件。
    1. 若从镜像文件写回 device 时,device 容量需与相当。
    1. 通常用制作开机磁片。

相关推荐

  1. Linux文件管理命令cat

    2023-12-12 09:36:04       51 阅读
  2. Linux文件和目录管理命令---- cat 命令

    2023-12-12 09:36:04       65 阅读
  3. Linux cat 命令

    2023-12-12 09:36:04       63 阅读
  4. Linux】`cat` 命令详解:查看、合并文件的利器

    2023-12-12 09:36:04       31 阅读
  5. Linux 文件管理命令----pwd 命令

    2023-12-12 09:36:04       58 阅读
  6. Linux 常用命令 cat

    2023-12-12 09:36:04       44 阅读
  7. 10个linux文件管理命令

    2023-12-12 09:36:04       57 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-12 09:36:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-12 09:36:04       100 阅读
  3. 在Django里面运行非项目文件

    2023-12-12 09:36:04       82 阅读
  4. Python语言-面向对象

    2023-12-12 09:36:04       91 阅读

热门阅读

  1. react面试题总结1

    2023-12-12 09:36:04       43 阅读
  2. react内置组件之<Profiler></Profiler>

    2023-12-12 09:36:04       52 阅读
  3. var、let、const 的区别?

    2023-12-12 09:36:04       63 阅读
  4. BERT、GPT学习问题个人记录

    2023-12-12 09:36:04       58 阅读
  5. Android 13 - Media框架(21)- ACodec(三)

    2023-12-12 09:36:04       56 阅读
  6. 前端js优化表单中单个输入框的回车提交事件

    2023-12-12 09:36:04       53 阅读
  7. 解决Zabbix问题Utilization of ODBC poller processes over 75%

    2023-12-12 09:36:04       59 阅读