[Go] Show file command: Cat, more, less, tail, touch

Source: Internet
Author: User
Tags touch command

Cat command
The cat command connects the files and prints them to the standard output device. Cat is often used to display the contents of a file, similar to the following type command.

General format: Cat [Options] File
Note: This command has two functions, one is to display the contents of the file, it reads the file specified by the parameter files, the contents of the output to the standard output, and the other is to connect two or more files, such as Cat fl F2 > F3 will combine the file FL and a few of the content together, They are then placed in the file F3 by the output redirect ">".
Common options:
-b,--number-noblank all non-empty output lines starting from 1.
-n,--number the number of all output lines starting from 1.
-s,--squeeze-blank merges multiple adjacent empty rows into a blank row.
-Helpprints the command usage and exits with its return code indicating success.
Note: When the file is large, the text flashes quickly on the screen (scrolling), and the user is often not aware of what is displayed. Therefore, generally with more commands split screen display. In order to control the scrolling screen, you can press the Ctrl+s key, stop the scrolling screen, press the CTRL+Q key to restore the scroll screen. Press the CTRL + C (break) key to terminate the execution of the command and return to the shell prompt state.
Example: (set ml and M2 are two files in the current directory)
# Cat M1 (displays the contents of the file ml on the screen)
# Cat M1 m2 (simultaneous display of files ml and m2 content)
# Cat M1 m2 > file (merging Files ml and m2 into file files)

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

General format: More [options] file
Description: The command displays one screen of text at a time, stops after a full screen, and at the bottom of the screen a prompt message appears, giving the percentage of the file that has been displayed:--more--(XX%) can answer the prompts in the following different ways:
① 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) and enter a pattern to find the next matching pattern in the text.
④ Press the H key to display the help screen with relevant help information.
⑤ Press the B key to display the previous screen content.
⑥ Press the Q key to exit the Rnore command.
Common options:
-num, which specifies an integer that indicates how many rows are displayed on a single screen.
-D, which displays the following more friendly tips at the bottom of each screen:
--more--(XX%) [Press space to continue, ' Q ' to quit.]
and when the user presses the key with an error, the [press ' H ', for instructions] is displayed. Information, rather than a simple alarm.
-C or-p, without scrolling, to clear the screen before displaying the next screen.
-S, which compresses contiguous blank lines in the file into a blank line display.
+/, the mode after which the option (Pattem) specifies the string to search for before each file is displayed.
+num, starting with the line number Num. The
More command also uses interactive commands that are based on the vi editor during execution, which is not detailed here.
Example:
① Displays the contents of file files, but the screen is cleared before being displayed, and the percentage of cores is displayed at the bottom of the screen.
# MORE-DC File
② Displays the contents of file files, once per 10 lines, and clear the screen before displaying.
# more-c -10 file

Less command
As with the more command, the less command is also used to display the contents of a file on a split screen. But there is a difference: the less command allows the user to navigate forward or backward through the file, while the more command can only be browsed forward. When displaying a file with the less command, use the PageUp key to page up and PAGE down with the PageDown key. To exit the less program, you should press the Q key. Less has several formats and many options, which are not detailed here.

Head command
The command displays several lines at the beginning of the specified file on the screen.

General format: Head [options] File
Description: The head command displays several lines at the beginning of the specified file on the screen, and the number of rows is determined by the parameter values. The default value for displaying the number of rows is 10.
Options:
-c,-bytes=size Displays the preceding SIZE bytes.
The value of-n,-lines=number number specifies how many lines are displayed earlier. The default is 10 rows.
-q,-quiet,--silent does not display the title of the given file.
-v,-verbose always displays the title of the given file.
Example:
# head-5 file (shows the first 5 lines of the files)
# head-v file (displays the contents of the files, and gives the filename title)
# head-q file (displays the contents of the files, but does not list the filename title)

Tail command
The tail command displays the end of the specified file on the screen as if it were thousands of lines.

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 that is displayed. If no file is specified or the file name is "-", the standard input is read.
Options:
-c,--bytes=n the last N bytes of output.
-F Output additional data when the file grows.
The-n,-lines=n outputs the last n rows instead of the default 10 rows.
-q,-quiet,--silent does not output a caption that contains the given file name.
-v,-verbose always outputs the caption that contains the given file name.
Note: If there is a "+" sign before the N value that represents a byte or number of rows, the nth item starting at the beginning of the file is displayed instead of the last n of the file. The n value can be followed by a suffix: b means that 512,k means that 1024,m represents 1 048576 (1M).
Example:
# tail file (shows the last 10 lines of the files)
# tail +20 file (displays the contents of the files, from line 20th to the end of the file)
# tail-c file (displays the last 10 characters of the filename)

Touch command
You can modify the time label of the specified file or create an empty file.

General format: Touch [options] File name ...
Note: The touch command will modify the time label of the specified file, updating the time label of the existing file to the current time of the system (the default), and their data will remain intact. If the file does not already exist, an empty new file is created.
Options:
-A changes the access time of the specified file only.
-C does not create any files.
-M only changes the modified time of the specified file.
-T STAMP uses the time label specified by STAMP instead of the current time of the system. The format of the stamp is [[cc]yy]mmddhhmm[. SS], where CC represents the first two bits of the year, YY represents the last two bits of the year, MM for the month,DD for the date, HH for the hour, mm for minutes, and SS for seconds.
Example:
# Touch EX2 Create an empty file Ex2 in the current directory.
Then, using the Ls-l command, you can find that the file Ex2 is 0 in size, indicating that it is an empty file.

Original address: http://www.linuxde.net/2011/08/551.html

Use more of the cat, head.

Touch more to create a new file

[Go] Show file command: Cat, more, less, tail, touch

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.