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? 連接文件并在標(biāo)準(zhǔn)輸出上打印
可以用它來顯示文件內(nèi)容,創(chuàng)建文件,還可以用它來顯示控制字符。
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 exit
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: <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. 參數(shù) -n 或 -number 可以自動在每一行的顯示內(nèi)容前標(biāo)注上行號,如:
hann@HannYang:~$ cat -n cmd1.txt
1 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. 如果希望創(chuàng)建一個名為bigfile的文件,該文件包含上述三個文件的內(nèi)容,可以把上面命令的輸出重定向到新文件中,這就是cat連接文件的功能:
$ cat myfile1 myfile2 myfile3 > bigfile
6. 有一點要提醒的是,如果在敲入了cat以后就直接按回車,該命令會等你輸入字符。也是說幫助中說的“With no FILE, or when FILE is -, read standard input.”,沒有文件時則從標(biāo)準(zhǔn)輸入(默認設(shè)備就是鍵盤)中讀取內(nèi)容。如果你本來就是要輸入一些字符,那么它除了會在你輸入時在屏幕上顯示以外,還會再回顯這些內(nèi)容;最后按<Ctrl-d>結(jié)束輸入即可。
hann@HannYang:~$ cat
123456789
123456789
abcdefg
abcdefg
7. 如果希望創(chuàng)建一個新文件,并向其中輸入一些內(nèi)容,只需使用cat命令把標(biāo)準(zhǔn)輸出重定向到該文件中,這時cat命令的輸入是標(biāo)準(zhǔn)輸入—鍵盤,你輸入一些文字,輸入完畢后按<Ctrl-d>結(jié)束輸入。這就是一個非常簡單的文字編輯器!
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
已復(fù)制 ? ? ? ? 1 個文件。C:\Users\boyso>type myfile
123456
abcdef
Dos系統(tǒng)是用<Ctrl-z>退出輸出的。
8.? 連接多個文件時,還能用鍵盤輸入一些內(nèi)容。即是前面第6點中提到的“or when FILE is -” ,也就當(dāng)文件參數(shù)有“-”減號時,就從鍵盤輸入內(nèi)容直到按<Ctrl-d>結(jié)束輸入。
例如以下操作,連接文件aa,bb成cc,并且兩個文件間用"==========="隔開:文章來源:http://www.zghlxwxcb.cn/news/detail-644606.html
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.zghlxwxcb.cn/news/detail-644606.html
到了這里,關(guān)于Linux 終端命令之文件瀏覽(1) cat的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!