Things You'll Need:
- A Mac running MacOS X
-
Step 1
The command promptLaunch Terminal. This application gives you access to the command line interface of your Mac. You can find Terminal at the following path /Applications/Utilities/
When you start Terminal you're going to see a command prompt, which is typically a small rectangle. To the left of the command prompt is your username and then the name of your computer.
The example screen shot shows a computer named 'test' and username 'ehow', like this:
test:~ ehow$
Working on the command line normally happens in these steps:
-You type a command and then hit return
-The Terminal responds with a response
-The command prompt returns after the process finishes, waiting for another command -
Step 2
Result of running 'ls -l' on the command lineAll commands that you enter below should be followed by hitting the return key.
Enter this command:
ls -l -
Step 3
When you start Terminal your current working directory will be your 'Home' folder. After running the 'ls -l' command you will see lines of text similar to these:
drwx------ 3 ehow ehow 102 Nov 28 12:42 Desktop
drwx------ 3 ehow ehow 102 Nov 28 12:42 Documents
drwx------ 17 ehow ehow 578 Nov 28 12:42 Library
drwx------ 3 ehow ehow 102 Nov 28 12:42 Movies
drwx------ 3 ehow ehow 102 Nov 28 12:42 Music
drwx------ 4 ehow ehow 136 Nov 28 12:42 Pictures
drwxr-xr-x 4 ehow ehow 136 Nov 28 12:42 Public
drwxr-xr-x 6 ehow ehow 204 Nov 28 12:42 Sites
Open up your 'Home' directory in the finder. Notice that the names of these entries, like Documents, Music, Movies, etc., match the result of running 'ls -l' on your system.
If you've modified your 'Home' directory then the result will be different than what you see here since you may have more (or less) folders or even files.
Let's look at the first entry
drwx------ 3 ehow ehow 102 Nov 28 12:42 Desktop
The last word in the line tells you the name of this resource, which is 'Desktop' in this case. 'Desktop' is the desktop area for your user account that you see when you first turn on your computer where you see your hard drive(s). Any files that are on your desktop will also be contained within this folder.
The first section of the line details the permissions of the 'Desktop' folder. For now, we're just concerned with the first letter of this section. A 'd' means that that the entry is a directory (folder). A dash means that the entry is a file.
'ehow' is listed next and twice because it represents the user and group who 'own' that folder; however, you will see your own username instead of 'ehow'.
The date and time represent the last time that the file or folder (and any file or folder contained within that folder) were changed. -
Step 4
To navigate on the command line use the 'cd' command. This allows you to change your current working directory. Now, change to the 'Desktop' folder by typing the following command:
cd Desktop
The only response you will get is that your command prompt will change to reflect your new location:
test:~/Desktop ehow$
To confirm that you're actually in the 'Desktop' folder, run this command again:
ls -l
If you have any files on the desktop of your Mac you will see them listed here.
To go back to the previous directory, run this command
cd ..
That command will always take you back one directory. So if you're in the '/Users/ehow/Desktop' folder and you run 'cd ..' that will take you back a directory to '/Users/ehow/'.
Now let's go to the default document root and see what's in that directory. Run this command,
cd /Library/WebServer/Documents/
And then run
ls -l
You should see a bunch of default files such as index.html. What is important to note is that you can 'cd' to nested folders, not just one at a time. -
Step 5
Result of running 'pwd' on the command lineA good way to confirm your current location is by running this command
pwd
That will print your current working directory, which in this case should be /Library/WebServer/Documents/. In order to get back to your home directory without typing the full path (which would be '/Users/ehow/'), run this command
cd ~
That is cd, a space and a tilde. To type a tilde, hold down the shift key and hit the key to the left of the '1' key.
This shortcut switches your current working directory to your 'Home' folder.
Now, let's go back to /Library/WebServer/Documents/ the easy, less typing way. Type the following but don't hit return this time.
cd /Li
Immediately after typing 'i' hit the tab key and the Terminal will complete the path for you.
This shortcut completes the name of known, existing folders for you. After 'cd /Library/' start typing 'We' and then hit tab and you'll end up with cd /Library/WebServer'. If you don't type the path name with the correct case this shortcut will not work. Also, if there are paths with similar names then 'Tab Completion' may not know which path to complete so you will need to type additional letters before hitting tab. Complete the path by typing 'Do' and then the tab again. You should end up with this:
cd /Library/WebServer/Documents/
Hit enter and you've now changed directories with much less work. If you end up working on the command line a lot this simple trick will become very helpful.
Now, run this command to clean the Terminal up a bit
clear
This time, instead of typing a command, hit the up arrow on your keyboard and you should see your prompt replaced with the word 'clear' that we just ran. Hit the up arrow again and you should now see command you ran before 'clear.' The up and down arrows allow you to scroll through the history of commands you've already entered. This is helpful when you're moving back and forth between long paths or running the same, complex commands.
Please comment and rate this article. Thanks!












Comments
brionlg said
on 9/3/2009 THANK YOU !!! This was Awesome !!
More please.
enebekee said
on 1/28/2008 This actually assisted me. Am new to Mac and needs training. thanks
Mike