Filed under: UNIX / BSD, Terminal Tips
Monday man page: ls
There are two kinds of Mac folk: them that finds this "Terminal" thing strangely fascinating, and them what considers it the worst kind of wicked magic, not to be trifled with. Here at TUAW we've got all kinds, and for anyone who might be curious about the power and possibilities of the command line, we're going to provide some weekly quick tips and suggestions for introductory use. Always keep in mind, though, that the damage you can do from Terminal is effectively unlimited, especially with administrative access. Best to play around in a 'dummy' account until you have your sea legs.Even before we start, an explanation of the title: 'man pages' are the BSD UNIX manuals, already tucked away on your Mac. You can type "man command" in Terminal for a detailed (not to say overwhelming) rundown on any command-line tool. As we've mentioned before, an excellent intro to Terminal in Tiger can be found over at the O'Reilly Mac Dev Center. We also posted about Unix for the Beginning Mage, an amusing beginner's guide to the plumbing under Mac OS X.
Our fine feathered friend today is 'ls' -- the UNIX directory list command. Read on for more...
Last login: Mon Dec 18 00:02:44 on ttyp1"Cool beans," you say, "but can't I do that from the Finder?" Yes; but with some options, 'ls' can:
Welcome to Darwin!
MTR-iMac-242:~ miker$ ls ~/Desktop
Desktop 20060904 MacHeist ?? Bundle Receipt.pdf
Desktop 20061217 TuneTalk.JPG
- list ALL the files in a directory: 'ls -a ~/Desktop' -- great for finding mystery files; C.K. posted about this a while back
- give a detailed readout including permissions: 'ls -l' -- or combine with above for all the invisibles and all the permissions: 'ls -la'
- see the otherwise-hard-to-find ACLs for a directory or file: 'ls -e'
- sort the file list by modification date, most recent first: 'ls -t'

![TUAW [Cafepress]](http://www.blogsmithmedia.com/www.tuaw.com/media/tuaw-cafepress-promo.png)


Reader Comments (Page 1 of 1)
Lowell said 10:29AM on 12-18-2006
Another useful switch is '-F' (capitalization important) which adds a slash ('/') after anything that's a directory and an asterisk ('*') after anything that is a binary executable. (Also has symbols for symbolic links ('@'), sockets ('='), whiteouts ('%'), and FIFOs ('|')).
I generally use this in combination with the -a and -l switches to get the most useful information: "ls -laF"
Reply
mauve said 10:35AM on 12-18-2006
You're not a Russell Brand fan by any chance, are you Michael?
Reply
Jason said 10:36AM on 12-18-2006
Wow, as a switcher from both windows and a linux server, I feel left out by that first sentence :)
Reply
stainboy said 10:36AM on 12-18-2006
i'm now using the free Bwana to view my man pages in Safari:
http://www.bruji.com/bwana/index.html
great tool!
Reply
fanguad said 10:43AM on 12-18-2006
Then there are those of us who didn't consider OS9 a real OS because it didn't have a command-line, and only bought a Mac because of OSX's BSD core.
On the subject of ls, I personally use GNU ls, which has slightly different options. "ls --color=auto" is my personal favorite, and what "ls" is aliased to on all my systems (dunno what the BSD equivalent is).
Reply
nate said 10:46AM on 12-18-2006
you may want to mention that if you do 'man ', you need to hit 'q' to get out of the man pages
Reply
Michael Rose said 11:07AM on 12-18-2006
Thanks for the great feedback everyone.
Russell Brand -- had never heard of him before now. Sounds like a funny guy. What seemed reminiscent of him?
Windows/Linux switchers -- sorry to make you feel excluded, although I imagine you fall in the 'fascinated' category. Or perhaps the 'yeah, a CLI, BFD' category.
q or ctrl-c to exit 'man' -- good point.
Bwana -- I love Bwana, and it was actually revved to v2.1 this week. It may merit a standalone post.
Reply
Michael Rose said 11:07AM on 12-18-2006
Let me know your suggestions for what next week's Xmas Monday man page should be: choices are
cp/ditto
whereis
dig
cal
Reply
Mark Studdock said 11:32AM on 12-18-2006
wow, this is sad - just stop wasting your time
Reply
narco said 11:50AM on 12-18-2006
I had my first brush with Terminal yesterday when I tried to delete a 20GB text file that would Kernel Panic every time I tried to delete it. I had lots of help, of course.
Long story short, the hard drive won't boot up. That's the end of my Terminal days.
Fishes,
narco.
Reply
ryan said 11:54AM on 12-18-2006
What about the mac folk that has at least a dozen terminal windows open at a time, and spends his 8 hour work day there?
Reply
ryan said 11:54AM on 12-18-2006
""ls --color=auto" is my personal favorite, and what "ls" is aliased to on all my systems (dunno what the BSD equivalent is)."
ls -G
Reply
Craig McCreath said 12:00PM on 12-18-2006
Well if there's a coincidence like none other this would be it. After having to repair a busted iMac G5 today (wouldn't boot) I scoured the internet searching for this very command! How odd!
Seriously, tuaw, stop reading my mind. First, an Apple Store in Scotland - now this!
Reply
Clair said 12:01PM on 12-18-2006
The BSD backbone is one of the reasons I moved back to an Apple computer after almost 20 years. I do not go a day without accessing the command line.
Reply
Michael Rose said 12:06PM on 12-18-2006
Narco: sorry to hear it. Most likely there was something else wonky on your machine...
Ryan: I'd put you in the 'fascinated' category, or possibly the 'jaded' category.
Reply
ryan said 12:08PM on 12-18-2006
little more fitting to what ls --color=auto does (for bash users...
in your ~/.bash_profile
if [ "$TERM" == "xterm-color" ]; then
alias ls='ls -G'
fi
wow, three comments in one story. I really need to gather my thoughts a little better prior to posting :-)
Reply
Jason said 10:38PM on 12-18-2006
Michael:
It'd be cool for you to do one on dig next. If more people know about it and nslookup (actually what I usually use), I can pretend there are more people who will want to learn more about DNS in general and troubleshoot their own issues :)
Reply
linkbeat said 1:01AM on 12-19-2006
Ahhh yes, "ls -alh --color=auto" is what I aliased ls to be on my old linux systems. I tried that on the mac (recent switcher) and obviously was disappointed. I didn't even think about researching the BSD equivalent. Thanks for the -G info.
I vote for a detailed review on the "Dig" command. That thing can be powerful in scripting.
Reply
Mike Rose said 8:05AM on 12-19-2006
Suggestions noted: next week, a special Xmas Monday man page on dig, host and nslookup.
Reply