Home >Operation and Maintenance >Linux Operation and Maintenance >What is the command to view files in linux
Linux command to view files: 1. "cat", display the file content from the first line; 2. "tac", display from the last line; 3. "nl"; 4. "more" , display the file content page by page; 5. "less"; 6. "head", only look at the first few lines; 7. "tail", only look at the last few lines.
#The operating environment of this tutorial: Red Hat Enterprise Linux 6.1 system, Dell G3 computer.
Linux commands to view the contents of log files are
You can use man [command] to view each command Usage documentation, such as: man cp.
Command function:
Display the file content starting from the first line
Command syntax:
cat [-AbEnTv] 一次显示整个文件。$ cat filename 2.从键盘创建一个文件。$ cat > filename 只能创建新文件,不能编辑已有文件. 3.将几个文件合并为一个文件: $cat file1 file2 > file
Options | Parameters |
---|---|
-A | is equivalent to the integration option of -vET, which can list some special characters instead of just blanks; |
-b | lists lines Number, only line numbers are displayed for non-blank lines, blank lines are not marked with line numbers! |
-E | Display the ending line break byte$; |
-n | column Print line numbers, and blank lines will also have line numbers, which is different from the -b option; |
-T | displays the [tab] key as ^I ; |
-v | List some invisible special characters |
Related recommendations:《Linux Video Tutorial》
Check the contents of /etc/issue:
cat filename #一次显示整个文件. cat > filename #从键盘创建一个文件。 #只能创建新文件,不能编辑已有文件. cat file1 file2 > file #将几个文件合并为一个文件
Command function:
tac is just the opposite of the cat command. The file content is displayed from the last line. It can be seen that tac is cat written backwards!
Command syntax:
tac [选项]
Example
[root@www ~]# tac /etc/issue Kernel \r on an \m CentOS release 6.4 (Final)
Command function:
Display line number; nl commandRead the file parameter (standard input by default), calculate the line number in the input, and write the calculated line number to the standard output . In the output, the nl command evaluates the lines to the left based on the flags you specify on the command line. Input text must be written in a logical page. Each logical page has header, body and footer sections (can have empty sections). Unless the -p
option is used, the nl command resets the line number at the beginning of each logical page. The line calculation flag can be set individually for header, body, and footer sections (for example, header and footer lines can be counted but text lines cannot). The default result is a little different from cat -n
. nl can do more display designs for line numbers, including the number of digits and whether to automatically complete 0s, etc.
Command syntax:
nl [-bnw] 文件
Options and parameters:
Example: Use nl to list the contents of /etc/issue
[root@www ~]# nl /etc/issue 1 CentOS release 6.4 (Final) 2 Kernel \r on an \m
Command function:
Flip page by page,more command is a text filter based on the vi editor. It displays the content of the text file page by page in full screen mode and supports keywords in vi Positioning operations. There are several shortcut keys built into the more list, the commonly used ones are H (get help information), Enter (scroll down one line), Space (scroll down one screen), Q (exit command).
Command syntax:
more(语法)(参数)
Options | Description |
---|---|
- |
Specify the number of lines displayed on each screen; |
-d | Display "[press space to continue,'q' to quit.]" and "[Press 'h' for instructions]"; |
-c | No scrolling operation is performed. Refresh this screen every time; |
-s | Compress multiple blank lines into one line for display; |
-u | Underlines are prohibited; |
|
Display starts from the line with the specified number. |
实例
[root@www ~]# more /etc/man.config # # Generated automatically from man.conf.in by the # configure script. # # man.conf from man-1.6d ....(中间省略).... --More--(28%) <== 重点在这一行喔!你的光标也会在这里等待你的命令
在 more 这个程序的运行过程中,你有几个按键可以按的:
命令功能:
less命令允许用户向前或向后浏览文件,而more命令只能向前浏览。用less命令显示文件时,用PageUp键向上翻页,用PageDown键向下翻页。要退出less程序,应按Q键。
命令语法:
less(选项)(参数)
选项
选项 | 说明 | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
-e | 文件内容显示完毕后,自动退出; | ||||||||||||||||||||||||||||||||||
-f | 强制显示文件; | ||||||||||||||||||||||||||||||||||
-g | 不加亮显示搜索到的所有关键词,仅显示当前显示的关键字,以提高显示速度; | ||||||||||||||||||||||||||||||||||
-l | 搜索时忽略大小写的差异; | ||||||||||||||||||||||||||||||||||
-N | 每一行行首显示行号; | ||||||||||||||||||||||||||||||||||
-s | 将连续多个空行压缩成一行显示; | ||||||||||||||||||||||||||||||||||
-S | 在单行显示较长的内容,而不换行显示; | ||||||||||||||||||||||||||||||||||
-x<数字> | 将TAB字符显示为指定个数的空格字符。 |
选项 | 说明 |
---|---|
-n<数字> | 指定显示头部内容的行数; |
-c<字符数> | 指定显示头部内容的字符数; |
-v | 总是显示文件名的头信息; |
-q | 不显示文件名的头信息。 |
选项 | 说明 |
---|---|
--retry | 即是在tail命令启动时,文件不可访问或者文件稍后变得不可访问,都始终尝试打开文件。使用此选项时需要与选项“——follow=name”连用; |
-c |
输出文件尾部的N(N为整数)个字节内容; |
-f |
显示文件最新追加的内容。“name”表示以文件名的方式监视文件的变化。“-f”与“-fdescriptor”等效; |
-F | 与选项“-follow=name”和“--retry"连用时功能相同; |
-n |
输出文件的尾部N(N位数字)行内容。 |
--pid=<进程号> | 与“-f”选项连用,当指定的进程号的进程终止后,自动退出tail命令; |
-q或——quiet或——silent | 当有多个文件参数时,不输出各个文件名; |
-s<秒数>或——sleep-interal=<秒数> | 与“-f”选项连用,指定监视文件变化时间隔的秒数; |
-v或——verbose | 当有多个文件参数时,总是输出各个文件名; |
--help | 显示指令的帮助信息; |
--version | 显示指令的版本信息。 |
[root@www ~]# tail /etc/man.config # 默认的情况中,显示最后的十行!若要显示最后的 20 行,就得要这样: [root@www ~]# tail -n 20 /etc/man.config
更多编程相关知识,请访问:编程教学!!
The above is the detailed content of What is the command to view files in linux. For more information, please follow other related articles on the PHP Chinese website!