Daily Linux (1)-cat
effect
Connect files and print to standard output
grammar
Command Line
cat [-AbeEnstTuv] [--help] [--version] [infilename] [>filename]
-AbeEnstTuv:参数
-v (show-nonprinting):使用 ^ 和 M- 符号,除了 LFD 和 TAB 之外。
-E 或 --(show-ends) : 在每行结束处显示 $。
-T 或 --(show-tabs): 将 TAB 字符显示为 ^I。
-A, --show-all:等价于 -vET。
-e:等价于"-vE"选项;
-t:等价于"-vT"选项;
--help:查看帮助
--version:版本说明
infilename:读取文件名称,没有该参数默认从键盘输入,用于写文件
>filename:输出文件名称,没有该参数默认输出到终端显示
parameter
-
Test file test.txt
# 测试内容 test test1 test2 test3
-
-n (number): display each line number (including blank lines), starting from 1
$cat -n text.txt 1 test test1 2 test2 3 4 5 test3
-
-b (number-nonblank): same as -n, but does not contain blank lines
$cat -b text.txt 1 test test1 2 test2 3 test3
-
-s (squeeze-blank): merge continuous empty lines with one blank line
$cat -s text.txt test test1 test2 test3
-
-v (show-nonprinting): directly read the bytes of the file and convert the special characters
- Use '^' to input control characters except LFD and TAB
- The character with the highest bit of each byte being 1 replaces the highest bit of each byte with 'M-'
- Generally, this parameter can be used when the encoding format error occurs
举例 汉字:'学' UTF-8:16进制 E5 AD A6 2进制 11100101 10101101 10100110 高1位转换:M-1100101 M-0101101 M-0100110 后7位转换:M-eM--M-&
-
-E (show-ends): display $ at the end of each line
$cat -E text.txt test test1$ test2$ $ $ test3$
-
-T (show-tabs): display TAB characters as ^ I
$cat -T text.txt test^Itest1 test2 test3
-
-A: equivalent to -vET
-
-e: equivalent to -vE
-
-t: equivalent to -vT
Tips
- cat> filename is used to create a new file and edit the content, overwrite if the file name exists
- cat >> filename is used to create a new file and edit the content, append if the file name exists