linux - 历史和剪切命令 : get the second field

标签 linux bash shell cut

我正在尝试从历史命令中获取命令。

ubuntu@ip-172-31-13-192:~/redacted$ history
 1  ls
 2  sudo apt-get install git -y
 3  git clone https://redacted@bitbucket.org/redacted/redacted.git
 4  ls
 5  cd redacted

ubuntu@ip-172-31-13-192:~/redacted$ history | cut -d ' ' -f 2

没有输出。怎么了?

最佳答案

每行的开头也有空格,因此第 2 列很可能只是另一个空格。由于历史记录的格式是固定的,您可以根据字符数来进行剪切,如下所示:

[mureinik@computer /]$ history | cut -c8-

关于linux - 历史和剪切命令 : get the second field,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26328833/

相关文章:

bash - Shell 脚本反斜杠和空格参数

c++ - 使用 gcc 版本 4.1.2 模拟 is_pointer

linux - 使用 lsof 检查文件是否打开

linux - 如何遍历目录并获取每个 txt 文件的 wc?

bash - 使用 awk 和 mkdir 创建带有空格的目录

python - 如何使用 Python 运行快捷键?

java - 我如何使用星号执行 getRuntime().exec?

linux写系统调用和libc

c - 使用 Linux 接收系统 key 的信号?

linux - 如何使用 grep 处理那些复杂的表达式?