|
|
Strange ls output as root user
|
|
|
|
Mac Elite
Join Date: Sep 2001
Location: Chico, CA and Carlsbad, CA.
Status:
Offline
|
|
Just noticed this and it's kinda annoying:
Code:
[theman@computer: ~]$ sudo su -
computer:~ root# ls -l
ls: -l: No such file or directory
Yet:
Code:
[theman@computer: ~]$ sudo -s
[root@computer: ~]$ ls -l
total 572416
drwx------ 8 theman theman 272 Dec 3 07:19 Desktop
drwx------ 19 theman theman 646 Nov 22 00:24 Documents
...
drwxr-xr-x 5 theman theman 170 Apr 19 2004 Public
drwxr-xr-x 8 theman theman 272 Aug 21 17:37 Sites
and:
Code:
[theman@computer: ~]$ sudo su
computer:/Users/theman root# ls -l
total 572416
drwx------ 8 theman theman 272 Dec 3 07:19 Desktop
drwx------ 19 theman theman 646 Nov 22 00:24 Documents
...
drwxr-xr-x 5 theman theman 170 Apr 19 2004 Public
drwxr-xr-x 8 theman theman 272 Aug 21 17:37 Sites
For some reason that first command errors. It believe it has to do with the fact that I'm using "-" after su, which is treating the shell as a login shell (thus sourcing all rc files for the shell and setting up the environment). It would seem as if the shell is reading a bad alias or setting in somewhere, but a simple ls -l?
Ahh!
edit: quotes to codes.
(
Last edited by [APi]TheMan; Dec 6, 2004 at 11:38 AM.
)
|
"In Nomine Patris, Et Fili, Et Spiritus Sancti"
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Oct 2000
Location: Seattle
Status:
Offline
|
|
works for me, but I get a list for /private/var/root
according to the man page su - cd s to the user's home folder
[bigEd:~] me% sudo su -
[bigEd:~] root# ls -l
total 24
-rw-r--r-- 1 root wheel 4 21 May 2004 .CFUserTextEncoding
-r--r--r-- 1 root wheel 10 12 Sep 2003 .forward
-rw------- 1 root wheel 1720 24 Sep 2003 .nsmbrc
drwx------ 5 root wheel 170 12 Sep 2003 Library
try this:
root# pwd
/private/var/root
what do you have set as home directory for root?
sudo cat /Private/etc/passwd , as well as netinfo manager
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Sep 2001
Location: Chico, CA and Carlsbad, CA.
Status:
Offline
|
|
Originally posted by Gavin:
according to the man page su - cd s to the user's home folder
Eh, I guess it does that in the process, but it's really just launching a new shell as that user, but it's a login shell. Login shells read certain files when they start up like .bash_profile, .bashrc, and .profile, and start the user off in their own home directory.
Originally posted by Gavin:
[bigEd:~] me% sudo su -
[bigEd:~] root# ls -l
total 24
-rw-r--r-- 1 root wheel 4 21 May 2004 .CFUserTextEncoding
-r--r--r-- 1 root wheel 10 12 Sep 2003 .forward
-rw------- 1 root wheel 1720 24 Sep 2003 .nsmbrc
drwx------ 5 root wheel 170 12 Sep 2003 Library
Well the thing is that I don't get a listing because ls fails and states that it can't find the file or directory "-l" or "-a" when attempting to use ls -l and ls -a.
|
"In Nomine Patris, Et Fili, Et Spiritus Sancti"
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Sep 2001
Location: Chico, CA and Carlsbad, CA.
Status:
Offline
|
|
Even though I solved my problem half way through my previous post I figured it'd be best to finish that train of thought and properly respond to Gavin. Here's what happened:
I use a GNU ls (comes packaged with coreutils) so I can get a colored ls output to more easily identify binaries, directories, etc. In my profile I alias "ls" to "ls --color" and that works fine for my normal user.
The problem is that /bin/ls is not "--color" savvy. What I realized while thinking about what was happening, was that a normal "ls" worked. I checked out my aliases and sure enough "ls" was aliased to "ls --color". A quick check by unalising ls showed that everything worked fine. Sure enough, right inside root's .profile was:
Code:
computer:~ root# more ~/.profile
alias ls='ls --color'
Oops, I guess the mystery is solved.
(
Last edited by [APi]TheMan; Dec 6, 2004 at 11:37 AM.
)
|
"In Nomine Patris, Et Fili, Et Spiritus Sancti"
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Oct 2000
Location: Seattle
Status:
Offline
|
|
Thanks for the update.
Another question. What's the reason for su-ing to root in the first place? I haven't found anything I can't do with sudo.
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Sep 2001
Location: Chico, CA and Carlsbad, CA.
Status:
Offline
|
|
Originally posted by Gavin:
Thanks for the update.
Another question. What's the reason for su-ing to root in the first place? I haven't found anything I can't do with sudo.
- sudo's nice for single commands.
- sudo -s is nice if you just need a quick root shell to run a few commands and don't want to hassle with remembering to prepend your commands with "sudo". Using sudo -s is really just running: sudo bash. If you take a look at your environment settings before and after running sudo, they're basically just your user's settings with a few extra settings about the root user. Also, the "level" of the shell is that of an auxiliary shell (just as if you were to type "tcsh" in one of your shells).
See:
Code:
[theman@computer: ~]$ echo $SHLVL
1
[theman@computer: ~]$ sudo -s
[root@computer: ~]$ echo $SHLVL
2
- su, used without any other options, is used to run a shell as the super user (it is also possible to use su to "switch users" and provide a user name or uid). With su -, that shell is treated as a login shell ($SHLVL is 1), so lots of environment settings get set (through the reading of various files upon initiation) and the shell changes directories to that user's home directory. I guess the extra "-" is not too important, but it's nice just to be 100% root.
The only reason that I started caring about using "su" instead of "sudo" is because of one fairly trivial thing that could really mess with you if you didn't know what was going on:
Code:
[theman@computer: ~]$ echo $HOME
/Users/theman
[theman@computer: ~]$ sudo -s
[root@computer: ~]$ echo $HOME
/Users/theman
See how the home directory for that root shell is still my user's home? Working in the shell as root with his $HOME as my own user's home directory was not good for writing scripts where I was moving, copying, deleting, and writing files.
It basically boils down to each user. Personally, I like being as root as possible without having to log into my computer as the super user himself (there's no root password, so this isn't even possible).
edit: spelling
(
Last edited by [APi]TheMan; Dec 6, 2004 at 04:35 AM.
)
|
"In Nomine Patris, Et Fili, Et Spiritus Sancti"
|
|
|
|
|
|
|
|
Senior User
Join Date: Jan 2001
Location: Mahwah, NJ USA
Status:
Offline
|
|
Very good explanation.
|
-DU-...etc...
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Oct 2000
Location: Seattle
Status:
Offline
|
|
|
|
|
|
|
|
|
|
|
Junior Member
Join Date: Nov 2004
Location: Michigan
Status:
Offline
|
|
Why don't you not replace the default OSX ls and instead use ls -G for color?
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Sep 2001
Location: Chico, CA and Carlsbad, CA.
Status:
Offline
|
|
Originally posted by ctlq:
Why don't you not replace the default OSX ls and instead use ls -G for color?
Eh, it's ugly by default, and I never figured out how to change the colors. A few years ago someone told me about the colored ls that came with coreutils/fileutils and I got used to the default color scheme that version of ls came with. Maybe it would have been different if I hadn't have gotten hooked, but ls -G is so ugly!
Red for an executable? C'mon, everyone knows that a bolded bright green is better!
|
"In Nomine Patris, Et Fili, Et Spiritus Sancti"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|