Learning the Command Line – Listing Files

This is the second article in the command line series. The first article by vansmith can be found here: http://www.mac-forums.com/blog/learning-the-command-line-part-one/

This time we will be discussing file management commands. Some of these commands might look strange to you. That’s because most Terminal commands have the vowels and sometimes consonants removed to make the command shorter. For instance the copy command is cp with the o and y removed.

Obligatory warning: Please be careful when working on the command line. Most commands will not ask you “Are You Sure?” like a graphical application will. And, as you will see, some commands are irreversible, meaning if you delete a file it’s not coming back (you do have backups right?). So let’s get started.

If you downloaded the Virtual OS in the first lesson that’s great. Personally I’d rather work in OS X’s Terminal but whichever you feel comfortable with.

Our first command is the ls command. It’s quite simple , it just lists the files and directories in your home folder. Open Terminal and you will get a prompt similar to this:


Obvously <yourusername> is your login name. <yourcomputername> would be whatever your computer’s name is. And the :~ is where you are, in this case your home folder (dir). All of this can be changed and we’ll get to that in another lesson.

Now type:


That is a lowercase L. You should get something like this:


Yours may or may not be in color. In this case the directories are blue. That green one is an alias. Some commands have options, or switches. ls has several but right now we’re only concerned with two or three of them. Try this, type

ls -l


What is all this stuff? The -l switch will give you a single column list showing permissions, owners, groups, file sizes etc. Much more information than the plain ls command. But that’s not all. Something’s missing. Type this:

ls -la

See all those file names beginning with a dot? Those are hidden files and directories not normally seen by users.


Now lets add another switch. Type

ls -laF

This switch will list directories with a slash after them, executable files with an asterisk, and an @ after each symbolic link (sort of like an alias).


To get a list of all the switches for the ls command type ‘man ls’ without the quotes in Terminal. This will give the ‘manual’ for the command. Pressing the space bar will page down (or push the up and down arrows) and pressing q will exit the manual. If there is a way to page up I haven’t found it yet. If you want a possibly easier way to read man pages there is an application called ManOpen which is a graphical interface for the man pages with a scrollable window which you can put alongside Terminal if you want.

In the next lesson we will learn about the filesystem of OS X and why you shouldn’t move or change certain files and directories.