Unix Navigation Commands
Here is an overview of commands [ Unix ] for navigating around the filesystem.
You use commands from the terminal app.
Macintosh-HD -> Applications -> Utilities -> Terminal
Why the terminal is so cryptic? Here is a picture of an early terminal. It was a piece of hardware not an app.
The terminal is designed for little fuss and maximum power. Be careful. Please have a full backup of your system before using terminal commands. The only mildly dangerous command that I mention is the mv command. Avoid it to reduce your risk.
Check all commands twice to avoid mistyping.
In all cases, you type the command after the prompt. Generally, prompts end with a $. You press the return key to run the command. You must use the larger delete key to backup and delete the prior character. The use of the mouse inside the terminal window acts a little different. You may copy from anywhere as before, but paste will always paste to where the terminal cursor is. The terminal existed before the mouse was invented!
"mac $" is my terminal prompt. Your prompt will be different.
What is my short user name?
Type the whoami command. Then press the return key. The terminal types out the answer. In my case, my single user name is "mac". Yours will be different.
mac $ whoami
mac
mac $
How to list all of your disk names.
The ls command is for list.
mac $ ls /Volumes/
Audio CD Macintosh-HD Spotless Tiger-ext mac $
Let's say your flash drive is named Spotless
cd -- Change directory
# cd is change directory
# for historical reasons, folders are called directories when using terminal commands.
# so, you end up with the command cd.
mac $ cd /Volumes/Spotless
pwd -- print working directory
# pwd is Print Working Directory. A directory is the Unix name for a folder. You always have a default directory.
# You use the pwd command to see what it is.
mac $ pwd
/Volumes/Spotless
mac $
ls -- list files
# The ls command is for list. The letter l is a lower case L.
# l is long
# F is type of file where / is directory. For directories, the slash is pasted to the end of the name.
mac $ ls -lF
total 134704
-rw-r--r-- 1 mac staff 64560 Mar 3 2009 A-picture-of-Youpi-key.png
drwxr-xr-x 83 mac staff 2822 Nov 7 14:52 Applescript files/
drwxrwxrwx 12 mac staff 408 Dec 13 2008 Christmas Cards/
drwxr-xr-x 9 mac staff 306 Dec 21 17:39 Christmas Cards 2009/
... trimmed ...
What does all this mean?
# l is long
# F is print what kind of file is listed.
# a is all to show hidden files & directories.
mac $ ls -lFa
total 134736
drwxr-xr-x 41 mac staff 1496 Dec 22 17:11 .
drwxrwxrwt 8 root admin 272 Dec 24 13:55 ..
-rwxrwxrwx 1 mac staff 15364 Dec 23 12:52 .DS_Store*
drwx------ 4 mac staff 136 Jan 22 2009 .Spotlight-V100
drwxrwxrwt 5 mac staff 170 Sep 14 16:36 .TemporaryItems
d-wx-wx-wx 4 mac staff 136 Dec 31 1969 .Trashes
-rw-r--r-- 1 mac staff 64560 Mar 3 2009 A-picture-of-Youpi-key.png
drwxr-xr-x 83 mac staff 2822 Nov 7 14:52 Applescript files
drwxrwxrwx 12 mac staff 408 Dec 13 2008 Christmas Cards
drwxr-xr-x 9 mac staff 306 Dec 21 17:39 Christmas Cards 2009
... trimmed ...
d = directory
Next is a triplet of permissions for the owner, group and other.
r = read
w = write
x = executeable program
- = you do not have this permission
drwxrwxrwx
↑↑ ↑ ↑
|| | other -- all other users not in first two types
|| |
|| group
||
|owner
|
What type of entry is this? d = directory, - = file, etc.
Every Unix resource: files, folders, etc has an owner, group, other permission.
• Unix resource has one owner.
• Unix resource has one group. A group contains a list of users.
To gain access to a file, you can be the owner, in the group, or not the owner and not in the group hence you end up as other. The owner, group, or other has read, write, or execute permissions.
mv -- Move
# mv is move or rename
# The mv command can be dangerous. It lets you destroy an existing file.
# Always use the -i option to avoid issues. Be sure to take your time.
# -i for interactive which prompts you before overwriting an existing file
mv -i the-name the-new-name
# You can just rename the file back to what it was with mv command.
mv -i old-name new-name
Here is what these commands mean:
cd is change directory
pwd is a print working directory
ls is list
sudo is Super user do
mv is move or rename
man -- manual
For cryptic comments, you can always uses the manual command which is man. For example:
man mv
Type the letter q to quit the man command.
You sometimes see the tilde ~ in Unix commands. It means your home directory.
mac $ pwd /Users/mac/Downloads mac $ cd ~ /Users/mac mac $ pwd /Users/mac mac $
In case you have spaces in your filenames or directories, you need to escape them. Use quotes around the name or a backslash before each space.
mac $ ls -l ~/"see it"
-rw-r--r-- 1 mac staff 3171 Oct 26 23:38 /Users/mac/see it
mac $ cd /Users/mac/Desktop/ttt\ html\ copy/
command line features
Do you know about tabbing? Type in a few letters of a file or directory name then press the tab key. The computer will type out the rest of the name if it is unique.
Press the up arrow key to see the previous command(s).
To edit a command, use the left arrow key to more left and the right arrow key to move right. Use the delete key to delete the key to the left. Type a letter to insert.
history -- print previous commands
history to see many previous commands.
mac $ history
1 pwd
2 man ls
3 history
You may copy then paste from this list.
Robert
PS. fyi: The commands also work in Single User Mode.
Start up your Mac in single-user mode or verbose mode - Apple Support