Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

1, cat command:

Function: 1) Display the entire file. Example: $cat fileName 2) Connect file strings to basic output, such as merging several files into a single file or output to the screen. Example: $cat file1 file2 > file Description: After connecting the file string to the basic output (screen or add > fileName to another file)

  1. Cat parameter description:

-n or -number Indicates the number of all output lines starting from 1

-b or -number-nonblank is similar to -n except that it is not numbered for blank lines

-s or -squeeze-blank when there are more than two consecutive blank lines, substitute for one blank line

V or — show — nonprinting

2, more command:

View the log as a percentage.

Press the space bar to scroll down or Ctrl+F,

Ctrl+ B to scroll up, q to exit the more command

More +/ character filename the search character begins on the second line;

3, less command:

It has the same function as More, but less supports scrolling through files before and after.

-m Displays the percentage of more commands

-n Displays the line number of each line

Space key to scroll a page/Enter key to scroll a line

Q out less

4, head command:

Run the head command to view the beginning of a text file.

The following is an example:

TXT displays the first ten lines of the example. TXT file.

Head-n 20 example. TXT Displays the first 20 lines of the example. TXT file.

Head a:

-n Specifies how many lines of text you want to display.

-n number This parameter option must be a decimal integer, which will determine the position in the file, in behavior units.

-c number This parameter option must be a decimal integer that determines the position in the file, in bytes.

5, tail command:

Run the tail command to display the last lines of a text file.

The following is an example:

Tail example. TXT Displays the last ten lines of the example. TXT file.

Tail -n 20 example. TXT Displays the last 20 lines of the example. TXT file.

Tail -f example. TXT Displays the last ten lines of the example. TXT file and automatically displays the new file content after it is added.

Tail -n 50 -f example. TXT Displays the last 50 lines of the example. TXT file and automatically displays the new file content after it is added.

Note: This last command is very useful, especially when monitoring log files, to keep the new log information on the screen.

conclusion

In fact, Linux beginners commonly used commands are CD, ls, rm< very dangerous >, chmod, chown, mkdir, free and so on

This article will start with a few more advanced instructions.