Linux常用基本命令(cat)
cat命令
作用:连接多个文件并且打印到屏幕输出,或者重定向到其他文件,也可以用来查看显示单个文件,或者多个文件。
格式:
cat [option] [file]
1,最简单的用法,直接跟文件名称,查看文件内容
ghostwu@dev:~/linux/cat$ ls
ghostwu@dev:~/linux/cat$ echo 'hello,my name is ghostwu, how are you?' > test.txt
ghostwu@dev:~/linux/cat$ cat test.txt
hello,my name is ghostwu, how are you?
ghostwu@dev:~/linux/cat$
2,也可以使用如下方式,向文件写入或者追加内容
ghostwu@dev:~/linux/cat$ ls
test.txt
ghostwu@dev:~/linux/cat$ cat >> test.txt << EOF
> 这是我新增的内容
> 这是第三行内容
> EOF
ghostwu@dev:~/linux/cat$ cat test.txt
hello,my name is ghostwu, how are you?
这是我新增的内容
这是第三行内容
3,-n与-b 都是对文件进行编号,-b不会对空行编号
ghostwu@dev:~/linux/cat$ cat test.txt
hello,my name is ghostwu, how are you?
这是我新增的内容
这是第三行内容
ghostwu@dev:~/linux/cat$ cat >> test.txt << EOF
>
>
> 上面加入了两个空行
> EOF
ghostwu@dev:~/linux/cat$ cat test.txt
hello,my name is ghostwu, how are you?
这是我新增的内容
这是第三行内容 上面加入了两个空行
ghostwu@dev:~/linux/cat$ cat -n test.txt
hello,my name is ghostwu, how are you?
这是我新增的内容
这是第三行内容 上面加入了两个空行
ghostwu@dev:~/linux/cat$ cat -b test.txt
hello,my name is ghostwu, how are you?
这是我新增的内容
这是第三行内容 上面加入了两个空行
ghostwu@dev:~/linux/cat$
4,-E 在每一行的行尾显示美元符号
ghostwu@dev:~/linux/cat$ cat -E test.txt
hello,my name is ghostwu, how are you?$
这是我新增的内容$
这是第三行内容$
$
$
上面加入了两个空行$
5,-s: 把两个以上连续的空行,变成一个
ghostwu@dev:~/linux/cat$ cat -n test.txt
hello,my name is ghostwu, how are you?
这是我新增的内容
这是第三行内容 上面加入了两个空行 上面加入了一个空行
ghostwu@dev:~/linux/cat$ cat -ns test.txt
hello,my name is ghostwu, how are you?
这是我新增的内容
这是第三行内容 上面加入了两个空行 上面加入了一个空行
6,利用/dev/null 删除文件内容
ghostwu@dev:~/linux/cat$ cat test.txt
hello,my name is ghostwu, how are you?
这是我新增的内容
这是第三行内容 上面加入了两个空行 上面加入了一个空行
ghostwu@dev:~/linux/cat$ cat /dev/null > test.txt
ghostwu@dev:~/linux/cat$ cat test.txt
7,利用重定向写入内容
ghostwu@dev:~/linux/cat$ cat test.txt
ghostwu@dev:~/linux/cat$ cat > test.txt
this is ghostwu
how are you
ghostwu@dev:~/linux/cat$ cat test.txt
this is ghostwu
how are you
内容输入完毕,用ctrl+d或者ctrl+c中断输入
8,显示多个文件内容
ghostwu@dev:~/linux/cat$ cat > abc.txt
this is abc.txt
ghostwu@dev:~/linux/cat$ cat test.txt abc.txt
this is ghostwu
how are you
this is abc.txt
Linux常用基本命令(cat)的更多相关文章
- Linux常用基本命令(less)
转: Linux常用基本命令(less) LESS:跟more命令的功能类似,都是用于分页显示内容,但是他的性能比more更高,功能比more更丰富,他读取文件是按需加载 格式: less [opti ...
- Linux 常用基本命令及应用技巧
需要pdf 版 联系我 我的文件中有目录一.Linux 的常用基本命令................................................................. ...
- Linux常用命令 - cat命令详解
21篇测试必备的Linux常用命令,每天敲一篇,每次敲三遍,每月一循环,全都可记住!! https://www.cnblogs.com/poloyy/category/1672457.html 获取t ...
- 【Linux】linux常用基本命令(转)
(转自:http://blog.csdn.net/xiaoguaihai/article/details/8705992) Linux中许多常用命令是必须掌握的,这里将我学linux入门时学的一些常用 ...
- 【Linux】linux常用基本命令
Linux中许多常用命令是必须掌握的,这里将我学linux入门时学的一些常用的基本命令分享给大家一下,希望可以帮助你们. 这个是我将鸟哥书上的进行了一下整理的,希望不要涉及到版权问题. 1.显示日 ...
- linux常用基本命令
Linux中许多常用命令是必须掌握的,这里将我学linux入门时学的一些常用的基本命令分享给大家一下,希望可以帮助你们. 系统信息 arch 显示机器的处理器架构(1) uname -m 显示机器 ...
- linux常用基本命令整理小结
linux系统遵循的基本原则 由目标单一的小程序组成,组合小程序完成复杂任务: 一切皆文件: 尽量避免捕捉用户接口: 配置文件保存为纯文本文件: Linux命令行常识 命令格式 命令+选项+参数 选项 ...
- Linux 常用基本命令
这两天有俩哥们问了我linux的事,问我在工作中需不需要用到,需不需要学会 一个是工作1年不到的,我跟他说,建议你学学,在以后肯定是要用到的,虽然用到的机会不多,但是会总比不会好 另一个是工作6年的, ...
- Linux常用基本命令:三剑客命令之-awk内置函数用法
awk的内置函数大致可以分类为算数函数.字符串函数.时间函数.其他函数等 算数函数 最常用的算数函数有rand函数.srand函数.int函数. 可以使用rand函数生成随机数,但是使用rand函数时 ...
随机推荐
- 201621123018《Java程序设计》第5周学习报告
1. 本周学习总结 1.1 写出你认为本周学习中比较重要的知识点关键词 接口.interface.implements.Comparable.Comparator. 1.2 尝试使用思维导图将这些关键 ...
- 556. Next Greater Element III
Given a positive 32-bit integer n, you need to find the smallest 32-bit integer which has exactly th ...
- java打包jar后,使之一直在linux上运行,不随终端退出而关闭
nohup java -jar xxx.jar&
- POJ 2545
#include<iostream> #include<stdio.h> #include<iomanip> #define MAXN 100000 using n ...
- 生成代码的代码 之 POJO生成器
我们在写Java代码时候,有时候需要写一些POJO类,也就是只有一些属性和get, set方法的类.例如,在写REST 服务时候,利用Jersery + Jackson,可以把输入的JSON字符串自动 ...
- 集合框架_DAY16
1:List及其子类(掌握) (1)List的特点: Collection |--List:元素有序(存入顺序和取出顺序一致),可重复. |--Set:元素无序,唯一. ...
- ASP.NET MVC网站使用新浪微博账号登录
首先到http://open.weibo.com/development 注册一个开发者账号. 然后可以点微连接--网站接入 会分配App Key 和App Secret 然后点高级信息 在这里设置回 ...
- What does -> do in clojure?
https://stackoverflow.com/questions/4579226/what-does-do-in-clojure
- Hadoop2源码分析-MapReduce篇
1.概述 前面我们已经对Hadoop有了一个初步认识,接下来我们开始学习Hadoop的一些核心的功能,其中包含mapreduce,fs,hdfs,ipc,io,yarn,今天为大家分享的是mapred ...
- 利用VS(Visual Studio)自带的工具查看DLL文件的信息
装完VS后,就可以使用其自带的dumpbin命令来查看DLL文件的信息, 首先要打开VS的Developer Command Prompt命令窗口,打开不同版本的VS可能略有不同, 请参考:http: ...