Linux在history上添加时间和用户等参数的方法(图)

原标题:”Linux在history上添加时间和用户等参数的方法”相关电脑问题教程分享。 – 来源:WiFi之家网。众所周知,Linux系统下可以使用history命令来查看指令的历史记录。为了提高hi

亲,以下就是关于(Linux在history上添加时间和用户等参数的方法(图)),由“WiFi之家网”整理!

Linux在history上添加时间和用户等参数的方法(图)

原标题:"Linux在history上添加时间和用户等参数的方法"相关电脑问题教程分享。 – 来源:WiFi之家网。

  众所周知,Linux系统下可以使用history命令来查看指令的历史记录。为了提高history命令的效率,还可以在history命令加上一些参数,比如时间、用户和IP等等参数。那么如何在history上添加这些参数呢?想必很多用户都想知道,下面跟随WiFi之家网小编一起来看看Linux在history上添加时间和用户等参数的方法。

Linux系统

Linux系统

  1.设置显示时间和用户:

  echo ‘export HISTTIMEFORMAT=“%F %T `whoami` ”’ 》》 /etc/profile

  执行source生效:

  source /etc/profile

  查看结果:

  history

  1852 2016-01-11 16:24:52 xubo hs

  1853 2016-01-11 16:24:53 xubo ls

  1854 2016-01-11 16:24:56 xubo history

  1855 2016-01-11 16:25:02 xubo history –help

  1856 2016-01-11 16:26:35 xubo vi /etc/profile

  1857 2016-01-11 16:27:27 xubo echo ‘export HISTTIMEFORMAT=“%F %T `whoami` ”’ 》》 /etc/profile

  1858 2016-01-11 16:27:29 xubo vi /etc/profile

  1859 2016-01-11 16:27:42 xubo source /etc/profile

  1860 2016-01-11 16:27:46 xubo history

  1861 2016-01-11 16:27:59 xubo ls

  1862 2016-01-11 16:28:01 xubo history

  1863 2016-01-11 16:31:00 xubo clear

  1864 2016-01-11 16:31:02 xubo history

  2.只看到自己的操作记录(时间,用户,ip名):

  USER_IP=`who -u am i 2》/dev/null| awk ‘{print $NF}’|sed -e ‘s/[()]//g’`

  xport HISTTIMEFORMAT=“[%F %T][`whoami`][${USER_IP}] ”

  执行source生效:

  source /etc/profile

  查看结果:

  hadoop@Master:~$ history

  1002 [2016-01-11 16:47:37][hadoop][host-e-150.ustcsz.edu.cn] cd 。。/

  1003 [2016-01-11 16:47:37][hadoop][host-e-150.ustcsz.edu.cn] du -h –max-depth=1

  1004 [2016-01-11 16:47:37][hadoop][host-e-150.ustcsz.edu.cn] du -h –max-depth=2

  1005 [2016-01-11 16:47:37][hadoop][host-e-150.ustcsz.edu.cn] sudo find /* -name pokec-relationships

  1006 [2016-01-11 16:47:37][hadoop][host-e-150.ustcsz.edu.cn] sudo find /* -name pokec

  1007 [2016-01-11 16:47:37][hadoop][host-e-150.ustcsz.edu.cn] sudo find /* -name kddcup

  1008 [2016-01-11 16:47:37][hadoop][host-e-150.ustcsz.edu.cn] sudo find /* -name kddcup*

  1009 [2016-01-11 16:47:37][hadoop][host-e-150.ustcsz.edu.cn] sudo find /* -name *kddcup*

  3.将history记录到log:

  #export HISTTIMEFORMAT=“%F %T $USER_IP:`whoami` ”

  #export HISTTIMEFORMAT=“%F %T $USER_IP:`whoami` ”

  USER_IP=`who -u am i 2》/dev/null| awk ‘{print $NF}’|sed -e ‘s/[()]//g’`

  export HISTTIMEFORMAT=“[%F %T][`whoami`][${USER_IP}] ”

  #history

  LOGIP=`who -u am i 2》/dev/null| awk ‘{print $NF}’|sed -e ‘s/[()]//g’`

  LOG_DIR=/var/log/history

  if [ -z $LOGIP ]

  then

  LOGIP=`hostname`

  fi

  if [ ! -d $LOG_DIR ]

  then

  mkdir -p $LOG_DIR

  chmod 777 $LOG_DIR

  fi

  if [ ! -d $LOG_DIR/${LOGNAME} ]

  then

  mkdir -p $LOG_DIR/${LOGNAME}

  chmod 777 $LOG_DIR/${LOGNAME}

  fi

  export HISTSIZE=4096

  LOGTM=`date +“%Y%m%d_%H%M%S”`

  export HISTFILE=“$LOG_DIR/${LOGNAME}/${LOGIP}-$LOGTM”

  chmod 777 $LOG_DIR/${LOGNAME}/*-* 2》/dev/null

  运行结果:

  root@xubo:/media/xubo/My Passport/gene_data/1000genomes# ls /var/log/history/root/

  host-e-150.ustcsz.edu.cn-20160111_171845 host-e-150.ustcsz.edu.cn-20160111_172719 host-e-213.ustcsz.edu.cn-20160111_202047

  root@xubo:/media/xubo/My Passport/gene_data/1000genomes# vi /var/log/history/root/host-e-213.ustcsz.edu.cn-20160111_202047

  #1452514808

  ls root/

  #1452514818

  history

  #1452514847

  source /etc/profile

  #1452514848

  history

  #1452514860

  ls root/

  #1452514861

  ls

  #1452514863

  cd root/

  #1452514864

  ls

  #1452514866

  exit

  以上就是Linux在history上添加时间和用户等参数的方法

  相关内容推荐:

  修改Linux系统Shell脚本输出文字的颜色的方法

以上就是关于-常见问题-(Linux在history上添加时间和用户等参数的方法(图))的教程!

原创文章,作者:常见问题,如若转载,请注明出处:https://www.224m.com/114682.html

赞 (0)
常见问题常见问题

相关推荐

  • wifi扩展器到底有没有用?(wifi扩展器有用还是没用?)

    请问各位:wifi扩展器有用吗? 答:Wi-Fi扩展器称为Wi-Fi放大器,主要用于放大路由器的wifi信号,增强wifi的覆盖范围。这一点毋庸置疑,大家可以放心,这里推荐一款不错…

    2023年7月3日
    35.0K
  • 多台无线路由器怎么连接?

    在这个被网络覆盖的时代,无线网络似乎成为了人们必不可少的工具。如果家庭或单位想要使用多台路由器上网,满足更多人的需求,那么按下面的方法连接吧,简单快捷。

    2023年5月28日
    79.5K
  • 电信“云宽带”是什么?

    电信行业一直处于快速变化之中,为了更好地满足用户需求,新的技术和服务不断涌现。其中,“云宽带”是近年来备受关注的一个概念,那么,电信“云宽带”究竟是什么呢? 什么是“云宽带”? 简…

    2023年5月25日
    14.1K
  • 路由器会不会自动的限制网速?

    路由器本身不会自动限制网速,但是路由器的一些设置可能会导致网速的限制。以下是一些可能导致网速受限的设置: 1.QoS设置 路由器的QoS(Quality of Service)设置…

    2023年3月27日
    46.6K
  • 猫(Modem)与路由器有什么区别?

    猫(Modem)和路由器是网络中的两种不同的设备,它们各自有着不同的功能和作用。 猫(Modem) 猫是调制解调器的缩写,它是将数字信号转换成模拟信号或者将模拟信号转换成数字信号的…

    2023年3月27日
    11.7K
  • 无线路由器怎么改密码

    1、登录你要更改的路由器,我的就是192.168.1.1,各个品牌登录地址不同的,具体的路由器后背有登录地址的,如图所示 2、打开浏览器,在地址栏输入路由器IP地址192.168.…

    2023年3月27日
    17.7K
⚡ WP超强优化 · 实时生成 · 已写入缓存 · 生成查询 65 次 · 生成耗时 0.438 秒 · 内存 48.5 MB