CentOS8-linux安装 tailf命令

CentOS8-linux安装 tailf命令

一、起因

我安装的 CentOS8-linux 中,没有tailf命令,在网上搜了安装的方法,整理如下。可能不是最简单的,但亲测有效。

二、tailf 简介

(网上搜的,如果不感兴趣,可以直接跳过!)

  1. tailf命令几乎等同于tail -f,严格说来应该与tail --follow=name更相似些。

  2. 当文件改名之后它也能继续跟踪,特别适合于日志文件的跟踪(follow the growth of a log file)。

  3. 与tail -f不同的是,如果文件不增长,它不会去访问磁盘文件(It is similar to tail -f but does not access the file when it is not growing. This has the side effect of not updating the access time for the file, so a filesystem flush does not occur periodically when no log activity is happening.)。

  4. tailf特别适合那些便携机上跟踪日志文件,因为它能省电,因为减少了磁盘访问嘛(tailf is extremely useful for monitoring log files on a laptop when logging is infrequent and the user desires that the hard disk spin down to conserve battery life.)。

  5. tailf命令不是个脚本,而是一个用C代码编译后的二进制执行文件,某些Linux安装之后没有这个命令,本文提供了怎么编译安装tailf命令的方法。

三、使用格式

格式:tailf logfile
动态跟踪日志文件logfile,最初的时候默认打印文件的最后10行内容。

四、安装

  1. 将下面代码存储到 tailf.c 文件中,上传到 CentOS8-linux 中(上传方式:方式一,可以直接拖到 /usr/local或者 /usr/local/tmp目录下,tmp 是我自己建的;方式二,使用 FileZilla 等基于 FTP协议的客户端工具)
/* tailf.c -- tail a log file and then follow it 
 * Created: Tue Jan  9 15:49:21 1996 by [email protected] 
 * Copyright 1996, 2003 Rickard E. Faith ([email protected]) 
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a 
 * copy of this software and associated documentation files (the "Software"), 
 * to deal in the Software without restriction, including without limitation 
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
 * and/or sell copies of the Software, and to permit persons to whom the 
 * Software is furnished to do so, subject to the following conditions: 
 * 
 * The above copyright notice and this permission notice shall be included 
 * in all copies or substantial portions of the Software. 
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
 * OTHER DEALINGS IN THE SOFTWARE. 
 *  
 * less -F and tail -f cause a disk access every five seconds.  This 
 * program avoids this problem by waiting for the file size to change. 
 * Hence, the file is not accessed, and the access time does not need to be 
 * flushed back to disk.  This is sort of a "stealth" tail. 
 */  
  
#include   
#include   
#include   
#include   
#include   
//#include "nls.h"  
#define _(s) s  
  
static size_t filesize(const char *filename)  
{
     
    

你可能感兴趣的:(Linux,linux,centos)