Every once in awhile, I find myself needing to list files in a directory that I don't have execution permission on. So I do a sudo:
>sudo ll /opt/mydir
[sudo] password for civfan:
sudo: ll: command not found
And then I say, "D'oh!" and switch to ls
. And then remember I really wanted ls -l
. And then remember I REALLY wanted ls -al
.
Can someone save me from myself?
I see that ll
is an alias for my user:
>alias ll
alias ll='ls -alF'
How do I make sudo ll
work? Presumably I need an alias for root... if so, how do I set aliases for root?
EDIT: My guess is trying to run sudo ll
is so common that this question deserves to stand alone from the suggested duplicate.
UPDATE: root already has an ll
alias!
civfan@civfan:~>sudo -s
root@civfan:~>alias ll
alias ll='ls -alF'
And yet sudo ll
doesn't work...
UPDATE 2 - answer:
The answer in the suggested duplicate question fits my workflow the best, and I don't see any downsides. I wanted to note it here:
alias sudo="sudo "
From man bash:
If the last character of the alias value is a blank, then the next command word following the alias is also checked for alias expansion.
ll
as sudo. To your second point, can you elaborate in an answer? – CivFan Jun 15 '15 at 18:11su
orsudo -s
, it turns out thell
alias already exists. I don't know whysudo ll
doesn't work, then. – CivFan Jun 15 '15 at 18:22ll
works when switched to root user. – CivFan Jun 15 '15 at 18:27ll
is a shell alias,sudo
does not run the command in a shell. – ctrl-alt-delor Jun 15 '15 at 19:18