File filtering and content editing processing commands

cat: Merge files or view file content (merge up and down)

01. No parameter: view the content of the file cat file.txt

02. No parameters: merge multiple files cat file1.txt file2.txt >newfile.txt

03. No parameter: append content to the end of the file cat >>file.txt<<EOF

04. No parameter: clear the content of the file cat /dev/null>file.txt

05. -n: start from 1 to display the line number of the output content cat -n file.txt

06. -b: Ignore the blank and display the line number cat -b file.txt

07. -A: Equivalent to vET, display the identifier cat -A file.txt

08, ctrl+backspace key: delete

tac: display the contents of the file in reverse

01. No parameter: output the content of each line in reverse order tac file.txt

more: Distribution display file content (understand)

01. No parameters: display the file content page by page more /etc/services

02. +num: display more +88 /etc/services from the line number num

less: Display file content in pages (emphasis, increased version of more)

01. No parameters: page display file content less /etc/services

02. -N: Display the line number of each line less -N /etc/services

03. On the arrow keys: scroll up one line

04. Down the direction key: scroll down one line

05. page up: scroll up one page

06. page down: scroll down one page

07. g: move to the first line

08. G: move to the last line

09. ? String: search upwards for "string"

10. /string: search down for "string"

11. n: Find the next matching text backwards

12. N: Find the next matching text forward

head: Display the header of the file content

01. No parameters: display the first 10 lines of the file by default head /etc/passwd

02, -n: specify the number of lines displayed head -n 5 /etc/passwd

tail: display the tail of the file content

01. No parameter: display the last 10 lines of tail /etc/passwd

02. -n: Display the specified number of lines tail -n 5 /etc/passwd

03. -f: Real-time output of data appended after file changes tail -f /application/nginx/logs/access.log

tailf: Track log files (tailf is almost equivalent to tail -f, the difference is that tailf will not access disk files and will not change the access time of files)

01. No parameters: the last 10 lines of the default output log file tailf /application/nginx/logs/access.log

02. -n: Display the specified number of lines tailf -n 5 /application/nginx/logs/access.log

cut: extract a piece of text from the text and output

01, -b: split in units of characters cut -b 3-5,10 oldboy.txt

02. -n: Cancel splitting multi-byte characters, use cut -nb 2-10 oldboy.txt in conjunction with option -b

03. -c: split in units of characters cut -c 2-10 oldboy.txt

04. -d: Custom delimiter, the default is tab as delimiter cut -d : /etc/passwd

05. -f: Used in conjunction with option -d to specify which area to display cut -d: -f 1 /etc/passwd

06. N: Nth byte, character or field

07. N-: From the Nth byte, character or field to the end of the line

08. NM: from the Nth to the Mth (including More) bytes, characters or fields

09. -M: From the 1st to the Mth (including More) bytes, characters or fields

split: split the file

01. -l: Specify the maximum number of lines in the split file split -l 10 inittab new_

paste: Merge files (merge left and right)

01. No parameter: default merge file paste test1 test2

02. -d: Specify the separator, the default is tab paste -d: test1 test2

03. -s: each file occupies one line paste -s test1

04. -sd: Make the first line = the second line (special usage, the order of parameters cannot be changed) paste -sd '=\n' test.txt

Make line 1 = line 2: xarge -n 2 <test.txt|sed 's# #=#g'

sort: text sorting

01. No parameter: sort oldboy.txt in ascending order of ASCII code

02. -b: Ignore the space character of the switch sort -b oldboy.txt

03. -u: remove duplicate lines sort -u oldboy.txt

04. -n: Sort according to the size of the value sort -n oldboy.txt

05. -t: specify the separator sort -t "." oldboy.txt

06. -r: Arrange in reverse order

07. -k: specify interval sort sort -t "." -k 1.10,1.11 -k 4,4n sort.txt

join: Merge by the same fields of two files

01. No parameters: Merge sorted files sort a.txt>a.txtn sort b.txt>b.txtn join a.txtn b.txtn

02. -a: Output unmatched lines

03, -i: Ignore case when comparing fields

04, -1: Merge based on the specified field of the first file

05, -2: Merge based on the specified fields of the second file

06、:

uniq: remove duplicate rows

01. No parameter: remove duplicate lines uniq oldboy.txt

02. -c: Remove duplicate lines and count the number of occurrences of each line sort -n oldboy.txt|uniq -c

03, -d: only display duplicate lines

04. -u: Only display unique lines

wc: Count the number of lines, words or bytes of a file

01. No parameters: number of lines, number of words, number of bytes wc /etc/inittab

02. -c: Statistical bytes wc -c /etc/inittab

03. -w: Count the number of words wc -w /etc/inittab

04. -l: Count the number of lines wc -l /etc/inittab

05. -L: print the length of the longest line wc -L /etc/inittab

06. -m: Count the number of characters wc -m /etc/inittab

iconv: Convert the encoding format of the file

01. No parameters:

02. -f: convert from encoding A to iconv -f gb2312 -t utf-8 GB2312.txt

03. -t: convert to code A

04. -l: Display the encoding supported by the system

05. -o: input the output to the specified file

dos2unix: Convert dos format files to UNIX format

01. No parameter: dos2unix oldboy.win.sh

diff: Compare the differences between two files

01. No parameter: output diff test1 test2 in default format

02. -y: Display the similarities and differences of files in a parallel manner diff -y test1 test2

03. -W: When using -y, specify the displayed width diff -y -W 30 test1 test2

04. -c: Use context format to output diff -c test1 test2

05. -u: Use a unified format to output diff -u test1 test2

vimdiff: visual comparison tool

01. No parameters: call vim to open the file, and the color is vimdiff a.txt b.txt

rev: Reverse the contents of the output file

01. No parameter: output the contents of the file in reverse, at least one space echo{1…10}}rev

tr: replace and delete characters

01. No parameters: replace the previous characters with the following characters, one-to-one correspondence tr 'abc' 'xyz' <oldboy.txt

02, -d: delete each character specified tr -d 'oldboy'

03. -s: Keep the first character of consecutive characters, delete other characters echo 'ooollldddoyyy'|tr -s oldboy

04. -c: use the complement of the first string (setl), reverse tr -c '0-9' '*'<oldboy.txt

od: display files in different bases

01. No parameters:

02. -A: specify base o octal (default) d decimal x hexadecimal n do not print the displacement value

03, -t: specify the data format a named character cASCII character d signed decimal f floating point number o octal (default) u unsigned decimal x hexadecimal

04、file /bin/ls od -Ax -tcx /bin/ls|less

tee: multiple redirects

01. No parameter: Write the content to the file ls|tee ls.txt while standard output

02. -a: Append content to the file ls|tee -a ls.txt

vi/vim: plain text editor

normal mode

01. gg: the first line of the file

02. G: the last line of the file

03, 0: move the cursor to the current line switch

04. $: Move the cursor to the end of the current line

05. Number n: Move the cursor down n lines

06. /XXX: search down for the XXX string

07. ?XXX: search upward for XXX string

08, n: Repeat the previous search action upwards

09, N: Repeat the previous search action downward

10. %s#A#Bg: replace all A with B

11. yy: copy the current line

12. nyy: copy n lines down from the cursor position

13. p: Paste to the next line of the cursor

14. P: Paste to the line above the cursor

15. dd: delete the line where the cursor is located

16. ndd: delete n lines from the position containing the cursor down

17. u: restore the previous execution operation, undo

18..: Repeat the previous action

19. x: delete characters backward

20. X: delete characters forward

21. d1G: delete the current line to the first line

22. dG: delete the current line to the last line

23. d0: delete the current cursor text to the beginning of the line

24. d$: delete the current cursor text to the end of the line

edit mode

01, i: Insert text at the current cursor position

02. a: insert text at the next character where the cursor is

03. I: Insert text at the beginning of the current line

04. A: Insert text at the end of the current line

05. O: insert a new row in the previous row of the current row

06. o: insert a new line in the next line of the current line

07. Esc: exit edit mode

block mode

01. Ctrl+v: Enter visualization mode

02, n1, n2s/#//gc: cancel multi-line comments

03. del: delete the selected content at one time

04, r: Replace the selected content at one time

command mode

01. wq: save and exit

02. wq!: force save and exit

03. q!: Force quit without saving

04. n1, n2 w filename: Save the content from line n1 to line n2 as filename

05. n1,n2 co n3: Copy the content from line n1 to line n2 to the position of n3

06. n1,n2 m n3: Cut the content from line n1 to line n2 to the position of n3

07. !command: Temporarily leave vi to execute command display results in command line mode, such as !ls/etc

08. set nu: display line number

09. set nonu: cancel the line number

10. vs filename: vertically split the screen to display the content of the current file and filename

11. sp filename: display the content of the current file and filename in horizontal split screen

Guess you like

Origin blog.csdn.net/Chen118222/article/details/131228617
Recommended