I'm not too sure I follow - if you want to rerun the last command each shell has a different syntax to allow this - the
last command shows a history of logins, not commands. Some OS's provide the
lastcomm command if accounting is enabled, although this may require superuser privileges.
You can look into
fc -e -, I always alias this (if not pre-aliased) to
r in Bourne-type shells thusly:
alias r='fc -e -'
Then you can do stuff like
$ r ls
ls -la /my/dir
which will execute the last command in your history (providing your shell supports history) starting with "ls".
As I say, each shell supports differing history syntax and functionality, please post the output of
echo $0
echo $SHELL
uname -a
plus a further rundown of your exact requirements for a more detailed solution.
EDIT: Looking back at your OP, do you want to run
last as a user that doesn't have the privilege to run the command? If so
sudo may be the solution.
Cheers
ZB