Operation and Maintenance
Linux Operation and Maintenance
What are the three commands to view logs in Linux?
What are the three commands to view logs in Linux?
There are three commands for viewing logs in Linux: 1. tail command, which can monitor logs in real time, with the syntax "sudo tail parameter log file path"; 2. multitail command, which can monitor and track multiple log files in real time, and also Allows users to navigate back and forth in monitored files; 3. The lnav command can monitor multiple log files in real time, and can watch and track multiple files and display their contents in real time.

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
Three commands to view logs in real time on Linux
1. tail command - real-time monitoring of logs
As mentioned above, the tail command is the most common solution for displaying log files in real time. However, there are two versions of the command that displays the file, as shown in the example below.
In the first example, the command tail requires the -f parameter to trace the contents of the file.
$ sudo tail -f /var/log/apache2/access.log

Real-time monitoring of Apache logs
The second version of this command is actually a command itself: tailf. You don't need to use the -f switch because the command is built-in with the -f parameter.
$ sudo tailf /var/log/apache2/access.log

Real-time Apache log monitoring
Typically, the logrotate utility rotates log files frequently on a Linux server. To view the rotated log files on a daily basis, you can use the tail -F command.
tail -F will track new log files being created and start tracking new files instead of old files.
$ sudo tail -f /var/log/apache2/access.log
However, by default, the tail command will display the last 10 lines of the file. For example, if you only want to view the last two lines of a log file in real time, use the -n file combined with the -f flag, as shown in the example below.
$ sudo tail -n2 -f /var/log/apache2/access.log

View the last two lines of log
2.multitail command - monitor multiple log files in real time
Another interesting command for displaying log files in real time is the multitail command. The name of the command means that the multitail utility can monitor and track multiple files in real time. Multitail also allows you to navigate back and forth among monitored files.
To install mulitail utility in Debian and RedHat based systems, issue the following command.
$ sudo apt install multitail [On Debian&Ubuntu] $ sudo yum install multitail [On RedHat&CentOS] $ sudo dnf install multitail [On Fedora 22+ version]
To display the output of two log files simultaneously, execute the command shown in the following example.
$ sudo multitail /var/log/apache2/access.log /var/log/apache2/error.log

Multiple monitoring logs
3. lnav command - real-time monitoring of multiple log files
Another interesting command, similar to the multitail command, is the lnav command. The Lnav utility can also watch and track multiple files and display their contents in real time.
Install the lnav utility in Debian and RedHat based Linux distributions by issuing the following command.
$ sudo apt install lnav [On Debian&Ubuntu] $ sudo yum install lnav [On RedHat&CentOS] $ sudo dnf install lnav [On Fedora 22+ version]
Observe the contents of two log files simultaneously by issuing the command, as shown in the example below.
$ sudo lnav /var/log/apache2/access.log /var/log/apache2/error.log

lnav - Real-time log monitoring
Related recommendations: "Linux Video Tutorial"
The above is the detailed content of What are the three commands to view logs 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)
How to install software on Linux using the terminal?
Aug 02, 2025 pm 12:58 PM
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.
The Ultimate Guide to High-Performance Gaming on Linux
Aug 03, 2025 am 05:51 AM
ChoosePop!_OS,Ubuntu,NobaraLinux,orArchLinuxforoptimalgamingperformancewithminimaloverhead.2.InstallofficialNVIDIAproprietarydriversforNVIDIAGPUs,ensureup-to-dateMesaandkernelversionsforAMDandIntelGPUs.3.EnabletheperformanceCPUgovernor,usealow-latenc
What are the main pros and cons of Linux vs. Windows?
Aug 03, 2025 am 02:56 AM
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.
Understanding RAID Configurations on a Linux Server
Aug 05, 2025 am 11:50 AM
RAIDimprovesstorageperformanceandreliabilityonLinuxserversthroughvariousconfigurations;RAID0offersspeedbutnoredundancy;RAID1providesmirroringforcriticaldatawith50�pacityloss;RAID5supportssingle-drivefailuretoleranceusingparityandrequiresatleastthre
Linux how to enable and disable services at boot
Aug 08, 2025 am 10:23 AM
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
Linux how to list all running processes
Aug 08, 2025 am 06:42 AM
Usepsauxforacompletesnapshotofallrunningprocesses,showingdetailedinformationlikeUSER,PID,CPU,andmemoryusage.2.Usetoporhtopforreal-timemonitoringofprocesseswithdynamicupdates,wherehtopoffersamoreintuitiveinterface.3.UsepgreporpidoftoquicklyfindthePIDs
How to clean up your Linux system
Aug 22, 2025 am 07:42 AM
Removeunusedpackagesanddependencieswithsudoaptautoremove,cleanpackagecacheusingsudoaptcleanorautoclean,andremoveoldkernelsviasudoaptautoremove--purge.2.Clearsystemlogswithsudojournalctl--vacuum-time=7d,deletearchivedlogsin/var/log,andempty/tmpand/var
Linux how to view the contents of a file
Aug 19, 2025 pm 06:44 PM
ToviewfilecontentsinLinux,usedifferentcommandsbasedonyourneeds:1.Forsmallfiles,usecattodisplaytheentirecontentatonce,withcat-ntoshowlinenumbers.2.Forlargefiles,uselesstoscrollpagebypageorlinebyline,searchwith/search_term,andquitwithq.3.Usemoreforbasi


