这是一个困扰我的理论心理游戏。
如果我想在输入的命令前面添加 sudo 等命令,一种方法是为特定命令设置别名。但我想知道是否也可以使用通用方法,所以现在无论我输入什么命令,特定的命令/字符串都会添加到命令行的开头。
有任何想法吗?
答案1
您可能对历史替换感兴趣!!
,它会替换!!
您的最后一个命令。
$ apt update
Reading package lists... Done
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
W: Problem unlinking the file /var/cache/apt/pkgcache.bin - RemoveCaches (13: Permission denied)
W: Problem unlinking the file /var/cache/apt/srcpkgcache.bin - RemoveCaches (13: Permission denied)
$ sudo !!
[sudo] password for panki:
[...]
Reading package lists... Done
Building dependency tree
Reading state information... Done
42 packages can be upgraded. Run 'apt list --upgradable' to see them.
如果这种情况经常发生在您身上,您可能需要考虑设置alias
:
alias dangit='sudo !!'
这使得这成为可能:
$ less /etc/shadow
/etc/shadow: Permission denied
$ dangit
<less opens the file>