To list the names only of all visible items in the current directory (see cd for information on setting the current directory)
lsTo list detailed information about all items (visible and invisible) in the current directory (the -a option is to show all files, the -l option is to show details)
ls -al
[root->~] ls -lFG
total 112
-rw-r--r-- 1 root wheel 3 Dec 18 19:31 .CFUserTextEncoding
drwxr-xr-x 7 root wheel 238 Jan 19 00:01 .cpan/
-r--r--r-- 1 root wheel 10 Jul 21 2012 .forward
-rw------- 1 root wheel 60 Jan 22 21:42 .lesshst
-rw------- 1 root wheel 1241 Jan 19 23:03 .sh_history
drwx------ 3 root wheel 102 Jan 19 23:02 .ssh/
-rw------- 1 root wheel 5237 Jan 30 20:13 .viminfo
drwx------ 4 root wheel 136 Dec 24 16:21 .vnc/
-rw-r--r-- 1 root wheel 32127 Jan 19 22:47 .zcompdump
-rw------- 1 root wheel 1681 Jan 31 23:21 .zsh_history
drwx------ 8 root wheel 272 Dec 24 16:21 Library/
The problem is that by default 'ls -l' shows the hidden files:
Code:[root->~] ls -lFG total 112 -rw-r--r-- 1 root wheel 3 Dec 18 19:31 .CFUserTextEncoding drwxr-xr-x 7 root wheel 238 Jan 19 00:01 .cpan/ -r--r--r-- 1 root wheel 10 Jul 21 2012 .forward -rw------- 1 root wheel 60 Jan 22 21:42 .lesshst -rw------- 1 root wheel 1241 Jan 19 23:03 .sh_history drwx------ 3 root wheel 102 Jan 19 23:02 .ssh/ -rw------- 1 root wheel 5237 Jan 30 20:13 .viminfo drwx------ 4 root wheel 136 Dec 24 16:21 .vnc/ -rw-r--r-- 1 root wheel 32127 Jan 19 22:47 .zcompdump -rw------- 1 root wheel 1681 Jan 31 23:21 .zsh_history drwx------ 8 root wheel 272 Dec 24 16:21 Library/
When you're logged in as root, ls -l will show hidden files. This doesn't happen when you're logged in as a regular user/admin, and I'm not sure if there's a way to disable it, but that's why your findings contradict what GGJ posted.
edit: To clarify, ls with any argument will show hidden files while logged in as root.
Hi ruqui,
I believe the "-A" is always set for the superuser on the "ls" command. The only way around this is not to be superuser (or perhaps to change superuser's group to not be wheel - but this would be problematic and I'm not sure it would work). So, when logged in as root, you can "su" to a regular administrator's account, "su username". Then "ls" will not show the hidden files. Exiting the "su username" then gets you back to your root login.
I guess you should ask if you need to be logged in as root in the first place? Perhaps "sudo" would accomplish what you need root for?
Regards,
Switon
This behaviour is "awkward" to say the leastIf I'm using root it's supposed that I have total control of my environment so I can do whatever I like (at my own risk of course), I don't like this way of forcing me what to see when I type ls ... it's the only unix-like system I know that does that (and I've worked with several in the last 15 years
)
And regarding your question: yes, I do need to be logged-in as root (technically, I'm not logged in as root, I'm opening a root shell, but it's the same for this purpose) ... I don't like at all to be typing my password every time I need a command as root.
Yeah, I hear you...I also hate how Apple has made certain "decisions" for the users's sake, and I'm particularly sad at the direction that the Mac OS and the OS Server software is taking: eliminating flexibility and options for the sake of simplicity only. I, too, may be forced back to using only Linux because of this.
If I were you I would just alias the ls command to a separate bash command that does /bin/ls followed by grep or awk and cut out all of the dot files that you don't want to see. Thus "ls" under root would not show you these hidden files. Actually, I'd probably alias the new command to something like "lsm" so if I did a "lsm" I wouldn't see the hidden files since it runs the bash command instead while if I did a "ls" it would show the hidden files (or vice versa).
Regards,
Switon
OP, check to see is the ls command is aliased. As root type: 'alias' (no quotes) and see if ls is listed. If it is, it is probably aliased to 'ls -a'. If it is, just type: unalias ls. And you'll be good.
BL.
That's a very good idea, I don't use bash (I'm a zsh fan) but I think I can do this in zsh also. Thanks!
This behaviour is "awkward" to say the leastIf I'm using root it's supposed that I have total control of my environment so I can do whatever I like (at my own risk of course), I don't like this way of forcing me what to see when I type ls ... it's the only unix-like system I know that does that (and I've worked with several in the last 15 years
)
And regarding your question: yes, I do need to be logged-in as root (technically, I'm not logged in as root, I'm opening a root shell, but it's the same for this purpose) ... I don't like at all to be typing my password every time I need a command as root.
suenv command goes here
suenv id
Get the Darwin source for the ls command, change it to do what you want, recompile, install. Total control.
The feature is probably tied to the C code in ls calling getuid() or geteuid() and checking for 0 (root). Assuming it's that or similar, it wouldn't be hard to find.
Copy the /usr/bin/env command to a private location, accessible only to your uid. Change its owner to root. Change its mode to setuid. Change its name to suenv (for example). Add the private dir to your PATH env-var.
To run as root w/o entering a password:
Where "command goes here" is the command to run. For example, try the 'id' command:Code:suenv command goes here
Code:suenv id
It's a bit weird that you log in as root. I didn't know it was possible on OS X but even Unix administrators don't normally do this.
Have you considered using sudo instead? When you need to do a lot of things as root you can use 'sudo -i'.
Well, I must tell you that I am a unix administrator (I administer a couple of enterprise class Oracle Solaris mainframes, a bunch of RedHat blade servers and some other servers) and I can assure you that I do a lot of things as root
I know how to use sudo, the thing is I'm interested in fixing other stuff. BTW, using 'sudo ls' still shows the hidden files, so using sudo is not help at all.
I do wonder if you get the same behavior with GNU ls (on Linux). The manual doesn't seem to say: http://linuxcommand.org/man_pages/ls1.html
Update: if the behavior is different then maybe you could try installing GNU ls. It's in the package coreutils.
GNU ls don't have that problem, so it's a very good idea to install coreutils. Is there a standard method to install this? (my idea is to install using brew, but I'm not sure if there are better methods to do this).