I wanted to run two sudo commands, piping the output from one to the other. However, when I haven't entered my password for sudo recently, it prompts me for the password. The pipes and two sudos seem to screw it up, so I can't correctly enter my password.
My solution to this is to run "sudo ls" or something else that prompts me for my password, so that the piped commands will work without asking me to enter it. This got me wondering if there was a "correct" way to run sudo such that you're not also running some other pointless command. The manpage for sudo doesn't seem to say anything about this.
Best Answer
What you are looking for is
sudo -v
. From the man page:(And the counterpart to explicitly remove the credentials:
sudo -k
)