在Fish Shell中为历史记录命令启用时间戳记
只要在终端中输入命令,该命令将保存在Linux中历史文件的末尾。 您可以随时使用以下命令轻松检索这些命令 history
命令。 外壳程序还将跟踪所有命令条目的时间戳,以便我们可以轻松找到执行特定命令的时间。 我们已经向您展示了如何在中启用时间戳 重击 和 sh 贝壳。 今天,我们将了解如何在中启用历史记录命令的时间戳 鱼壳 在Linux中。 此外,我们还将学习如何创建一个简单的函数来在fish shell的history命令输出中显示日期和时间戳。
在Fish Shell中为历史记录命令启用时间戳记
从2.6版开始, fish
shell支持内置的时间戳 history
命令。 让我们在 fish
外壳会话:
> lsb_release -a
> uname -r
> hostname -f
> mkdir ostechnix
> cd ostechnix/
> touch ostechnix.txt
> ls
如果您运行 history
不带任何标志的命令,您将看到所有这些以前执行的命令,没有时间戳。
> history
ls
touch ostechnix.txt
cd ostechnix/
mkdir ostechnix
hostname -f
uname -r
lsb_release -a
[...]
为启用时间戳 history
命令输入 fish
外壳,使用 --show-time
标记如下所示:
> history --show-time
样本输出:
# Monday 30 November 2020 02:39:52 PM
history
# Monday 30 November 2020 02:36:52 PM
ls
# Monday 30 November 2020 02:36:47 PM
touch ostechnix.txt
# Monday 30 November 2020 02:36:39 PM
cd ostechnix/
# Monday 30 November 2020 02:36:36 PM
mkdir ostechnix
# Monday 30 November 2020 02:34:11 PM
hostname -f
# Monday 30 November 2020 02:33:51 PM
uname -r
# Monday 30 November 2020 02:33:42 PM
lsb_release -a
[...]
在Fish Shell中为历史记录命令启用时间戳记
如您所见,history命令在每个命令的顶部显示时间戳。 我不喜欢鱼壳显示日期和时间戳的方式。 因此,我自定义了history命令输出,如下所示:
> history --show-time="%F %T "
样本输出:
2020-11-30 14:47:12 history --show-time
2020-11-30 14:39:52 history
2020-11-30 14:36:52 ls
2020-11-30 14:36:47 touch ostechnix.txt
2020-11-30 14:36:39 cd ostechnix/
2020-11-30 14:36:36 mkdir ostechnix
2020-11-30 14:34:11 hostname -f
2020-11-30 14:33:51 uname -r
2020-11-30 14:33:42 lsb_release -a
[...]
现在很完美!
在这里 %F
选项显示日期 YYYY-MM-DD
(年月日)格式。 和 %T
选项以格式显示时间 HH:MM:SS
(时-分-秒)格式。
如果你想展示 只有日期,请使用以下命令:
> history --show-time="%F "
样本输出:
2020-11-30 ls
2020-11-30 touch ostechnix.txt
[...]
显示 只有时间,然后使用:
> history --show-time="%T "
样本输出:
14:36:52 ls
14:36:47 touch ostechnix.txt
[...]
您还可以使用以下不同格式:
> history --show-time="%d/%m/%y %H:%M:%S "
这将以以下格式显示历史记录输出:
30/11/20 14:36:52 ls
30/11/20 14:36:47 touch ostechnix.txt
[...]
这是另一个版本:
> history --show-time="%h/%d - %H:%M:%S "
样本输出:
Nov/30 - 14:36:52 ls
Nov/30 - 14:36:47 touch ostechnix.txt
[...]
鱼的功能,以显示历史命令输出中的日期和时间戳
如果您想节省一些笔触,可以使用 function
像下面一样。
> nano ~/.config/fish/functions/history.fish
注意: 如果 ~/.config/fish/functions/
目录不存在,只需创建它即可。
在下面添加以下行 history.fish
文件:
function history
builtin history --show-time="%F %T "
end
现在 history
该命令将向您显示没有任何标志的时间戳:
在Linux的fish shell中的history命令的输出中显示日期和时间
有关更多详细信息,请参见fish手册页:
> man fish
您现在知道如何显示日期和时间 history
在Linux的fish shell中输出命令。 您还学习了如何使用简单的 function
在鱼壳中为历史命令启用时间戳。 希望您觉得这个有帮助。
FishHistory命令LinuxLinux基础Linux命令Shell Shell提示时间戳