Linux file filters and content editing

Learn about Linux file filters and content editing process, temporarily recording part, the subsequent supplement.

Plain text editor vi / vim

vim is developed from a vi text editor, but now found to have more than just a text editor, and also has code completion, function compilation is suitable for programming appears. vim has three modes, command mode (Command mode), the edit mode (Insert mode) and line mode (Lastline mode), there is separately its three way conversion.

As shown below, the use of vim command to enter command mode, there i, a, o are three ways to enter the edit mode, where i represents the cursor at the current cursor, when the current representative of a cursor to a cursor, line o represents replaced move the cursor being only understand these three.

i:insert

a:append

O:

Another is the command line mode, in addition to WQ, there wq, q, q like, specifically the following meanings!!:

(1) wq, write and quite, save and exit

(2) wq! ! Is mandatory sense, forced to save and exit behalf

(3) q to exit without saving

(4) q! Forced to exit without saving

(5) set nu display line numbers

(6) set nonu not show line numbers

There are some basic common vim command, recorded as follows, does not distinguish between modes.

Into the beginning of the line end of the line

In order to facilitate better understanding vim command, echo command written to the first portion of the text file test.txt, and line output.

Press enter $ current line, press 0 into the current line, the specific operation experience.

The beginning of the end of the file

Gg beginning of the file into the press, into the first digital gg + row number, into the end of the file by G, G is pressed into the FIG. 31 line.

search for

/ + Searches downward search, the search continues down by n, N OPPOSITE

? + Searches search up and continue the search up by n, reverse press N

replace

:% S / A / B / g, s behalf Alternatively, A is replaced element, B is an element after the replacement, g is meant the overall replacement, g into a digital number represents the replacement of only the representative of a column, wherein the swash lines may use other delimiters, such as may be implemented using a #.

After below using% s / chaolin / pengfei / g command result becomes as follows.

: M, Ns / A / B / g, the content of which represents the replacement M ~ N lines, similar with the above, but substitute content specified line.

 As shown below. 1 to 10 rows of modified yang YANG.

Delete or cut

删除或剪切单行按dd,删除多行按数字+dd。

如下图使用25gg先去到25行,然后使用25dd删除了25行后面的行。

撤销返回

按u就可以返回。

复制粘贴

单行复制按yy,p粘贴,多行复制数字+yy,p粘贴,粘贴时光标位置移动到要粘贴位置的前一行上。

如下图将光标移动到第30行按yy,然后将光标在第30行上按p,就自动粘贴到下一行上。

cat命令

cat命令就是查看文件内容命令,cat - concatenate files and print on the standard output,连接文件打印标准输出。如果想显示行号,使用参数-n。

more命令

more是可以分页查看文件内容命令,按回车往下走,按空格就是翻页走,不能回着看,按q退出。

less命令

less也是可以分页查看文件内容得命令,按回车往下走,按空格就是翻页走,可以回着看,按q退出。

head命令

输出文件的头部,默认显示10行,可以使用参数-n+数字来表示自定义行数。

tail命令

输出文件的尾部,也是默认显示10行,可以使用参数-n+数字来表示自定义行数,也可以使用参数-f显示文件尾部实时更新,即tail -f 文件名这个在MES中经常使用查看log实时变化。

如另外连接linux后,使用echo hello >>test.txt命令不断往test.txt文件尾部添加hello后,原来xshell窗口在使用tail -f test.txt命令后呈现的结果如下图。

不断append元素到文件结尾

tail -f test.txt后可以看到实时变化

tac命令

跟cat相反,倒过来显示文件内容,tac - concatenate and print files in reverse。

如下图文件头尾颠倒着显示。

rev命令

反转显示每行内容,rev - reverse lines of a file or files,如下所示。

总结

Linux命令很强大,继续学习吧。

 

参考博文:

(1)https://www.cnblogs.com/yangjig/p/6014198.html

(2)https://www.cnblogs.com/youngchaolin/p/10962089.html#_label5

 

Guess you like

Origin www.cnblogs.com/youngchaolin/p/11296784.html