Linux 终端命令之文件浏览(1) cat

18647a9c4d804f0eacedc1984bee2940.png

Linux 文件浏览命令

cat, more, less, head, tail,此五个文件浏览类的命令皆为外部命令。

hann@HannYang:~$ which cat
/usr/bin/cat
hann@HannYang:~$ which more
/usr/bin/more
hann@HannYang:~$ which less
/usr/bin/less
hann@HannYang:~$ which head
/usr/bin/head
hann@HannYang:~$ which tail
/usr/bin/tail

(1) cats

英文帮助

NAME
       cat - concatenate files and print on the standard output

SYNOPSIS
       cat [OPTION]... [FILE]...

DESCRIPTION
       Concatenate FILE(s) to standard output.

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

       -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

EXAMPLES
       cat f - g
              Output f's contents, then standard input, then g's contents.

       cat    Copy standard input to standard output.

AUTHOR
       Written by Torbjorn Granlund and Richard M. Stallman.

REPORTING BUGS
       GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
       Report cat translation bugs to <https://translationproject.org/team/>

COPYRIGHT
       Copyright   ©   2018   Free   Software   Foundation,  Inc.   License  GPLv3+:  GNU  GPL  version  3  or  later
       <https://gnu.org/licenses/gpl.html>.
       This is free software: you are free to change and redistribute it.  There is NO WARRANTY, to the  extent  per‐mitted by law.


中文注解 

cat  连接文件并在标准输出上打印

可以用它来显示文件内容,创建文件,还可以用它来显示控制字符。

cat命令的一般形式为:

cat [options] filename1 ... filename2 ...

帮助

hann@HannYang:~$ cat --help
Usage: cat [OPTION]... [FILE]...
Concatenate FILE(s) to standard output.With no FILE, or when FILE is -, read standard input.-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 exitExamples: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: <https://www.gnu.org/software/coreutils/>
Report cat translation bugs to <https://translationproject.org/team/>
Full documentation at: <https://www.gnu.org/software/coreutils/cat>
or available locally via: info '(coreutils) cat invocation'

版本

hann@HannYang:~$ cat --version
cat (GNU coreutils) 8.30
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.Written by Torbjorn Granlund and Richard M. Stallman.

注释

1. 如果希望显示名为myfile的文件,可以用:

$ cat myfile 

2. 在使用cat命令时要注意,它不会在文件分页符处停下来;它会一下显示完整个文件。如果希望每次显示一页,可以使用more命令或把cat命令的输出通过管道传递到另外一个具有分页功能的命令中,如:

$ cat myfile | more

上面这个写法与 $ more myfile 等效

3. 参数 -n 或 -number 可以自动在每一行的显示内容前标注上行号,如:

hann@HannYang:~$ cat -n cmd1.txt1  alias - Define or display aliases.2  alias: alias [-p] [name[=value] ... ]3  bg - Move jobs to the background.4  bg: bg [job_spec ...]5  bind - Set Readline key bindings and variables.6  ......

4. 如果希望显示myfile1、myfile2、myfile3这三个文件,可以用:

$ cat myfile1 myfile2 myfile3

5. 如果希望创建一个名为bigfile的文件,该文件包含上述三个文件的内容,可以把上面命令的输出重定向到新文件中,这就是cat连接文件的功能

$ cat myfile1 myfile2 myfile3 > bigfile

6. 有一点要提醒的是,如果在敲入了cat以后就直接按回车,该命令会等你输入字符。也是说帮助中说的“With no FILE, or when FILE is -, read standard input.”,没有文件时则从标准输入(默认设备就是键盘)中读取内容。如果你本来就是要输入一些字符,那么它除了会在你输入时在屏幕上显示以外,还会再回显这些内容;最后按<Ctrl-d>结束输入即可。

hann@HannYang:~$ cat
123456789
123456789
abcdefg
abcdefg

7. 如果希望创建一个新文件,并向其中输入一些内容,只需使用cat命令把标准输出重定向到该文件中,这时cat命令的输入是标准输入—键盘,你输入一些文字,输入完毕后按<Ctrl-d>结束输入。这就是一个非常简单的文字编辑器!

hann@HannYang:~$ cat > myfile
123456789
abcdefg
hann@HannYang:~$ cat myfile
123456789
abcdefg

上面这个功能,与Dos命令中的copy con file类似:

C:\Users\boyso>copy con myfile
123456
abcdef
^Z
已复制         1 个文件。

C:\Users\boyso>type myfile
123456
abcdef

Dos系统是用<Ctrl-z>退出输出的。

8.  连接多个文件时,还能用键盘输入一些内容。即是前面第6点中提到的“or when FILE is -” ,也就当文件参数有“-”减号时,就从键盘输入内容直到按<Ctrl-d>结束输入。

例如以下操作,连接文件aa,bb成cc,并且两个文件间用"==========="隔开:

hann@HannYang:~$ cat aa
abcd
efg
hann@HannYang:~$ cat bb
123456
7890
hann@HannYang:~$ cat aa - bb > cc
===========
hann@HannYang:~$ cat cc
abcd
efg
===========
123456
7890

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/70606.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

24近3年内蒙古大学自动化考研院校分析

今天给大家带来的是内蒙古大学控制考研分析 满满干货&#xff5e;还不快快点赞收藏 一、内蒙古大学 学校简介 内蒙古大学位于内蒙古自治区首府、历史文化名城呼和浩特市&#xff0c;距北京400余公里&#xff0c;是中华人民共和国成立后党和国家在民族地区创办的第一所综合大…

【【verilog典型电路设计之FIR滤波器的设计】】

verilog典型电路设计之FIR滤波器的设计 我们常用的FIR滤波器称为有限冲激响应 是一种常用的数字滤波器 &#xff0c;采用对已输入样值的加权和来形成它的输出。 对于输入序列X[n] 的FIR滤波器可用下图所示的结构示意图来表示&#xff0c;其中X[n] 是输入数据流。各级的输入连…

java八股文面试[java基础]——String StringBuilder StringBuffer

String类型定义&#xff1a; final String 不可以继承 final char [] 不可以修改 String不可变的好处&#xff1a; hash值只需要算一次&#xff0c;当String作为map的key时&#xff0c; 不需要考虑hash改变 天然的线程安全 知识来源&#xff1a; 【基础】String、StringB…

【云原生】Docker 详解(二):Docker 架构及工作原理

Docker 详解&#xff08;二&#xff09;&#xff1a;Docker 架构及工作原理 Docker 在运行时分为 Docker 引擎&#xff08;服务端守护进程&#xff09; 和 客户端工具&#xff0c;我们日常使用各种 docker 命令&#xff0c;其实就是在使用 客户端工具 与 Docker 引擎 进行交互。…

【Kafka】2.在SpringBoot中使用官方原生java版Kafka客户端

目 录 1. 新建一个消息生产者2. 新建一个消息消费者3. 测 试 在开始之前&#xff0c;需要先做点准备工作&#xff0c;用 IDEA 新建一个 Maven 项目&#xff0c;取名 kafka-study&#xff0c;然后删掉它的 src 目录&#xff0c;接着在 pom.xml 里面引入下面的依赖。这个项目的作…

[oneAPI] 手写数字识别-LSTM

[oneAPI] 手写数字识别-LSTM 手写数字识别参数与包加载数据模型训练过程结果 oneAPI 比赛&#xff1a;https://marketing.csdn.net/p/f3e44fbfe46c465f4d9d6c23e38e0517 Intel DevCloud for oneAPI&#xff1a;https://devcloud.intel.com/oneapi/get_started/aiAnalyticsToolk…

在本地搭建WAMP服务器并通过端口实现局域网访问(无需公网IP)

文章目录 前言1.Wamp服务器搭建1.1 Wamp下载和安装1.2 Wamp网页测试 2. Cpolar内网穿透的安装和注册2.1 本地网页发布2.2 Cpolar云端设置2.3 Cpolar本地设置 3. 公网访问测试4. 结语 前言 软件技术的发展日新月异&#xff0c;各种能方便我们生活、工作和娱乐的新软件层出不穷&a…

第57步 深度学习图像识别:CNN可视化(Pytorch)

基于WIN10的64位系统演示 一、写在前面 由于不少模型使用的是Pytorch&#xff0c;因此这一期补上基于Pytorch实现CNN可视化的教程和代码&#xff0c;以SqueezeNet模型为例。 二、CNN可视化实战 继续使用胸片的数据集&#xff1a;肺结核病人和健康人的胸片的识别。其中&…

考研算法第46天: 字符串转换整数 【字符串,模拟】

题目前置知识 c中的string判空 string Count; Count.empty(); //正确 Count ! null; //错误c中最大最小宏 #include <limits.h>INT_MAX INT_MIN 字符串使用发运算将字符加到字符串末尾 string Count; string str "liuda"; Count str[i]; 题目概况 AC代码…

【数据分析入门】Numpy进阶

目录 一、数据重塑1.1 透视1.2 透视表1.3 堆栈/反堆栈1.3 融合 二、迭代三、高级索引3.1 基础选择3.2 通过isin选择3.3 通过Where选择3.4 通过Query选择3.5 设置/取消索引3.6 重置索引3.6.1 前向填充3.6.2 后向填充 3.7 多重索引 四、重复数据五、数据分组5.1 聚合5.2 转换 六、…

腾讯云GPU服务器GN7实例NVIDIA T4 GPU卡

腾讯云GPU服务器GN7实例搭载1颗 NVIDIA T4 GPU&#xff0c;8核32G配置&#xff0c;系统盘为100G 高性能云硬盘&#xff0c;自带5M公网带宽&#xff0c;系统镜像可选Linux和Windows&#xff0c;地域可选广州/上海/北京/新加坡/南京/重庆/成都/首尔/中国香港/德国/东京/曼谷/硅谷…

机器学习---对数几率回归

1. 逻辑回归 逻辑回归&#xff08;Logistic Regression&#xff09;的模型是一个非线性模型&#xff0c; sigmoid函数&#xff0c;又称逻辑回归函数。但是它本质上又是一个线性回归模型&#xff0c;因为除去sigmoid映射函 数关系&#xff0c;其他的步骤&#xff0c;算法都是…