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

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

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

无输出。怎么了?

最佳答案

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

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

10-04 23:43