


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
- cat displays the file contents starting from the first line
- tac displays the contents starting from the last line, It can be seen that tac is cat written backwards
- nl When displayed, the line number is output along the way!
- more Displays the file content page by page
- less is similar to more, but better than more, it can turn pages forward!
- head Only look at the first few lines
- tail only look at the tail lines
You can use man [command] to view each command Usage documentation, such as: man cp.
cat
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 and parameters
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 #将几个文件合并为一个文件
tac
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)
nl
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:
- -b: There are two main ways to specify the line number:
- -b a: Indicates that the line number is also listed regardless of whether it is a blank line (similar to cat -n);
- -b t: If there is a blank line, do not list the empty line Line number (default value);
- -n: Lists the ways to represent line numbers. There are three main types:
- -n ln: The line number is on the screen. Displayed at the far left;
- -n rn: The line number is displayed at the far right of its own field without adding 0;
- -n rz: The line number is displayed at the far right of its own field. Display on the right and add 0;
- -w: The number of digits occupied in the line number field.
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
more
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
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 这个程序的运行过程中,你有几个按键可以按的:
- 空白键 (space):代表向下翻一页;
- Enter :代表向下翻『一行』;
- /字串 :代表在这个显示的内容当中,向下搜寻『字串』这个关键字;
- :f :立刻显示出档名以及目前显示的行数;
- q :代表立刻离开 more ,不再显示该文件内容。
- b 或 [ctrl]-b :代表往回翻页,不过这动作只对文件有用,对管线无用。
less
命令功能:
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 | 显示指令的版本信息。 |
- -n :后面接数字,代表显示几行的意思
- -f :表示持续侦测后面所接的档名,要等到按下[ctrl]-c才会结束tail的侦测
[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!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

There are three main ways to install software on Linux: 1. Use a package manager, such as apt, dnf or pacman, and then execute the install command after updating the source, such as sudoaptininstallcurl; 2. For .deb or .rpm files, use dpkg or rpm commands to install, and repair dependencies when needed; 3. Use snap or flatpak to install applications across platforms, such as sudosnapinstall software name, which is suitable for users who are pursuing version updates. It is recommended to use the system's own package manager for better compatibility and performance.

ChoosePop!_OS,Ubuntu,NobaraLinux,orArchLinuxforoptimalgamingperformancewithminimaloverhead.2.InstallofficialNVIDIAproprietarydriversforNVIDIAGPUs,ensureup-to-dateMesaandkernelversionsforAMDandIntelGPUs.3.EnabletheperformanceCPUgovernor,usealow-latenc

Linux is suitable for old hardware, has high security and is customizable, but has weak software compatibility; Windows software is rich and easy to use, but has high resource utilization. 1. In terms of performance, Linux is lightweight and efficient, suitable for old devices; Windows has high hardware requirements. 2. In terms of software, Windows has wider compatibility, especially professional tools and games; Linux needs to use tools to run some software. 3. In terms of security, Linux permission management is stricter and updates are convenient; although Windows is protected, it is still vulnerable to attacks. 4. In terms of difficulty of use, the Linux learning curve is steep; Windows operation is intuitive. Choose according to requirements: choose Linux with performance and security, and choose Windows with compatibility and ease of use.

RAIDimprovesstorageperformanceandreliabilityonLinuxserversthroughvariousconfigurations;RAID0offersspeedbutnoredundancy;RAID1providesmirroringforcriticaldatawith50�pacityloss;RAID5supportssingle-drivefailuretoleranceusingparityandrequiresatleastthre

To manage the startup of Linux services, use the systemctl command. 1. Check the service status: systemctlstatus can check whether the service is running, enabled or disabled. 2. Enable the service startup: sudosystemctlenable, such as sudosystemctlenablenginx. If it is started at the same time, use sudosystemctlenable--nownginx. 3. Disable the service startup: sudosystemctldisable, such as sudosystemctldisablecups. If it is stopped at the same time, use sudosystemctldisabl

Usepsauxforacompletesnapshotofallrunningprocesses,showingdetailedinformationlikeUSER,PID,CPU,andmemoryusage.2.Usetoporhtopforreal-timemonitoringofprocesseswithdynamicupdates,wherehtopoffersamoreintuitiveinterface.3.UsepgreporpidoftoquicklyfindthePIDs

Removeunusedpackagesanddependencieswithsudoaptautoremove,cleanpackagecacheusingsudoaptcleanorautoclean,andremoveoldkernelsviasudoaptautoremove--purge.2.Clearsystemlogswithsudojournalctl--vacuum-time=7d,deletearchivedlogsin/var/log,andempty/tmpand/var

ToviewfilecontentsinLinux,usedifferentcommandsbasedonyourneeds:1.Forsmallfiles,usecattodisplaytheentirecontentatonce,withcat-ntoshowlinenumbers.2.Forlargefiles,uselesstoscrollpagebypageorlinebyline,searchwith/search_term,andquitwithq.3.Usemoreforbasi
