Folders and Directories

Handling Files and Folders is one of the main operations of the Finder on the Mac. The shell can be used as well. Both shell and Finder operate on the same set of Files on your Disk. Let's have a look at that:

Open the Terminal, which will get you a shell on your local machine.

Type:
pwd

You will see something like this
/Users/andreas

pwd is a unix command. It does print the working directory. Unix names are short. Maybe unusually short by todays standards. Everybody could create longer ones. It's easy, but nobody does it. pwd has no command line options. What is called a 'folder' in the Finder is called a directory in Unix (and I believe in windows as well). It's the very same thing.

But what would a 'working directory' be? Imagine your would only have ONE window in the finder. You Navigate around in this one window. That's what a working directory is. Soon we will see how you can move or copy a file with this concept. When you start a new shell/Terimnal window then you always start in the same directory, which is also called your home directory. In the Finder there is a House as a symbol for this directory:



Again: shell and Finder see the same thing. In the Finder you see what is in a Folder. How does the shell the same thing in a directory? The most commonly used unix command does that for you:
ls

will display something like this:
Desktop
Documents
Library
Movies
Music
Pictures
Public
Sites
What exactly you see depends which files and directories you have. What you see here is what OS X creates for every new user. In the Finder you can easily tell files and directories apart. In the shell you need to tell the ls command that you care about this:
ls -p
Desktop/
Documents/
Library/
Movies/
Music/
Pictures/
Public/
Sites/

With the -p option you instruct the ls command to append a '/' in the end of a name if it is a directory. ls command is actually a program that somebody wrote to list files and directories. On a unix system it can be assumed that this program is included. But it's an independent software. The shell just got the text from us and gave it to the ls command. It is up to the command to read and understand the -p option. What these parameters and options do does depend entirely on the program that is the first word in the line you enter. That is the reason why there are only few standards. But it is also the reason why unix still exists: Having many small and independent building blocks allowed for a very open and efficient development. And later we will see how much can be done with the combination of small commands ...

Let's continue with our exploration of directories



feedback