2024-04-25 01:10:27 发布
网友
命令grep -n blink ~/.bash_history输出包含blink的所有行。我需要一个只输出行号的命令,并在history -d linenum上执行行号 在python中:
grep -n blink ~/.bash_history
blink
history -d linenum
#list generated from command linenumbers = [1,2,3,4,5] for count in range(linenumbers): os.system("history -d {}".format(count))
我该怎么做?你知道吗
在bash中:
for offset in $(history | awk '/blink/ {print $1}' | tac) do history -d $offset done
您可以直接从history命令获得偏移量,无需使用grep生成行号。此外,您还需要反向删除这些行(因此使用tac),因为被删除的命令后面的命令的偏移量被下移。你知道吗
history
grep
tac
在bash中:
您可以直接从
history
命令获得偏移量,无需使用grep
生成行号。此外,您还需要反向删除这些行(因此使用tac
),因为被删除的命令后面的命令的偏移量被下移。你知道吗相关问题 更多 >
编程相关推荐