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?

bsky
  • 1,309
  • 4
  • 14
  • 17
  • Here's an answer for your question: http://askubuntu.com/questions/22037/aliases-not-available-when-using-sudo –  Jan 10 '14 at 14:03

2 Answers2

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.

sourav c.
  • 44,715
  • 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 '14 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.

Sajan Parikh
  • 1,055
  • 1
  • 9
  • 18