Color ls output and permission denied
Categories: Information Technology, System Administration, UNIXIn my post from earlier this week on removing the color output from the ls command I mentioned that in some circumstances the color-coded output can cause permissions errors. Cloned Milkmen asked that I explain why this would be.
I was hoping someone would ask that. In Linux and UNIX if the execute flag is not set on a directory, as in the example below, the ls --color=tty command will return Permission denied.
$ ls -ld ls_test/
dr——– 4 jonemmons pg222211 4096 Nov 12 20:07 ls_test/
$ ls —-color=tty ls_test/
ls: ls_test/test1: Permission denied
ls: ls_test/test2: Permission denied
ls: ls_test/test3: Permission denied
dir1 dir2
$ ls ls_test/
dir1 dir2 test1 test2 test3
The execute flag is funny on directories. The main effect is that it will inhibit a user’s ability to cd into a directory, but it will also keep you from being able to get information out of the file’s inode (the inode contains information about when a file was created, modified, accessed etc.) Since ls requires information from the inode to properly color-code files in a directory it will fail if the execute bit is not set. An ls -l will fail for the same reason.
So thanks to Cloned Milkmen for asking the question. If you’re looking for some eclectic and distracting reading, check out his blog The Synthetic Librarian.


November 22nd, 2007 at 2:45 am
I don’t think the follwoing you wrote works:
ls –color=tty ls_test/I believe the correct construct is:
ls -–color=tty ls_test/
Furthermore, if you wanted to make an alias I’d suggest the following:
ls=’-hF-–color=tty’
November 28th, 2007 at 9:51 pm
Erich,
Thanks for pointing that out! I’m not sure why (and don’t have the time to figure it out right now) but WordPress interpreted my double-dash as a single-dash. The temporary fix was to add two more dashes and it displays sort-of right.
I would consider the -F option redundant to the color output, but actually prefer it if you’re looking for an indication of the file types.
Thanks for the comment.