Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.


drwx------   2 root root   16384 26. juuli  2009 lost+found

How do I get this to show me completions:

sudo ls -l /lost+found/<TAB>

I'm looking for a solution that works across all commands. AFAICT "complete -cf" and "complete -F" alone are not the magic tools here.. right?

share|improve this question

1 Answer 1

You cannot get bash auto completion for directories/files where you don't have read access to. However, you would get auto completion if you were root already. But since you are about to execute the sudo command still being normaluser when calling for auto completion, it will not work.

This is intended since you would be able to bypass file system permissions otherwise.

share|improve this answer
But doesn't sudo take care of the authorization issues? If the user doesn't have enough sudo privileges, attempts to circumvent permissions will fail either way. I am not getting this: if user already can do "sudo ls -l /lost+found", why it's worse security wise using sudo to get completion results. –  lkraav Jun 16 '12 at 10:02
@lkraav Not until the command is executed. While you are still at your shell prompt, you are still the original user, which doesn't have permission to see into that directory. Once you press enter, then sudo is executed, elevates itself via SUID bit on the executable, checks if you have permission to run the command, asks a password if necessary, and finally executes the command as root (or another user if so specified). –  Stephanie Jun 16 '12 at 10:09
I guess my goal would be possible if completion internal plumbing was done with the help of external utilities like ls, that could be called with sudo. If they're done using internal bash routines, then indeed bash is unprivileged at the time. –  lkraav Jun 16 '12 at 11:54
@lkraav That is correct, and if those external utilities needed to prompt you for a password (as sudo does), how would they do it when you are in the middle of typing a command? I suppose if this were all integrated into the readline library that Bash uses to do all of this (command-line editing and completion), then maybe it could hide the command you were typing and prompt you, then restore the command you were typing. But it currently does not have that functionality. –  Fran Jun 16 '12 at 16:19
@Fran Yeah, password prompts are generally a problem. I have my sudo(s) set up with NOPASSWD so I'm not usually feeling that particular angle. Either way, the external vs internal thinking is what I needed to get to and I probably have enough to get my main use case implemented. Thanks everyone. –  lkraav Jun 16 '12 at 22:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.