Linux command - view file content command cat, more, less, head, tail
Command | Command Explanation |
---|---|
cat | Concatenate files and print on the standard output also you can connect multiple files to form new files |
more | View file content in split screen, you can only turn down the screen |
less | View file content in split screen, only flip up the screen |
head | View the content of the file header, the default front Ten lines of |
tail | View the content at the end of the file, the default last ten lines |
cat
command format: cat [OPTIONS] [file name......]
Common options:
-n Displays output lines preceded by line numbers, numbered sequentially from 1.
b- Omits line numbers from blank lines, when specified with the -n flag.
1. 1. View file content
cat fruits.txt
2. Display the line number to view the file content
cat -n fruits.txt
3. Label the non-blank lines in the output with line numbers
cat -b fruits.txt
First edit the fruits file with vim, add a few blank lines, and then let's take a look at what will happen
more and less
Command format:
more | less [options] [filename]
Common options:
- -number - only applicable to the more command, used to specify the number of lines per page when paging is displayed.
- +number - Specifies to start displaying from line number of the file.
- -c - clear the screen from the top and display the file contents.
- -N - For less command only, its effect is to add the output line number before each line.
1. View the content of the file
more fruits.txt
2. It will output and display according to the defined number of lines -3 will only display three lines
per page -5 will only display six lines per page
3. Display the file content from the specified sixth line
4. Add output lines before each line No
less -N fruits.txt
head and tail
Command: head | tail [options] [filename]
Common options:
1. If you use head command without any options, the head command displays the first ten lines.
head fruits.txt
2. Display the first 12 lines from standard input
head -n 12 fruits.txt
1. If you use tail command without any options, the tail command displays the last ten lines.
tail fruits.txt
2. Display the last 12 lines from standard input
tail -n 12 fruits.txt