Linux shell命令之cat

cat:查看文件的内容、连接文件、创建一个或多个文件和重定向输出到终端或文件  用法:cat [选项] [文件]

1. $ cat hello.txt

显示hello.txt文本文件中的内容

2. $ cat -n file

-n选项,可以显示文件的内容和行号

3. $ cat -b file

-b选项,与-n类似,但只标识非空白行的行号

4. $ cat -e file

-e选项,将在每一行的末尾显示“$”字符,在需要将多行内容转换成一行时非常有用。

5. $ cat

只输入cat命令的话,它只是接收标准输入的内容并在标准输出中显示,所以在输入一行并按回车后会在接下来的一行显示相同的内容。

如:$ cat

hello world!

hello world!

$

重定向的话:

$ cat >hello

hello world!

(ctrl+D组合键退出,输入的内容 hello world! 会写入到文件hello中)

$ cat hello

hello world!

$

重定向操作符有两个: >和>>,前者是内容覆盖,后者是最文件的最后追加。

6. 连接多个文件的内容到一个新文件

$ cat test test1 > test2

$ cat test2

结果将显示test和test1中的内容。

时间: 2024-12-17 00:32:20

Linux shell命令之cat的相关文章

37条常用Linux Shell命令组合

序号 任务 命令组合 1 删除0字节文件 find . -type f -size 0 -exec rm -rf {} \; find . type f -size 0 -delete 2 查看进程,按内存从大到小排列 ps -e -o “%C : %p : %z : %a”|sort -k5 -nr 3 按cpu利用率从大到小排列 ps -e -o “%C : %p : %z : %a”|sort -nr 4 打印说cache里的URL grep -r -a jpg /data/cache/*

常用Linux Shell命令组合

序号 任务 命令组合 1 删除0字节文件 find . -type f -size 0 -exec rm -rf {} \;find . type f -size 0 -delete 2 查看进程,按内存从大到小排列 ps -e -o “%C : %p : %z : %a”|sort -k5 -nr 3 按cpu利用率从大到小排列 ps -e -o “%C : %p : %z : %a”|sort -nr 4 打印说cache里的URL grep -r -a jpg /data/cache/*

[Shell&Mac&Environment variables]自己常用的Mac(或者说Linux)Shell命令小结,含Mac使用zsh shell的环境变量的有关配置方法

今天在使用tomcat的配置的时候,我用的mac,要是用到一些命令去配置tomcat. 问题来了: 我每次要去启动tomcat服务特别麻烦,因为我要先进入tomcat所在的文件目录,或者不进入使用~/,但是因为我把tomcat放到了一个比较“深“的文件夹里,所以命令显得又丑又长. 问题解决方案: 1.使用环境变量(修改.bashrc的方法) a.先查看自己的Mac目前正在用的是什么shell echo $SHELL 返回结果类似如下图 这里我是zsh,,也许你是bash,不过没关系,配置环境变量

Linux Shell命令总结

使用find命令找到大于指定大小的文件: find /-type f -size +10G 在Linux下如何让文件夹下的文件让文件按大小排序? 方法一:# ls -lhSl 长格式显示,h human readable模式,大小单位为M,G等易读格式,S size按大小排序: 方法二:# du -h | sort -n 当然您也可以结合管道查看文件夹内最大的几个文件或最小的几个文件, 再加上管道符号和head或者tail命令即可du -h | sort -n|head du -h * | so

linux shell 命令学习(5) xxd- make a hexdump or do the reverse.

对于标准输入或者给定的文件,显示其16进制的内容.也可以反过来进行转换. ? 1 2 3 xxd -h[elp] xxd [options] [infile [outfile]] xxd -r[evert] [options] [infile [outfile]] 如果没有指定输入文件, 则采用标准输入. -b: 以2进制格式进行输出 ? 1 2 3 4 [[email protected] src]$ xxd -b train.ini 0000000: 01011011 01110100 01

[Python] 利用commands模块执行Linux shell命令

用Python写运维脚本时,经常需要执行linux shell的命令,Python中的commands模块专门用于调用Linux shell命令,并返回状态和结果,下面是commands模块的3个主要函数: 1. commands.getoutput('shell command') 执行shell命令,返回结果(string类型) >>> commands.getoutput('pwd') '/home/oracle' 2. commands.getstatus('file') 该函数

linux shell 命令

linux shell 命令 什么是Shell? Shell 是连接操作系统内核 与 用户 的接口. 终端是shell的表现形式. 什么是Shell编程? Shell 脚本语言加上linux 命令语句就构成了shell程序.优点在于批量处理.不用用户每次手动输入. bash是shell程序解释器的一种. 常用命令 pwd:print working directory,打印工作目录. cd:chang directory,改变工作目录. 可使用绝对命令或相对命令. ls:list,查看目录内容.

java执行linux shell命令,并拿到返回值

1 package com.suning.spc.util; 2 3 import java.io.IOException; 4 import java.io.InputStream; 5 import java.nio.charset.Charset; 6 7 import org.slf4j.Logger; 8 import org.slf4j.LoggerFactory; 9 10 import ch.ethz.ssh2.ChannelCondition; 11 import ch.eth

使用Runtime.exec()运行windwos dos或linux shell命令

使用Runtime.exec()运行windwos dos或linux shell命令,按实际情况具体测试 实例代码: package com.bookoo.test.command; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter