What’s a directory? →
What’s a folder? →
What’s a pathname? →
Each operating system organizes their files and directories differently. OSX’s file structure looks like this (it’s similar to other UNIX based file systems):
It’s worth noting the directories nested under Users. They should seem familiar to you.
A pathname is the general form of the name of a file or directory; it specifies a unique location in a file system.
A path separator is a character that’s used to join together each directory in a pathname that contains nested directories (for example, Desktop was located under Users and username… there was a character that separated each directory).
What character represents the path separator on OSX (we just saw this)? →
We’ll look at this a little bit more in the next class.
There are shortcuts to represent specific paths:
The following paths are relative to the directory that you’re in:
List all of the files (and directories) in the current directory. →
Think: list (we just saw this!).
$ ls
Applications Documents ....
List all of the files (and directories) in the directory specified by the pathname. →
$ ls Desktop
cuny-first.png fractal mountains
The -l flag gives detailed output about each file in the directory →
Think: l for long version.
$ ls -l
drwx------ 3 bree staff 102 Nov 1 15:08 Applications
drwx------+ 7 bree staff 238 Jan 28 22:46 Desktop
The -a flag lists all files, including hidden ones →
Think: a for all.
$ ls -a
. .config Dropbox
You can combine flags by placing them one after the other. This outputs a detailed list of all files. →
$ ls -al
drwxr-xr-x+ 67 bree staff 2278 Jan 30 02:07 .
drwxr-xr-x 5 root admin 170 Aug 13 2011 ..
-rw-r--r--@ 1 bree staff 24580 Jan 30 02:19 .DS_Store
-rw-r--r-- 1 bree staff 3459 Mar 21 2011 .RData
The -t flag sorts by time. →
$ ls -lt
total 0
drwxr-xr-x 2 bree staff 68 Jan 30 02:07 mtec1003
drwx------@ 19 bree staff 646 Jan 29 21:21 Dropbox
drwxr-xr-x 9 bree staff 306 Jan 29 19:31 projects
You can use multiple flags… and combine them with an argument as well. What do you think this does? →
$ ls -alt Desktop
It lists all of the files in Desktop (if you’re in your home folder), ordered by time, including hidden files and showing extra information.
drwxr-xr-x+ 40 bree staff 1360 Jan 29 01:12 ..
-rw-r--r--@ 1 bree staff 6148 Jan 25 01:46 .DS_Store
drwx------+ 6 bree staff 204 Jan 24 08:26 .
-rw-r--r--@ 1 bree staff 245447 Jan 23 23:15 cuny-first.png
drwxr-xr-x 16 bree staff 544 Oct 28 18:46 fractal mountains
-rw-r--r-- 1 bree staff 0 Aug 31 22:41 .localized
Shows the directory that you’re currently in. →
Think: print working directory.
$ pwd
/Users/bree
Prints out the name of your computer →
$ hostname
walsh-9
Creates a directory with the name of the argument supplied. →
Think: make directory
One argument is required: the name of the directory to create.
$ mkdir my_animated_gifs
This attempts to create 3 directories nested within eachother. →
Forward slash (/) shows that a directory is within the directory preceding it. dir1/dir2 means dir2 in dir1.
However, nested directories don’t work as an argument for mkdir. (Unless…)
$ mkdir dir1/dir2
mkdir: dir1: No such file or directory
The -p flag allows you to create multiple directories nested within eachother. →
mkdir -p dir1/dir2
$ ls
dir1
$ ls dir1
dir2
Changes current directory to the directory specified in the argument. →
Think: change directory
One argument is required: the name of the directory to change to.
$ cd Desktop
$ pwd
/Users/bree/Desktop
Let’s use special paths with cd →
$ pwd
/Users/bree
$ cd ../
$ pwd
/Users
$ ls
Shared bree
$ cd ~
$ pwd
/Users/bree
$ cd /
$ pwd
/
Pass - (dash) as an argument to cd to go back to the directory you just changed from. →
$ pwd
/Users/bree
$ cd /tmp
$ pwd
/tmp
$ cd -
/Users/bree
Removes a directory with the name of the argument supplied. →
Think: remove directory
One argument is required: the name of the directory to remove.
$ mkdir foo
$ ls
foo
$ rmdir foo
$ ls
Change to directory, but save current one for later. →
$ pwd
/Volumes
$ pushd ~/Desktop/
~/Desktop /Volumes
$ pushd /Applications/
/Applications ~/Desktop /Volumes
$ popd
~/Desktop /Volumes
$ pwd
/Users/bree/Desktop
$ popd
/Volumes
Entering commands flash cards x 10 (use set 2)
We’ll do this together, then try downloading it yourself:
Entering commands flash cards x 10 (use set 12)
We’ll do this together, then try downloading it yourself: