K509 • Week 1

Getting around UNIX file systems, directories, word processing, simple UNIX commands. FTP'ing.

1. If you don't already have a personal web page from IU (mypages) and a corresponding UNIX acount on Steel, create one so you can try out the following items (see http://kb.iu.edu/data/cafu.html). In general, you can get an incredible amount of computing information from the UITS Knowledge Base. For a very basic UNIX online tutorial, check out http://www.ee.surrey.ac.uk/Teaching/Unix/unix1.html.

2. Standard Unix file structure (/usr/local/bin), special 'dot' files (.login, .profile, .cshrc, .tcshrc).

3. Understanding ownershipt and permissions (see chmod and chown below).

4. Frequently used UNIX Commands (see UNIX for Musicians Web Page and refer to Teach Yourself UNIX Book in cabinet). Open UNIX terminal shell on Steel with Mac Terminal program (ssh steel.ucs.indiana.edu) or Telnet SSH login:

flags are optional additions to UNIX commands; for example, ls will give you a simple file listing, but ls -l will give you a long listing. Commands may have many flags, which follow the command by a space and dash, but then have no space between flags, so ls -la will give both a long listing plus list hidden files. Flags are case-sensitive and an upper-case flag may act differently than a lower case one of the same letter.

Before you begin, particularly on our Mac acccount, please realize that unlike the forgiving interfaces of Mac OS or Windows or your teacher, many UNIX commands can wipe out files, directories, even entire accounts without a warning or an 'undo.' Beware of rm, cp, mv--on the studio Mac, we have aliased these to be a little more safe (you get one chance to save your soul), but that may not be the case on other systems or your home Mac.

pico filname -will create new or open existing text files in Pico editor--looks just like Shakespeare email editor (hardcore UNIX users prefer vi or EMACS). If creating a new file, it will be given the name of filename.

NOTE: UNIX filenames must not have any spaces (you can use underline to separate words, such as my_dreary_music.aif). In Mac OS X, ou may need to refer to a file with a space in it--to do so, precede the space with a '\', for example my\ stuff or enclose it in single quotes 'my stuff.'

. - current directory

.. - parent directory (directory one level up from where you are), so you can move to a parallel directory by cd ../new-directory

~ - your home directory (cd ~ will take you home)

/ - root directory (cd / will take you to the top of the system file structure)

* - wildcard symbol used for filenames (*.* means all files, *.snd means all files with the snd extension--ls *.snd will list only your .snd files)

cd - change directory

pwd - list current directory

ls - list files in current directory (ls -l =long list, ls -a=list all files). ls /usr/local/bin will list contents of remote directory without moving to it. If you alias ls as 'ls -CF' as I do in my .login or .bashrc file, the files will be listed in columns (-C) and the directories will be followed by a slash (-F). Also, in the listing, files which are executable are followed by an '*.'

cp file1 file2 - copy file1 to file2. Can also relocate; for example, cp myfile ../csound/myfile2 moves to another directory.

mv file1 file2 - move file1 to file2 -- think of this as renaming a file as well as potentially relocating it; for example, mv hiphop.good ~/trashy/hiphop.bad

rm filenames - permanently remove filenames (careful!) rm -i will ask about each specified file before deleting--rm *.* will remove all files with extensions from a directory. rm -r (recursively) will remove all files and subdirectories--this is the mother of all deletions--use very, very carefully! You should alias rm as rm -i in your .login file

mkdir directoryname - make new subdirectory in the current working directory

rmdir directoryname - remove (empty) directory from current working directory. You must empty directory before removing it.

find topdirectory -name filename. Searches directories recursively (starting at top directory and searching through all subdirectories) for filename. You can also use wildcard in single quotes; ex. find ~/bad_music -name '*.snd' would find and printout all files in the bad_music directory and its subdirectories with the .snd extension. Find usually prints the file names by default, but you can also specify another action; find ~/bad_music -name '*.snd' -ok rm {} \; will find all .snd files as before, but then ask if it is ok to delete them one by one--a {} space semicolon and backslash are required. This is handy for cleaning up your file systems.

cat file1 (file2...) - lists contents of files, one after another. Best to use only with text files unless you like reading lots of garbage characters.

> redirect output, as in ls -l > my_file_list.txt will create a new file of the filenames in your directory (it won't contain itself--ha, ha). To combine more than one file, use cat with multiple file names plus > to append one file after the other.

man term - provides help for UNIX term (usually more than you want). Examples are usually at bottom of page. By default, man uses less to page, so to learn how to page forward, backwards by x number of lines or pages, type an 'h' while you are on a man page or getting help for less to see all of the commands.

| - pipe. | less (pipe info to less) - use with ls or cat when you want info one page at a time, such as cat file1 | less (though you could just type less filename). Use spacebar for next page. ls -l | tee savedir will create a file called 'savedir' with the output of your file list--use man to see the tee command.

less filename - use to output longer file one screenfull at a time. Can replace cat. Spacebar will advance file one page, 'b' will backup one page, 'q' will quit. Less is more powerful than the similar more (go figure). Type 'h' to get all the direction commands while you are in the middle of a file.

alias [old command] [new command], such as alias ls 'ls -la' will cause an ls command to give you a long list of all files--a good alias to put in your .login or .tcshrc or .cshrc file is alias rm 'rm -i'. Put any commands with flags inside single quotes. Always make a backup of any '.' file before making changes (cp .login login.bak).

ln -s sourcefile newlink (or sourcedirectory newdirectory) creates a symbolic link pointing to a file (same as Mac aliases). The -s (symbolic) allows links across file systems.

ps -e list all processes so that you can...

kill [process # from ps]. kill -9 [process #] is a more intense form. Stops or quits processes that have hung...last resort for quitting.

chmod [###] filename changes file permissions for user-group-others to a combination of read (r), write (w) and execute (x). Can be octal or symbolic (see man page), but easiest is octal (4-read, 2-write, 1-execute) where you add up the numbers for user-group-others. Ex. chmod 744 myfile makes myfile rwx to owner, r only to group and others. Directories also have similar permissions and an x on a directory means it will be searchable. OR you can change a permissions one at a time; chmod u+x filename adds execute (x) to the user.

chown owner filename changes the user ID and/or the group ID of the specified files. Use man to read about changing groups.

grep search_term file_name will search for a particular word in a text file and output the line it is found in. Wildcards are ok, so if you have a lot of time on your hands, you can search the entire computer for a particular word.

touch filename changes file access and modification times, but also will create a new file without content if filename does not exist.

df [dir] - displays number of free disk blocks (~1k) and files under dir. df -k ~ prints out in kilobytes starting at your home directory.

du -k shows the size in kilobytes of all your directories. du -k [dir_name] shows the size of directories and subdirectories below dir_name.

DELETE key or ctl-c should stop a program from executing, ctl-s stops or suspends output, ctl-q resumes output. Control key for Terminal on Mac is 'option' key.

To suspend a job, type ctl-z and then fg (foreground) to resume. If you try to log out properly without resuming, you may not be able to--use ps and kill to end stopped jobs that you can't access again.

!! - repeat last command line. !2 - repeat 2nd to last command, etc.. !'#' - repeat command '#', where '#' is the command number gotten by typing history.

logout - proper way to end session so processes don't continue indefinitely, even while you sleep (bye also works for ftp sessions).

Additional interesting commands to look at (via man pages) once you get the hang of the commands above are: awk for pattern scanning on mulitple files, tee, tar (tape archive used for compression), uncompress and zcat (for uncompressing standard UNIX files that have been 'tar'ed and 'Z'ed, rlogin for remote login to another machine without leaving shell, ssh to check your mail from a shell. See UNIX for Musicians page for ftp'ing to and from remote machines and servers from a shell.

5. Reading long (ls -l) UNIX directory listings:

total 17 --size in blocks (on most systems, blocks are 1024 bytes, or close to 1k)

drwxr-xr-x 7 hassj 112 Aug 29 10:15 K509_grades

--the d indicates this is a directory followed by permissions (see above),

--followed by the number of links to the file or directory. hassj is the

--owner. 112 is the file length in bytes, followed by the last date and time

--of modification and finally the file name.

-rw-r--r-- 1 hassj 13312 Jul 30 22:04 k509_index.htm --a regular file (no d) of 13,312 bytes

Assignment 1 (due Tuesday): -Print out UNIX for Musicians web page and examine commands not listed above.
-Create a UNIX account on Steel with personal web page utility if you don't already have one.
Do not practice any of the following on your '.' files or login directory until you are comfortable with commands and then only after backing them up! Don't experiment with permissions on your login directory!
-On Steel, use Pico to create several files including one called Dr_Hass_is_cool.txt. and try out the various commands, including cat (and cat *.txt) and ls. (with ls -l, see if you can figure out all the file information you are getting) The Pico Write Out command = save. Exiting without writing out does not save.
-Create a new directory called K509_week1 using mkdir and mv or cp one of your files to it. Practice navaigating using cd and pwd. Move files into these new directories.
-create several text files and try out grep
-once you are getting the hang of it, in your steel account, cp your '.profile' to 'profile.bak'. Now using pico alias cp to cp -i, rm to rm -i, mv to mv -i
-use chmod to change permissions of these files to rwxr--r-- using the octal numbers, Then add write permission for the group using the g+w method.
-Either in the library or in the studio, open a terminal on a Mac running OS X and see if you can perform similar UNIX functions. I'd practive on the library computers first!
-Be prepared to show me the files in your Steel directories on Tuesday, par5ticularly Dr_Hass_is_cool.txt.