You can get the advice from IT HELP DESK

SYSTEM[LINUX] Command to check the contents of Linux file

Robert
16 Jan 2019
<head>Disk Management, Server Monitoring, System management, server monitoring, server management, system management, system monitoring, </head>

[LINUX] Command to check the contents of Linux file 


Hello ~! 

This time I will explain the command to check the contents of Linux file ~


1. cat

#cat [option] [filename1] [filename2] ...


The cat command is the most basic command to output a file. You can use it as well as copy and print files. You can also output multiple files at once.

Note that if the file is a text file, the contents will be output normally. However, if it is a binary file, the output will not be recognized.

The major options are:

 

Option  Explanation  
-bBlank without a line number.  
-nIt gives line numbers including spaces.  
-EDisplays the newline character as $.
-TTabs are marked with ^ |.
-vDisplays nonprinting characters except newline and tab.
-ADisplays all nonprinting characters including newlines and tabs.
(Option to overlap E, T, v)
-sIt treats consecutive spaces as a single space.



  1.1 Creating a file

#cat > [filename]

Creates file contents after command input. Save as [Ctrl + d].



  1.2 File output

# cat [filename]


If you want to output multiple files at once, use cat [file name1] [file name2] ... [file name n] . Multiple files are output without any distinction.


1.3 Copying Files

#cat [filename1] > [filename2]

You can use the same method as copying the file by transferring the same contents, or you can use it as a method to merge several files.

Below is an example of merging multiple files.


Additionally, store the results of the command to a file you how to. You can use the pipe symbol (|) to create a file. Alternatively, you can use a  ">" symbol to make it simpler.


Example:

ls -al | cat file1

ls -al > file1

Please use the example below to save the required results ~



2. more 

#more [option] [filename]

more, unlike cat, you can view the contents of a file by page break. It is mainly used for checking longer contents. Used in conjunction with pipe (|) when the output is broken by reading long files. 

You can open and edit the file in vi directly from that page,  which verifies the contents of a specific file, and you can check the contents of the text file one page at a time.  

The options when using the more command are as follows.

OptionExplanation
-pWhen you move the page, it prints without refreshing the screen without printing it down.
-numberDetermines how many lines of a page are set.
-sIf there are multiple lines of space, it will be shortened to a single space.
-dAt the end of a page, [press space to continue, q to quit] appears next to the -more-



  2.1 Commands available during execution


The more command shows the contents of the file on one page, as shown in the above picture. 

There are several commands available at this time.

CommandExplanation
spaceGo to next page
enterMove in line
Number + zMove to next by number line
q / Qmore command termination
fGo to next page
bGo to the previous page
=Show current line number
vRun as vi editor
/ StringSearch for a string. You can use n to find the strings in turn.


more can be used with the cat command. When using cat command, % of the current page is not displayed as shown in the picture below.

#cat [filename] | more



3. less 

#less [option] [filename]

more can be read while moving from top to bottom, but less can be moved from top to bottom and from top to bottom. You can also check the contents of a file once it has passed. Also, the speed is very fast because only the contents shown at a time are read out. When reading a large file, you can check the file at a high speed.


  3.1 Commands Available During Execution

CommandExplanation
space / fGo to next page
bGo back to previous screen
enterMove one row at a time
Number + nMove as many pages as you like
qLess command termination
/ ExpressionSearch for a string that matches an expression
• ExpressionSearch for previously found strings
GMove to the end of the text file


As mentioned above, less does not read all the files but prints only the output part, so it does not eat up the memory much and is much faster. You can also check previous documents, which is a common command for many people!


๐Ÿ””  TIP. Let me summarize the previous contents briefly! ๐Ÿ”” 

๐Ÿ’ก  cat: To print a short document simply cat

๐Ÿ’ก  more: If you want to see long output results

๐Ÿ’ก  less: If you want to check a long document a bit more precisely,