2

enter image description here

I don't understand why the directory dir1 isn't shown with the same colour. Although this may look unimportant, it seems to me that this is a violation of the so oftenly mentioned principle of independence in computing(I have professors who mention it during each lecture).

I know that 'ls' is an argument of 'sudo', but shouldn't 'sudo' just change privileges and then NOT interfere in ANY way with the instruction it receives as an argument?

1

2 Answers 2

3

This discrepancy comes from a simple option to ls nothing else.

In fact your ls is aliased to ls --color=auto. To see it try in terminal,

type ls

That is why you have colored outputs. But when you use sudo ls it uses /bin/ls which does not have the color option with it. So it fails to show colored outputs.

If you try /bin/ls you also will have color less output. Or try sudo ls --color=auto which should give you color.

1
  • 1
    Moreover, sudo will "clean" a lot of environment variables for sake of security. Try env and sudo env and see the difference. The rationale is that the privileged commands must run in a consistent way, independently from what you have set in the profiles for your shell.
    – Rmano
    Jan 10, 2014 at 15:14
0

I believe this is because your user octavian and the elevation of that user's permissions happens in two different shells.

Ubuntu by default uses bash as he shell for users. When you run commands through sudo, the shell changes to sh.

Here is a screenshot demonstrating the different shells.

You can see the first time I run ls, I'm in the bash shell. You can tell because the prompt notes my username, hostname, and current directory.

When I switch to sh, the prompt changes as it's a completely different shell with different features.

enter image description here

There are tons of different shells available, all with different features, prompts, and customization options. One of the most customizable shell is zsh.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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