File display commands: cat, more, less, tail, touch

cat Command
The cat command concatenates files and prints to the standard output device. cat is often used to display the contents of a file, similar to the TYPE command below.

General format: cat [option] File
description: This command has two functions, one is to display the contents of the file, it reads the files specified by the parameter file in turn, and outputs their contents to the standard output; the other The second is to connect two or more files. For example, cat fl f2 > f3 will combine the contents of the file fl and a few, and then put them into the file f3 through the function of the output redirection character ">".
Common options:
-b, --number-noblank Number all non-blank output lines starting at 1.
-n, --number Number all output lines starting at 1.
-s, --squeeze-blank Combine multiple adjacent blank lines into a single blank line.
-help prints the command usage and exits with a return code indicating success.
Note: When the file is large, the text flashes (scrolls) quickly on the screen, and the user often cannot see what is displayed. Therefore, commands such as more are generally used for split-screen display. To control scrolling, press Ctrl+S to stop scrolling; press Ctrl+Q to resume scrolling. Press Ctrl+C (break) to terminate the execution of the command and return to the shell prompt.
Example: (let ml and m2 be two files in the current directory)
# cat m1 (display the contents of the file ml on the screen)
# cat m1 m2 (display the contents of the files ml and m2 at the same time)
# cat m1 m2 > file ( Merge the files ml and m2 into the file file)

more command
The more command displays the contents of the file, one screen at a time.

General format: more [options] File
description: This command displays one screen of text at a time, stops when the screen is full, and a prompt message appears at the bottom of the screen, giving the percentage of the file that has been displayed so far: --More-- (XX%) You can use the following different methods to answer the prompt:
①Press the Space key to display the next screen of text.
②Press the Enier key to display only the next line of text.
③ Press the slash character (l), then enter a pattern, you can find the next matching pattern in the text.
④Press H key to display the help screen with related help information.
⑤Press B key to display the content of the previous screen.
⑥Press the Q key to exit the rnore command.
Common options:
-num, this option specifies an integer, indicating how many lines are displayed on one screen.
-d, display the following more friendly prompts at the bottom of each screen:
--More--(XX%) [Press space to continue, 'q' to quit.]
And when there is an error when the user presses a key, display [ Press space to continue, 'q' to quit.] 'h', for instructions.] message instead of a simple alarm.
-c or -p, do not scroll, clear the screen before showing the next screen.
-s, compress consecutive blank lines in the file into one blank line for display.
+/, the pattern after this option (Pattem) specifies the string to search before each file is displayed.
+num, start at line number num.
The more command also uses some interactive commands based on the vi editor during the execution process, which will not be described in detail here.
Example:
① Display the content of the file file, but clear the screen before displaying, and display the percentage of completion at the bottom of the screen.
# more -dc file ②Display
the content of the file file, every 10 lines, and clear the screen before displaying.
# more -c -10 file

The less command
, like the more command, is also used to display the contents of a file in a split screen. But there is a difference between the two: the less command allows the user to browse files forward or backward, while the more command can only browse forward. When displaying files with the less command, use the PageUp key to page up and the PageDown key to page down. To exit the less program, the Q key should be pressed. less has several formats and many options, which are not detailed here.

The head command
command displays the first lines of the specified file on the screen.

General format: head [option] file
Description: The head command displays the first lines of the specified file on the screen, and the number of lines is determined by the parameter value. The default value for the number of displayed lines is 10.
Options:
-c, -bytes=SIZE Display the first SIZE bytes.
-n, -lines=NUMBER The value of NUMBER specifies how many lines to display before. The default is 10 lines.
-q, -quiet, --silent Do not display the title of the given file.
-v, -verbose Always display the title of the given file.
Example:
# head -5 file (display the first 5 lines of the file file)
# head -v file (display the contents of the file file, and give the title of the file name)
# head -q file (display the contents of the file file, but not list out the file name title)

tail command
The tail command displays the last few thousand lines of the specified file on the screen.

General format: tail [options] [file]...
Description: The tail command displays the last 10 lines of the specified file on the screen. If more than one file is given, a filename header is prepended to each file displayed. If no file is specified or the filename is "-", standard input is read.
Options:
-c, --bytes=N Output last N bytes.
-f Print additional data as the file grows.
-n, -lines=N Print the last N lines instead of the default 10 lines.
-q, -quiet, --silent Do not output headers containing the given filename.
-v, -verbose Always output a header containing the given filename.
Note: If there is a "+" sign before the N value representing the number of bytes or lines, the display starts from the Nth item at the beginning of the file, not the last N items of the file. The N value can be followed by a suffix: b means 512, k means 1024, and m means 1 048576 (1M).
Example:
# tail file (display the last 10 lines of the file file)
# tail +20 file (display the content of the file file, from the 20th line to the end of the file)
# tail -c 10 file (display the last 10 characters of the file file)

The touch command
can modify the timestamp of the specified file or create an empty file.

General format: touch [option] filename...
Description: touch command will modify the time stamp of the specified file, update the time stamp of the existing file to the current time of the system (default mode), and their data will be kept intact down. If the file does not already exist, create an empty new file.
Options:
-a Change the access time of the specified file only.
-c does not create any files.
-m Change only the modification time of the specified file.
-t STAMP Use the timestamp specified by STAMP instead of the current system time. The format of STAMP is [[CC]YY]MMDDhhmm[.ss], where CC represents the first two digits of the year, YY represents the last two digits of the year, MM represents the month, DD represents the day, hh represents the hour, and mm represents the minute. ss means seconds.
Example:
# touch ex2 Creates an empty file ex2 in the current directory.
Then, using the ls -l command, you can find that the size of the file ex2 is 0, indicating that it is an empty file.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326250003&siteId=291194637