K509 — Computer Music Seminar: Assignment 1
Unix is a family of general-purpose computer operating systems derived from work at AT&T’s Bell Labs in 1969. (Bell Labs was also a hotbed of early computer music research, by the way.) By “Unix command line,” we really mean a program called “the shell” that lets you type in commands that control programs, edit text, manipulate files, etc., and see the results in textual form. There are many examples of shell programs: the Bourne shell (sh), the C shell (csh), the Korn shell (ksh), the Bourne-again shell (bash). Bash is the one used most frequently now and is the default in OS X (which is partly derived from BSD Unix).
Once you get the hang of working in the shell, it can be a very efficient way to work. The disadvantage is that it will strike most people as unintuitive. But it builds character!
Follow the steps given below for an introduction to the command line. You can do this on the studio Mac or any of the iMacs in the library. Although the commands below would work on any Unix system (a Linux box, the IU mercury webserver, etc.), those won’t have the TextWrangler program installed. If you want to do this on your own Mac, install the free TextWrangler program, which you can get here.
If everything is set up correctly, you’ll see a mostly-blank window with a line that begins with “Last login:” and a brief line of text ending in ‘$’. This line is the command prompt, and is where you type commands to be interpreted by the shell. The commands let you manage files (move, copy, delete, rename), run RTcmix scripts, and a million other things we won’t bother with.
/Users/johgibso
This is a full path name. It lists, from left to right, the
hierarchy of folders leading to the last element, which can be either
a folder or a file. Each element of the path is separated by a slash,
and the root, or highest level, of the hierarchy is represented
by a single slash on the far left side.
cd Documents
followed by the ls command again. You’ll see a list of
files in your Documents folder. If you get an error message like
“command not found” after giving the cd command,
make sure you type a space between “cd” and
“Documents.”
/Users/johgibso/Documents
cd ..
(That’s two periods with no space between them.)
“..” is another name for the parent directory, one level up in the hierarchy: in this case, you change back up to your home directory.
mkdir sco
cd sco
ls
touch dummy (create an empty file called "dummy")
ls
mv dummy bogus (rename the file to "bogus")
rm bogus (remove -- i.e., delete -- the file)
If that last one asks whether you really want to delete the file,
type a lower-case ‘y’ and press return. If it doesn’t
ask, say goodbye to your file. It’s not in the Trash, it’s
gone forever.
More commands...
cd
edit blah
cd without a directory name means to change to your home directory.
The edit command opens a new file, named “blah,” in
the TextWrangler text-editing program.
Type some random stuff into the TextWrangler window, and save the file. Then return to your shell window in the Terminal program. (Type command-tab to get there without using the mouse.) Give these commands:
ls (you'll see the "blah" file among those listed)
cat blah (dump your text file to the screen)
clear (clear the screen)
mv blah Documents
This moves the “blah” file into the Documents folder.
(Note how similar this is to using mv to rename a file, as we did
earlier. The difference in that case was that the second name was a file
name, rather than a directory name.)
cd Documents
cp blah blather (copy the "blah" file into a new file, "blather")
mv blather .. (move "blather" to parent directory)
cd .. (change working directory to parent)
rm blather Documents/blah
You can remove multiple files with one rm command.
“Documents/blah” is an example of a relative path name:
you construct a path that is relative to your current location in the
file system. You could’ve typed this (substituting your user name
for mine) with the same result:
rm /Users/johgibso/blather /Users/johgibso/Documents/blah
You can see why having really long file names, or file names with
embedded spaces or weird characters, would make life difficult for the
shell user. You have to put quotation marks around filenames that
the shell has trouble understanding.
cd Do<tab>
You’ll see the name expand to “Documents,” as long as
you don’t have any other file names in the working directory that
start with “Do.”
Two of the commands I use most often are grep, which lets you search through many text files for a word or phrase, and diff, which lets you compare two text files. See if you can figure out how to use those.
If you want even more info about this command-line business, see: