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命令直接查看
3)借助>>命令,将test2.txt的文本内容追加到text.txt文本中
执行命令cat -b test2.txt >> test.txt
4)借助写入>指向标签将文本test.txt的内容清空,执行之后我们在使用cat命令查看下内容
cat/dev/null>test.txt
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
在 more 这个程序的运行过程中,你有几个按键可以按的:
- 空白键 (space) :代表向下翻一页;
- Enter :代表向下翻『一行』;
- /字串 :代表在这个显示的内容当中,向下搜寻『字串』这个关键字;
- :f :立刻显示出档名以及目前显示的行数;
- q :代表立刻离开 more ,不再显示该文件内容。
- b 或 [ctrl]-b :代表往回翻页,不过这动作只对文件有用,对管线无用。