【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     :代表往回翻页,不过这动作只对文件有用,对管线无用。


相关文章
|
3月前
|
Linux 数据安全/隐私保护
Linux文件权限调整:chmod指令解析
在日常使用或系统管理中,对 `chmod`的熟练应用是提高工作效率和维持系统稳定性的关键。掌握如何给予或限制权限是每个Linux使用者都应该具备的技能。
248 17
|
3月前
|
移动开发 Linux Windows
Linux常用基本指令
对Linux中常用命令,包括文件创建与销毁,压缩与打包,查看搜索文件的方式等指令的介绍
207 1
|
4月前
|
存储 人工智能 Unix
Linux常见指令汇总
最常见的就是 ll (为ls -l的省略)
167 0
|
8月前
|
Unix Linux Shell
Linux新手入门手册
在Linux或类Unix系统中,掌握一系列基础命令和快捷键是提升工作效率的关键。这些工具和技巧不仅能帮助用户更高效地管理系统,还能在日常使用中带来极大的便利。以下是对这些基础操作与快捷键的详细解析大全。
142 9
|
9月前
|
消息中间件 Linux
Linux:进程间通信(共享内存详细讲解以及小项目使用和相关指令、消息队列、信号量)
通过上述讲解和代码示例,您可以理解和实现Linux系统中的进程间通信机制,包括共享内存、消息队列和信号量。这些机制在实际开发中非常重要,能够提高系统的并发处理能力和数据通信效率。希望本文能为您的学习和开发提供实用的指导和帮助。
630 20
|
Linux
【Linux开发习作】more命令的编写(1)
作者:gnuhpc 出处:http://www.cnblogs.com/gnuhpc/ /* * ===================================================================================== * * Filename: more01.
921 0
|
Linux
【Linux开发习作】more命令的编写(2)
作者:gnuhpc  出处:http://www.cnblogs.com/gnuhpc/ 可以根据终端大小自动调整输出,并且修正了上一个版本的一些小bug,更加贴近现在Linux用的More。
902 0
|
24天前
|
Linux 应用服务中间件 Shell
二、Linux文本处理与文件操作核心命令
熟悉了Linux的基本“行走”后,就该拿起真正的“工具”干活了。用grep这个“放大镜”在文件里搜索内容,用find这个“探测器”在系统中寻找文件,再用tar把东西打包带走。最关键的是要学会使用管道符|,它像一条流水线,能把这些命令串联起来,让简单工具组合出强大的功能,比如 ps -ef | grep 'nginx' 就能快速找出nginx进程。
260 1
二、Linux文本处理与文件操作核心命令
下一篇
oss教程