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


相关文章
|
13天前
|
监控 安全 Ubuntu
Linux下如何安装配置Fail2ban防护工具
通过以上步骤,可以在Linux系统中成功安装和配置Fail2ban,从而有效保护服务器免受暴力破解等攻击。Fail2ban通过实时监控日志文件,自动更新防火墙规则,为系统安全提供了一层重要的保护。
69 36
|
22天前
|
网络协议 Unix Linux
深入解析:Linux网络配置工具ifconfig与ip命令的全面对比
虽然 `ifconfig`作为一个经典的网络配置工具,简单易用,但其功能已经不能满足现代网络配置的需求。相比之下,`ip`命令不仅功能全面,而且提供了一致且简洁的语法,适用于各种网络配置场景。因此,在实际使用中,推荐逐步过渡到 `ip`命令,以更好地适应现代网络管理需求。
34 11
|
25天前
|
Linux 网络性能优化 网络安全
Linux(openwrt)下iptables+tc工具实现网络流量限速控制(QoS)
通过以上步骤,您可以在Linux(OpenWrt)系统中使用iptables和tc工具实现网络流量限速控制(QoS)。这种方法灵活且功能强大,可以帮助管理员有效管理网络带宽,确保关键业务的网络性能。希望本文能够为您提供有价值的参考。
79 28
|
27天前
|
Rust Ubuntu Java
[Linux工具] Makefile
Makefile是Linux环境下用于自动化编译和链接程序的配置文件,常用于简化大型项目的编译流程。通过定义目标文件、依赖文件及生成命令,Makefile能高效管理编译任务。它不仅适用于C语言项目,还可扩展到其他编程语言和非编程任务中。
53 20
[Linux工具] Makefile
|
1月前
|
安全 网络协议 Linux
结合 `nc` 工具利用笑脸漏洞(Smile Bug)攻击 Metasploitable2 Linux
本文介绍如何使用 `nc`(Netcat)工具结合笑脸漏洞(Smiley Bug)攻击 Metasploitable2 Linux 靶机。首先概述了 `nc` 的基本功能和高级用法,包括建立连接、监听端口、文件传输等操作。接着详细描述了笑脸漏洞的原理及其在网络攻防中的应用,展示了通过 `nc` 发送恶意输入检测漏洞的方法。最后结合 Python 脚本实现更复杂的攻击场景,并强调了合法性和环境隔离的重要性。
51 13
|
2月前
|
运维 监控 Linux
推荐几个不错的 Linux 服务器管理工具
推荐几个不错的 Linux 服务器管理工具
177 6
|
3月前
|
Linux 网络安全 数据安全/隐私保护
Linux 超级强大的十六进制 dump 工具:XXD 命令,我教你应该如何使用!
在 Linux 系统中,xxd 命令是一个强大的十六进制 dump 工具,可以将文件或数据以十六进制和 ASCII 字符形式显示,帮助用户深入了解和分析数据。本文详细介绍了 xxd 命令的基本用法、高级功能及实际应用案例,包括查看文件内容、指定输出格式、写入文件、数据比较、数据提取、数据转换和数据加密解密等。通过掌握这些技巧,用户可以更高效地处理各种数据问题。
347 8
|
9月前
|
监控 网络协议 Java
Linux 网络编程从入门到进阶 学习指南
在上一篇文章中,我们探讨了 Linux 系统编程的诸多基础构件,包括文件操作、进程管理和线程同步等,接下来,我们将视野扩展到网络世界。在这个新篇章里,我们要让应用跳出单机限制,学会在网络上跨机器交流信息。
Linux 网络编程从入门到进阶 学习指南
|
9月前
|
存储 消息中间件 网络协议
Linux 系统编程从入门到进阶 学习指南
本文旨在为初学者提供一个清晰的 Linux 系统编程入门指南,带你步入 Linux 系统编程的世界,从基本概念到实用技能,一步步建立起您的知识体系。
Linux 系统编程从入门到进阶 学习指南
|
存储 Linux C语言
Linux:入门学习知识及常见指令
Linux:入门学习知识及常见指令