【Linux】指令入门之文本编辑工具cat和more(六)

简介: cat(英文全拼:concatenate)命令用于连接文件并打印到标准输出设备上。cat命令用于查看内容较少的纯文本文件。使用工具查看文本文件,让我们快速响应。


1 Linux命令Cat


1.1 什么是cat?

cat(英文全拼:concatenate)命令用于连接文件并打印到标准输出设备上。cat命令用于查看内容较少的纯文本文件。


「命令格式」

cat[][]


1.2 命令和说明

Linux(CentOS)操作系统下

在Linux操作系统下,我们可以查看下他的帮助文档。

Aion.otn$cat--helpUsage:cat[OPTION]...[FILE]...ConcatenateFILE(s),orstandardinput,tostandardoutput.-A,--show-allequivalentto-vET-b,--number-nonblanknumbernonemptyoutputlines,overrides-n-eequivalentto-vE-E,--show-endsdisplay$atendofeachline-n,--numbernumberalloutputlines-s,--squeeze-blanksuppressrepeatedemptyoutputlines-tequivalentto-vT-T,--show-tabsdisplayTABcharactersas^I-u(ignored)-v,--show-nonprintinguse^andM-notation,exceptforLFDandTAB--helpdisplaythishelpandexit--versionoutputversioninformationandexitWithnoFILE,orwhenFILEis-,readstandardinput.Examples:catf-gOutputf's contents, then standard input, then g'scontents.catCopystandardinputtostandardoutput.GNUcoreutilsonlinehelp:<http://www.gnu.org/software/coreutils/>Forcompletedocumentation,run:infocoreutils'cat invocation'


MacOS操作系统下

Aion.Liu$cat--helpcat:illegaloption---usage:cat[-belnstuv][file...]


「参数说明」

参数

介绍

-n 或 --number 由 1 开始对所有输出的行数编号
-b 或 --number-nonblank 和 -n 相似,只不过对于空白行不编号
-s 或 --squeeze-blank 当遇到有连续两行以上的空白行,就代换为一行的空白行
-v 或 --show-nonprinting 使用 ^ 和 M- 符号,除了 LFD 和 TAB 之外
-E 或 --show-ends 在每行结束处显示 $
-T 或 --show-tabs 将 TAB 字符显示为 ^I
-A, --show-all 等价于 -vET
-e 等价于"-vE"选项
-t 等价于"-vT"选项


1.3 实验测试

1)首先我们创建一个文本文件test.txt,并将自增序列的文本写入文本内

foriin$(seq110);doecho$i>>test.txt;done

2)使用cat命令直接查看

image.png


3)借助>>命令,将test2.txt的文本内容追加到text.txt文本中

image.png

执行命令cat -b test2.txt >> test.txt

image.png

4)借助写入>指向标签将文本test.txt的内容清空,执行之后我们在使用cat命令查看下内容

cat/dev/null>test.txt

image.png


2 Linux命令More

2.1 什么是more?

more命令从前向后分页显示文件内容,简单来说就是一页一页翻动。


「命令格式」

more[]


2.2 命令和说明


MacOS操作系统下

Linux下面我就不罗列了,其实都是差不多的命令。

Aion.Liu$more--helpSUMMARYOFLESSCOMMANDSCommandsmarkedwith*maybeprecededbyanumber,N.NotesinparenthesesindicatethebehaviorifNisgiven.AkeyprecededbyacaretindicatestheCtrlkey;thus^Kisctrl-K.hHDisplaythishelp.q:qQ:QZZExit.---------------------------------------------------------------------------MOVINGe^Ej^NCR*Forwardoneline(orNlines).y^Yk^K^P*Backwardoneline(orNlines).f^F^VSPACE*Forwardonewindow(orNlines).b^BESC-v*Backwardonewindow(orNlines).z*Forwardonewindow(andsetwindowtoN).w*Backwardonewindow(andsetwindowtoN).ESC-SPACE*Forwardonewindow,butdon't stop at end-of-file.d^D*Forwardonehalf-window(andsethalf-windowtoN).u^U*Backwardonehalf-window(andsethalf-windowtoN).ESC-)RightArrow*Rightonehalfscreenwidth(orNpositions).ESC-(LeftArrow*Leftonehalfscreenwidth(orNpositions).ESC-}^RightArrowRighttolastcolumndisplayed.ESC-{^LeftArrowLefttofirstcolumn.FForwardforever;like"tail -f".ESC-FLikeFbutstopwhensearchpatternisfound.r^R^LRepaintscreen.RRepaintscreen,discardingbufferedinput.---------------------------------------------------Default"window"isthescreenheight.Default"half-window"ishalfofthescreenheight.---------------------------------------------------------------------------SEARCHING/pattern*Searchforwardfor(N-th)matchingline.?pattern*Searchbackwardfor(N-th)matchingline.n*Repeatprevioussearch(forN-thoccurrence).N*Repeatprevioussearchinreversedirection.ESC-n*Repeatprevioussearch,spanningfiles.ESC-N*Repeatprevioussearch,reversedir.&spanningfiles.ESC-uUndo(toggle)searchhighlighting.ESC-UClearsearchhighlighting.&pattern*Displayonlymatchinglines.---------------------------------------------------Asearchpatternmaybeginwithoneormoreof:^Nor!SearchforNON-matchinglines.^Eor*Searchmultiplefiles(passthruENDOFFILE).^For@StartsearchatFIRSTfile(for/)orlastfile(for?).^KHighlightmatches,butdon't move (KEEP position).^RDon't use REGULAR EXPRESSIONS.^WWRAPsearchifnomatchfound.---------------------------------------------------------------------------JUMPINGg<ESC-<*Gotofirstlineinfile(orlineN).G>ESC->*Gotolastlineinfile(orlineN).p%*Gotobeginningoffile(orNpercentintofile).t*Gotothe(N-th)nexttag.T*Gotothe(N-th)previoustag.{([*Findclosebracket})].})]*Findopenbracket{([.ESC-^F<c1><c2>*Findclosebracket<c2>.ESC-^B<c1><c2>*Findopenbracket<c1>.---------------------------------------------------Each"find close bracket"commandgoesforwardtotheclosebracketmatchingthe(N-th)openbracketinthetopline.Each"find open bracket"commandgoesbackwardtotheopenbracketmatchingthe(N-th)closebracketinthebottomline.m<letter>Markthecurrenttoplinewith<letter>.M<letter>Markthecurrentbottomlinewith<letter>.'<letter>            Go to a previously marked position.''Gotothepreviousposition.^X^XSameas'.ESC-M<letter>Clearamark.---------------------------------------------------Amarkisanyupper-caseorlower-caseletter.Certainmarksarepredefined:^meansbeginningofthefile$meansendofthefile---------------------------------------------------------------------------CHANGINGFILES:e[file]Examineanewfile.^X^VSameas:e.:n*Examinethe(N-th)nextfilefromthecommandline.:p*Examinethe(N-th)previousfilefromthecommandline.:x*Examinethefirst(orN-th)filefromthecommandline.:dDeletethecurrentfilefromthecommandlinelist.=^G:fPrintcurrentfilename.---------------------------------------------------------------------------MISCELLANEOUSCOMMANDS-<flag>Toggleacommandlineoption[seeOPTIONSbelow].--<name>Toggleacommandlineoption,byname._<flag>Displaythesettingofacommandlineoption.__<name>Displaythesettingofanoption,byname.+cmdExecutethelesscmdeachtimeanewfileisexamined.!commandExecutetheshellcommandwith$SHELL.|XcommandPipefilebetweencurrentpos&markXtoshellcommand.sfileSaveinputtoafile.vEditthecurrentfilewith$VISUALor$EDITOR.VPrintversionnumberof"less".---------------------------------------------------------------------------OPTIONSMostoptionsmaybechangedeitheronthecommandline,orfromwithinlessbyusingthe-or--command.Optionsmaybegiveninoneoftwoforms:eitherasinglecharacterprecededbya-,oranameprecededby--.-?........--helpDisplayhelp(fromcommandline).-a........--search-skip-screenSearchskipscurrentscreen.-A........--SEARCH-SKIP-SCREENSearchstartsjustaftertargetline.-b[N]....--buffers=[N]Numberofbuffers.-B........--auto-buffersDon't automatically allocate buffers for pipes.-c........--clear-screenRepaintbyclearingratherthanscrolling.-d........--dumbDumbterminal.-Dxcolor.--color=xcolorSetscreencolors.-e-E....--quit-at-eof--QUIT-AT-EOFQuitatendoffile.-f........--forceForceopennon-regularfiles.-F........--quit-if-one-screenQuitifentirefilefitsonfirstscreen.-g........--hilite-searchHighlightonlylastmatchforsearches.-G........--HILITE-SEARCHDon't highlight any matches for searches.-h[N]....--max-back-scroll=[N]Backwardscrolllimit.-i........--ignore-caseIgnorecaseinsearchesthatdonotcontainuppercase.-I........--IGNORE-CASEIgnorecaseinallsearches.-j[N]....--jump-target=[N]Screenpositionoftargetlines.-J........--status-columnDisplayastatuscolumnatleftedgeofscreen.-k[file].--lesskey-file=[file]Usealesskeyfile.-K........--quit-on-intrExitlessinresponsetoctrl-C.-L........--no-lessopenIgnoretheLESSOPENenvironmentvariable.-m-M....--long-prompt--LONG-PROMPTSetpromptstyle.-n-N....--line-numbers--LINE-NUMBERSDon't use line numbers.-o[file].--log-file=[file]Copytologfile(standardinputonly).-O[file].--LOG-FILE=[file]Copytologfile(unconditionallyoverwrite).-p[pattern]--pattern=[pattern]Startatpattern(fromcommandline).-P[prompt]--prompt=[prompt]Definenewprompt.-q-Q....--quiet--QUIET--silent--SILENTQuiettheterminalbell.-r-R....--raw-control-chars--RAW-CONTROL-CHARSOutput"raw"controlcharacters.-s........--squeeze-blank-linesSqueezemultipleblanklines.-S........--chop-long-linesChop(truncate)longlinesratherthanwrapping.-t[tag]..--tag=[tag]Findatag.-T[tagsfile]--tag-file=[tagsfile]Useanalternatetagsfile.-u-U....--underline-special--UNDERLINE-SPECIALChangehandlingofbackspaces.-V........--versionDisplaytheversionnumberof"less".-w........--hilite-unreadHighlightfirstnewlineafterforward-screen.-W........--HILITE-UNREADHighlightfirstnewlineafteranyforwardmovement.-x[N[,...]]--tabs=[N[,...]]Settabstops.-X........--no-initDon't use termcap init/deinit strings.-y[N]....--max-forw-scroll=[N]Forwardscrolllimit.-z[N]....--window=[N]Setsizeofwindow.-" [c[c]]  .  --quotes=[c[c]]Setshellquotecharacters.-~........--tildeDon't display tildes after end of file.-# [N]  ....  --shift=[N]Sethorizontalscrollamount(0=onehalfscreenwidth).--follow-nameTheFcommandchangesfilesiftheinputfileisrenamed.--incsearchSearchfileaseachpatterncharacteristypedin.--line-num-width=NSetthewidthofthe-NlinenumberfieldtoNcharacters.--mouseEnablemouseinput.--no-keypadDon't send termcap keypad init/deinit strings.--no-histdupsRemoveduplicatesfromcommandhistory.--rscroll=CSetthecharacterusedtomarktruncatedlines.--save-marksRetainmarksacrossinvocationsofless.--status-col-width=NSetthewidthofthe-JstatuscolumntoNcharacters.--use-backslashSubsequentoptionsusebackslashasescapechar.--use-colorEnablescoloredtext.--wheel-lines=NEachclickofthemousewheelmovesNlines.---------------------------------------------------------------------------LINEEDITINGThesekeyscanbeusedtoedittextbeingenteredonthe"command line"atthebottomofthescreen.RightArrow.....................ESC-l...Movecursorrightonecharacter.LeftArrow......................ESC-h...Movecursorleftonecharacter.ctrl-RightArrowESC-RightArrowESC-w...Movecursorrightoneword.ctrl-LeftArrowESC-LeftArrowESC-b...Movecursorleftoneword.HOME...........................ESC-0...Movecursortostartofline.END............................ESC-$...Movecursortoendofline.BACKSPACE................................Deletechartoleftofcursor.DELETE.........................ESC-x...Deletecharundercursor.ctrl-BACKSPACEESC-BACKSPACE...........Deletewordtoleftofcursor.ctrl-DELETE....ESC-DELETE....ESC-X...Deletewordundercursor.ctrl-U.........ESC(MS-DOSonly).......Deleteentireline.UpArrow........................ESC-k...Retrievepreviouscommandline.DownArrow......................ESC-j...Retrievenextcommandline.TAB......................................Completefilename&cycle.SHIFT-TAB......................ESC-TABCompletefilename&reversecycle.ctrl-L...................................Completefilename,listall.

简单来说,more命令常用的就两个,一个是查看(more),另外一个是退出(q这俩命令


2.3 实验测试


利用我们上一个命令vim剩余的测试文件来测试下。例入,我想查看test.txt文件中从第3行开始往后的内容,我们可以使用下面的命令来查看。

more+3test.txt

image.png


在 more 这个程序的运行过程中,你有几个按键可以按的:


  • 空白键 (space)  :代表向下翻一页;
  • Enter              :代表向下翻『一行』;
  • /字串              :代表在这个显示的内容当中,向下搜寻『字串』这个关键字;
  • :f                   :立刻显示出档名以及目前显示的行数;
  • q                    :代表立刻离开 more ,不再显示该文件内容。
  • b 或 [ctrl]-b     :代表往回翻页,不过这动作只对文件有用,对管线无用。


相关文章
|
11天前
|
存储 Linux
Linux专栏08:Linux基本指令之压缩解压缩指令
Linux专栏08:Linux基本指令之压缩解压缩指令
28 4
|
11天前
|
Linux
Linux专栏09:Linux基本指令之时间日期指令及关机重启指令
Linux专栏09:Linux基本指令之时间日期指令及关机重启指令
22 2
|
6天前
|
安全 Unix Linux
【Linux】基本指令
【Linux】基本指令
|
6天前
|
存储 Linux 开发工具
【Linux】常见指令(下)
【Linux】常见指令(下)
|
6天前
|
存储 Linux 网络安全
【Linux】常见指令(上)
【Linux】常见指令(上)
|
Linux Ubuntu
Linux基础命令---文本编辑join
join       找出两个文件中相同的字段,根据相同字段合并两个文件,将合并结果显示到标准输出。       此命令的适用范围:RedHat、RHEL、Ubuntu、CentOS、SUSE、openSUSE、Fedora。
917 0
|
Linux Perl 安全
Linux基础命令---文本编辑sed
sed        sed是一种流编辑器,用来从输入流中读取内容并完成转换,输入流可以来自一个文件,也可以来自一个管道。        此命令的适用范围:RedHat、RHEL、Ubuntu、CentOS、SUSE、openSUSE、Fedora。
1030 0
|
Linux 开发工具 缓存
Linux基础命令---文本编辑ex
ex       ex会启动vim编辑器,它的执行效果和vim –E相同。从ex模式回到普通模式,可以在vim中输入:vim。       此命令的适用范围:RedHat、RHEL、Ubuntu、CentOS、SUSE、openSUSE、Fedora。
1119 0
|
Linux 开发工具 缓存
Linux基础命令---文本编辑
vim        vim是unix系统最通用的文本编辑器,它的功能可以说是非常强大了,它是vi的升级版。vim有三种工作模式:编辑模式、命令模式、末行模式,默认打开的时候进入命令模式。        此命令的适用范围:RedHat、RHEL、Ubuntu、CentOS、SUSE、openSUSE、Fedora。
1073 0
|
3天前
|
Linux
会玩这10个Linux命令,一定是个有趣的IT男!
会玩这10个Linux命令,一定是个有趣的IT男!