Go Back   MacRumors Forums > Apple Systems and Services > OS X

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 31, 2013, 07:58 PM   #1
ruqui
macrumors newbie
 
Join Date: Jan 2013
Hidden files in Terminal

I have a question, how can I disable the option to see hidden files when doing a 'ls -l' in a terminal window?
ruqui is offline   0 Reply With Quote
Old Jan 31, 2013, 07:59 PM   #2
GGJstudios
macrumors Westmere
 
Join Date: May 2008
http://guides.macrumors.com/ls

Quote:
To list the names only of all visible items in the current directory (see cd for information on setting the current directory)
ls
To 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
GGJstudios is offline   0 Reply With Quote
Old Jan 31, 2013, 08:22 PM   #3
ruqui
Thread Starter
macrumors newbie
 
Join Date: Jan 2013
Quote:
Originally Posted by GGJstudios View Post
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/
ruqui is offline   0 Reply With Quote
Old Jan 31, 2013, 08:39 PM   #4
Stooby Mcdoobie
macrumors 6502a
 
Stooby Mcdoobie's Avatar
 
Join Date: Jun 2012
Location: Dallas, TX
Quote:
Originally Posted by ruqui View Post
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.

Last edited by Stooby Mcdoobie; Jan 31, 2013 at 08:45 PM. Reason: clarification
Stooby Mcdoobie is offline   0 Reply With Quote
Old Feb 1, 2013, 08:38 AM   #5
ruqui
Thread Starter
macrumors newbie
 
Join Date: Jan 2013
Quote:
Originally Posted by Stooby Mcdoobie View Post
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.
Yes, I forgot to mention that the problem is only with user root sorry about that.

Is it possible to disable this behaviour? (I only want to see hidden files when I need them, not every time).
ruqui is offline   0 Reply With Quote
Old Feb 1, 2013, 09:17 AM   #6
switon
macrumors 6502a
 
Join Date: Sep 2012
RE: ls and super user...

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
switon is offline   0 Reply With Quote
Old Feb 1, 2013, 09:58 AM   #7
ruqui
Thread Starter
macrumors newbie
 
Join Date: Jan 2013
Quote:
Originally Posted by switon View Post
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 least If 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.
ruqui is offline   0 Reply With Quote
Old Feb 1, 2013, 12:50 PM   #8
switon
macrumors 6502a
 
Join Date: Sep 2012
RE: Apple and ...

Quote:
Originally Posted by ruqui View Post
This behaviour is "awkward" to say the least If 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

Last edited by switon; Feb 2, 2013 at 07:16 AM.
switon is offline   0 Reply With Quote
Old Feb 2, 2013, 11:23 PM   #9
ruqui
Thread Starter
macrumors newbie
 
Join Date: Jan 2013
Quote:
Originally Posted by switon View Post
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.
Yes, I agree with you. I've just bought a Macbook Pro because I became somewhat tired of fighting with Linux to recognize all the hardware, at first it was very nice to see that everything worked out of the box in the Mac, but as I start really using it I'm beginnig to notice the lack of flexibility here and there ... probably when Linux solves the issue with the newest UEFi BIOS I'll go back to use them as my primary desktop, probably my next notebook will be Linux again.

Quote:
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
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!

Last edited by ruqui; Feb 3, 2013 at 12:51 AM.
ruqui is offline   0 Reply With Quote
Old Feb 2, 2013, 11:36 PM   #10
bradl
macrumors 68030
 
Join Date: Jun 2008
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.
bradl is offline   0 Reply With Quote
Old Feb 3, 2013, 01:00 AM   #11
ruqui
Thread Starter
macrumors newbie
 
Join Date: Jan 2013
Quote:
Originally Posted by bradl View Post
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.
Yes, that's the first thing I've checked but unfortunately that's not the case, and it would be very strange if it were, I'm using zsh as the default shell, and they don't share configuration files with bash; also, zsh is not installed by default in OS X.

I've also tried to execute \ls -l (usually the backslash escapes any alias defined and execute the original command) but I got the same result.

BTW, this behaviour happens independently of the shell used (at least is the same in both bash and zsh).
ruqui is offline   0 Reply With Quote
Old Feb 3, 2013, 08:35 AM   #12
switon
macrumors 6502a
 
Join Date: Sep 2012
RE: zsh...

Quote:
Originally Posted by ruqui View Post
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!
Hi ruqui,

I don't use zsh, but I do know that this alias of "ls" is possible not only in bash but also in csh and tcsh, so I suspect it must also be possible in zsh. It will take a different syntax most likely, however.

Good luck,
Switon
switon is offline   0 Reply With Quote
Old Feb 4, 2013, 03:07 PM   #13
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by ruqui View Post
This behaviour is "awkward" to say the least If 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 )
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.


Quote:
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.
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:
Code:
suenv command goes here
Where "command goes here" is the command to run. For example, try the 'id' command:
Code:
suenv id
chown33 is offline   1 Reply With Quote
Old Feb 4, 2013, 04:34 PM   #14
ruqui
Thread Starter
macrumors newbie
 
Join Date: Jan 2013
Quote:
Originally Posted by chown33 View Post
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.
Man, that's awesome! I really didn't know the source code is available! It could be a little work but I think is worth it

Obviously, I'm a little lost at the moment do you know where to begin? Where can I get the source code for ls?

Quote:
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:
Code:
suenv command goes here
Where "command goes here" is the command to run. For example, try the 'id' command:
Code:
suenv id
I'm not sure about this, isn't this equivalent to configure sudo to run without asking for password?
ruqui is offline   0 Reply With Quote
Old Feb 4, 2013, 08:59 PM   #15
dove
macrumors member
 
Join Date: Dec 2009
(Update: Okay, nevermind what I previously posted.)

Last edited by dove; Feb 4, 2013 at 09:07 PM.
dove is offline   0 Reply With Quote
Old Feb 4, 2013, 09:15 PM   #16
ruqui
Thread Starter
macrumors newbie
 
Join Date: Jan 2013
Quote:
Originally Posted by dove View Post
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.
ruqui is offline   0 Reply With Quote
Old Feb 4, 2013, 09:32 PM   #17
dove
macrumors member
 
Join Date: Dec 2009
Quote:
Originally Posted by ruqui View Post
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.
Yeah. Actually, 'sudo -i' was stupid advice because that will log you in as the root user. The effect I was going would be the one you get by running 'sudo sh'. E.g. mostly keep your env but change your privileges.

But as someone else pointed out, that doesn't work. In fact the ls manual has this to say:
-A List all entries except for . and ... Always set for the super-
user.
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.
dove is offline   0 Reply With Quote
Old Feb 4, 2013, 10:05 PM   #18
ruqui
Thread Starter
macrumors newbie
 
Join Date: Jan 2013
Quote:
Originally Posted by dove View Post
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).
ruqui is offline   0 Reply With Quote
Old Feb 5, 2013, 03:24 AM   #19
dove
macrumors member
 
Join Date: Dec 2009
Quote:
Originally Posted by ruqui View Post
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).
brew sounds good. I also found this: http://hocuspokus.net/2008/01/a-better-ls-for-mac-os-x/
dove is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > OS X

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Resolved: Hidden files spravtek OS X 10.8 Mountain Lion 9 May 1, 2014 06:18 PM
Overwritten(???) hidden folder Terminal. Help. DCWolfie OS X Mavericks (10.9) 5 Nov 15, 2013 04:59 PM
Hidden Games In Terminal! adam044 MacBook Pro 3 Feb 28, 2013 10:45 PM
hidden files on my HDD are to stay hidden forever???help falconb Mac Basics and Help 11 Oct 11, 2012 03:30 PM

Forum Jump

All times are GMT -5. The time now is 05:08 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC