AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

    • 主页
    • 系统&网络
    • Ubuntu
    • Unix
    • DBA
    • Computer
    • Coding
    • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题

问题[command-history](unix)

Martin Hope
user598527
Asked: 2024-03-17 17:28:16 +0800 CST

什么是“.tee_history”文件?

  • 11

这是一个纯文本文件,显然限制为 300 行。我经常在我的系统上使用tee。

$ file .tee_history
.tee_history: Unicode text, UTF-8 text
$ wc -l .tee_history
300 .tee_history
$ tee --version
tee (GNU coreutils) 9.3

我对历史没有任何用处。是否可以轻松禁用此日志记录,或者定期截断 ( > .tee_history) 或删除文件是最明智的解决方案?

command-history
  • 1 个回答
  • 1027 Views
Martin Hope
Aleksey
Asked: 2024-01-13 21:19:04 +0800 CST

在哪里可以知道哪个版本的本机 Linux 命令具有特定功能?

  • 5

我有lscpu具有特定属性的 Linux 命令-J允许以 JSON 格式输出。

我想在数百台具有不同 Linux 发行版的主机上使用该命令来获取 CPU 信息。我想自动完成。

不久前,我收到警告,该-J属性是新的命令功能,它可能在较旧的 Linux 发行版中关闭。

我想建议有多少主机支持该功能。我应该使用哪些文档来了解-Jlscpu 何时包含在内?

所有网页描述的命令仅具有当前的状态。

command-history
  • 1 个回答
  • 24 Views
Martin Hope
Jesse Taube
Asked: 2022-09-15 08:58:51 +0800 CST

bash_history 可以保存评估的命令输出吗?

  • 1

当它是一个参数时,bash 或其他 shell 的历史记录是否可以保存评估命令的输出?

$ echo $(pwd) && history
 /root
 0  I want something like:
 1  echo $(pwd) && history
 2  echo /root && history

VS

$ echo $(pwd) && history
 /root
 0  echo $(pwd) && history
bash command-history
  • 1 个回答
  • 21 Views
Martin Hope
gcv
Asked: 2022-06-21 14:10:12 +0800 CST

导出以 '\0' 字符而不是 '\n' 分隔的 zsh 历史记录

  • 3

我想访问 zsh 历史记录,其中的条目由分隔\0而不是\n. 内置解析器可以清楚地处理多行条目,因为fc 123会打开一个保留换行符的编辑器。但是,fc -l 123(打印到标准输出而不是启动编辑器)将换行符转换为\\n. 这意味着历史中包含文字的任何命令\n都不能与换行符消除歧义(例如,printf "\n"在 awk 调用中)。

有没有办法在 zsh 中使用fc或内置函数来获取未更改的历史条目?history我试图避免编写历史文件解析器的工作。作为参考,fish 有history -z这个用例。

(奖励:我也想做同样的事情来分析 bash 历史。它fc的行为似乎与 zsh 不同。)

zsh command-history
  • 2 个回答
  • 66 Views
Martin Hope
Damn Vegetables
Asked: 2022-05-16 14:31:26 +0800 CST

如何使用历史信息/保持计数?

  • 0

man history 说history info ?count?和history keep ?count?。我不知道这两个问号是什么意思。我试图history keep 1000保留 1000 个历史项目,但它刚刚返回fc: event not found: keep。我在谷歌上找不到任何例子。如何使用它们。问号是什么?

command-history
  • 1 个回答
  • 22 Views
Martin Hope
jamesdlin
Asked: 2022-02-26 23:12:34 +0800 CST

有没有一种简单的方法可以避免在 bash 的 HISTIGNORE 中重复命令?

  • 2

无论参数如何,我都想忽略我的 bash 历史记录中对命令的所有调用。例如,要排除所有ls、ls -l和ls SOME_DIRECTORY,我的理解是我需要这样做:

HISTIGNORE='ls:ls *'

我不能仅仅HISTIGNORE='ls*'因为那也会忽略其他以 开头的命令ls,这是不可取的。但是,ls当ls *我将条目添加到HISTIGNORE.

有没有一种模式可以用来匹配命令本身和参数?

bash command-history
  • 1 个回答
  • 88 Views
Martin Hope
Govind Rai
Asked: 2022-02-21 16:29:12 +0800 CST

zsh history 命令支持比文档状态更多的选项

  • 0

zsh 中的 history 命令支持类似的选项-c,-w即使文档声明没有这样的选项。

运行man zshbuiltins显示历史命令的文档。它说:

       history
              Same as fc -l.

滚动到fc同一 man 文件中较低的命令文档说:

       fc [ -e ename ] [ -LI ] [ -m match ] [ old=new ... ] [ first [ last ] ]
       fc -l [ -LI ] [ -nrdfEiD ] [ -t timefmt ] [ -m match ]
             [ old=new ... ] [ first [ last ] ]
       fc -p [ -a ] [ filename [ histsize [ savehistsize ] ] ]
       fc -P
       fc -ARWI [ filename ]
              The fc command controls the interactive history mechanism.  Note that reading and writing of history options is only performed if the shell is interactive.  Usually this is
              detected automatically, but it can be forced by setting the interactive option when starting the shell.

              The first two forms of this command select a range of events from first to last from the history list.  The arguments first and last may be specified as a number or as a string.
              A negative number is used as an offset to the current history event number.  A string specifies the most recent event beginning with the given string.  All substitutions old=new,
              if any, are then performed on the text of the events.

              In addition to the number range,
              -I     restricts to only internal events (not from $HISTFILE)
              -L     restricts to only local events (not from other shells, see SHARE_HISTORY in zshoptions(1) -- note that $HISTFILE is considered local when read at startup)
              -m     takes the first argument as a pattern (should be quoted) and only the history events matching this pattern are considered

              If first is not specified, it will be set to -1 (the most recent event), or to -16 if the -l flag is given.  If last is not specified, it will be set to first, or to -1 if the -l
              flag is given.  However, if the current event has added entries to the history with `print -s' or `fc -R', then the default last for -l includes all new history entries since the
              current event began.

              When the -l flag is given, the resulting events are listed on standard output.  Otherwise the editor program specified by -e ename is invoked on a file containing these history
              events.  If -e is not given, the value of the parameter FCEDIT is used; if that is not set the value of the parameter EDITOR is used; if that is not set a builtin default,
              usually `vi' is used.  If ename is `-', no editor is invoked.  When editing is complete, the edited command is executed.

              The flag -r reverses the order of the events and the flag -n suppresses event numbers when listing.

              Also when listing,
              -d     prints timestamps for each event
              -f     prints full time-date stamps in the US `MM/DD/YY hh:mm' format
              -E     prints full time-date stamps in the European `dd.mm.yyyy hh:mm' format
              -i     prints full time-date stamps in ISO8601 `yyyy-mm-dd hh:mm' format
              -t fmt prints time and date stamps in the given format; fmt is formatted with the strftime function with the zsh extensions described for the %D{string} prompt format in the
                     section EXPANSION OF PROMPT SEQUENCES in zshmisc(1).  The resulting formatted string must be no more than 256 characters or will not be printed
              -D     prints elapsed times; may be combined with one of the options above

              `fc -p' pushes the current history list onto a stack and switches to a new history list.  If the -a option is also specified, this history list will be automatically popped when
              the current function scope is exited, which is a much better solution than creating a trap function to call `fc -P' manually.  If no arguments are specified, the history list is
              left empty, $HISTFILE is unset, and $HISTSIZE & $SAVEHIST are set to their default values.  If one argument is given, $HISTFILE is set to that filename, $HISTSIZE & $SAVEHIST are
              left unchanged, and the history file is read in (if it exists) to initialize the new list.  If a second argument is specified, $HISTSIZE & $SAVEHIST are instead set to the single
              specified numeric value.  Finally, if a third argument is specified, $SAVEHIST is set to a separate value from $HISTSIZE.  You are free to change these environment values for the
              new history list however you desire in order to manipulate the new history list.

              `fc -P' pops the history list back to an older list saved by `fc -p'.  The current list is saved to its $HISTFILE before it is destroyed (assuming that $HISTFILE and $SAVEHIST
              are set appropriately, of course).  The values of $HISTFILE, $HISTSIZE, and $SAVEHIST are restored to the values they had when `fc -p' was called.  Note that this restoration can
              conflict with making these variables "local", so your best bet is to avoid local declarations for these variables in functions that use `fc -p'.  The one other guaranteed-safe
              combination is declaring these variables to be local at the top of your function and using the automatic option (-a) with `fc -p'.  Finally, note that it is legal to manually pop
              a push marked for automatic popping if you need to do so before the function exits.

              `fc -R' reads the history from the given file, `fc -W' writes the history out to the given file, and `fc -A' appends the history out to the given file.  If no filename is
              specified, the $HISTFILE is assumed.  If the -I option is added to -R, only those events that are not already contained within the internal history list are added.  If the -I
              option is added to -A or -W, only those events that are new since last incremental append/write to the history file are appended/written.  In any case, the created file will have
              no more than $SAVEHIST entries.

这些选项是如何工作的?我在 macosx monterey 上使用 zsh 5.8。

zsh command-history
  • 1 个回答
  • 197 Views
Martin Hope
sdbbs
Asked: 2021-12-05 03:06:58 +0800 CST

为什么历史不在子shell中输出任何内容?

  • 1

我刚刚意识到它history不会在子外壳中输出任何内容。我将尝试通过计算行数来显示 - 首先使用 echo 进行完整性检查:

$ echo a | wc -l
1

...在一个子shell中:

bash -c 'echo a' | wc -l
1

实际上,我们期望在这两种情况下都有一条线路输出。现在,对于history:

$ history | wc -l
681

...但在一个子外壳中:

$ bash -c 'history' | wc -l
0

...history不返回任何行。

为什么会发生这种情况 - 我怎样才能history在子 shell 中输出当前 shell 的历史记录(包括上次会话命令)?

bash command-history
  • 1 个回答
  • 73 Views
Martin Hope
dshri
Asked: 2021-10-30 01:17:32 +0800 CST

Bash 命令历史停止工作

  • 0

bash_history由于某种原因,我的文件中不再有新条目,并且执行history不会返回任何内容。历史文件的所有者是正确的并且具有读、写权限。我试过了

set -o history

但这也无济于事。

有谁知道什么可能触发了这种行为以及如何从这一点重新启用历史记录?

编辑:: 这里有一些有用的细节

$ echo $HISTFILESIZE
-1
$ echo $HISTSIZE
-1
bash command-history
  • 1 个回答
  • 747 Views
Martin Hope
Yvan Sraka
Asked: 2021-10-23 10:44:18 +0800 CST

一段时间后自动删除 .zsh_history 的最佳方法是什么?

  • 0

我觉得没有 ZSH 设置选项可以在一段时间后自动删除.zsh_history(例如,从现在起超过一个月)。实现它的最简单的方法是什么?

zsh command-history
  • 1 个回答
  • 189 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助
subwaysurfers
my femboy roommate

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve