This is a very short tutorial on Unix. Enough to to the CIS 456 projects. Unix is ``directory oriented''. You always are in some diretory. When you log on, you start in your home directory. In the afs system in NJIT, your directory is the same, whichever afs computer you are logged on to. Typically, you see a line like: maan-229 ott>: That means you are logged on to computer ``maan'' (actually: maan.njit.edu), that the sequence number of the prompt is 229, and that you are in a directory called ``ott'' (my home directory: my afs login is ``ott''). maan-229 ott>: is the prompt, it means the computer is ready to receive your next command. To find out exactly what directory you are in, you type (on the prompt) ``pwd'': maan-229 ott>: pwd /afs/cad.njit.edu/u/o/t/ott maan-230 ott>: We have a directory / , with a sub-directory afs , with a subdirectory cad.njit.edu , with a subdirectory u , ... , with a subdirectory ott . The full path name of my home directory is /afs/cad.njit.edu/u/o/t/ott You also see the computer gives me a new prompt. (number 230). My home directory has subdirectories. (Lots of them). One of the subdirectories is ``classes''. To go there: maan-230 ott>: cd classes /afs/cad/u/o/t/ott/classes maan-231 classes>: In general, on the prompt, typing ``cd '' moves you to that subdirectory. Anywhere, typing just cd moves you back to your home directory. To find out more about the command cd , type ``man cd'' . Try it. It will give lots of information. Every directory has a ``parent directory''. The parent directory of ``classes'' (in this case) is ``ott''. If you want to go to the parent directory of the current directory, you type cd .. maan-232 classes>: cd .. /afs/cad/u/o/t/ott maan-233 ott>: cd classes/spring06 /afs/cad/u/o/t/ott/classes/spring06 maan-234 spring06>: pwd /afs/cad.njit.edu/u/o/t/ott/classes/spring06 maan-235 spring06>: The ``current directory'' can always be called ``.'' . so, ``cd .'' keeps you where you are. (You know what directory we are now in). A directory contains files and subdirectories. To get a listing, you use the command ``ls''. Do ``man ls''. I like ls with the option -lt : maan-235 spring06>: ls -lt total 20 drwxr-xr-x 5 ott 30 2048 Mar 22 16:47 CIS456 drwxr-xr-x 3 ott 30 2048 Mar 6 06:52 CIS656 -rw-r--r-- 1 ott 30 5637 Jan 20 14:46 Grading.01.20.06 maan-236 spring06>: If you want to create a new subdirectory of the current directory, type mkdir . (Do ``man mkdir''). maan-236 spring06>: mkdir Junkdir maan-237 spring06>: I just created a new subdirectory, called Junkdir. Let's go there: maan-237 spring06>: cd Junkdir /afs/cad/u/o/t/ott/classes/spring06/Junkdir maan-238 Junkdir>: pwd /afs/cad.njit.edu/u/o/t/ott/classes/spring06/Junkdir maan-239 Junkdir>: Now I want to create a new file in this directory. One of the many ways to do that is by using an editor and typing in the content of the new file. There are many editors: pico , emacs , vi , etc. I use emacs. People tell me that pico is very easy to learn. To find a tutorial on pico: Go to Google, look for ``pico tutorial''. That gives a couple, one is http://www.usd.edu/trio/tut/pico . Of course, there also are books, on pico , emacs, vi , etc. I will create a new file called ``junkfile''. I will use emacs. maan-239 Junkdir>: emacs junkfile & [1] 23887 maan-240 Junkdir>: The ``ampersand'' means the editor will ``work in background'' so that the window I was working in still can be used for other work. I will not show you my typing. maan-240 Junkdir>: [1] Done emacs junkfile maan-240 Junkdir>: (Here I made an error i am not showing. As result the sequence numbers jump). I want to show the new file exists: maan-246 Junkdir>: ls -lt total 2 -rw-r--r-- 1 ott 30 0 Mar 25 14:37 : -rw-r--r-- 1 ott 30 117 Mar 25 14:37 junkfile maan-247 Junkdir>: (I accidentally created an ``empty'' file called : ). Let's remove it: maan-247 Junkdir>: rm : maan-248 Junkdir>: ls -lt total 2 -rw-r--r-- 1 ott 30 117 Mar 25 14:37 junkfile maan-249 Junkdir>: ``rm '' removes the file called . Do ``man rm''. Be careful with rm ! You may remove the result of a couple of days work! There are a few more handy command: cp (copy) do ``man cp''. mv (move) do ``man mv''. To see the content of a file, there are several commands. I like ``more'' (do ``man more''). Sometimes ``cat'' is nicer (do ``man cat''). For example: maan-249 Junkdir>: cat junkfile This is a junkfile. To show students how to create a file. More interesting would have been to type in a program. maan-250 Junkdir>: We see that the file ``junkfile'' contains four lines of text. Let's create another subdirectory, move the junkfile to that subdirectory, follow it, and look at it again: maan-250 Junkdir>: mkdir Junk2dir maan-251 Junkdir>: mv junkfile Junk2dir maan-252 Junkdir>: ls -lt total 4 drwxr-xr-x 2 ott 30 2048 Mar 25 14:51 Junk2dir maan-253 Junkdir>: cd Junk2dir /afs/cad/u/o/t/ott/classes/spring06/Junkdir/Junk2dir maan-254 Junk2dir>: ls -lt total 2 -rw-r--r-- 1 ott 30 117 Mar 25 14:37 junkfile maan-255 Junk2dir>: cat junkfile This is a junkfile. To show students how to create a file. More interesting would have been to type in a program. maan-256 Junk2dir>: OK, enough junk. Let's remove it: maan-256 Junk2dir>: rm junklfile junklfile: No such file or directory maan-257 Junk2dir>: rm junkfile maan-258 Junk2dir>: ls -lt total 0 maan-259 Junk2dir>: cd .. /afs/cad/u/o/t/ott/classes/spring06/Junkdir maan-260 Junkdir>: rmdir Junk2dir maan-261 Junkdir>: cd .. /afs/cad/u/o/t/ott/classes/spring06 maan-262 spring06>: rmdir Junkdir maan-263 spring06>: (Note the typo I made when trying to remove junkfile). rmdir removes directories, but only when they are empty. Do ``man rmdir''. I have not found a really good tutorial on Unix yet. If you find one you like, let me know. (28 years ago there was a very nice 11 page tutorial on Unix, but it was based on the editor ``ed'', which is truly archaic now. It took me only about 4 hours to become fairly competent in Unix.) You can use editors to write programs. In Unix (and Solaris, and Linux) you use a ``postfix'' or ``suffix'' to indicate what language the program is written in. program.f would be a file containing a Fortran program. program.c would be a file containing a C program. program.cc would be a file containing a C++ program. program.java would be a file containing a Java program. etc. You can use the ``mv'' command to change the name of a file. Or ``cp'', if you want two identical files with different names. (In fact, mv does not move the file! It changes its name etc). It is possible to create a file in one computer and then move it or copy it to another computer. There are many ways. You could burn it into a CD. Or copy it onto a floppy. Or send it by Email. Or FTP the file, see Comer Chapter 25, or Forouzan Chapter 19. There is a short FTP tutorial on this website. Or you could put the file in your website. FTP used to be the ``typical'' method for sharing files, but now www (http) has taken over, and peer-to-peer is becoming very popular. Let's do ``ls -lt'' again: maan-263 spring06>: ls -lt total 20 drwxr-xr-x 5 ott 30 2048 Mar 22 16:47 CIS456 drwxr-xr-x 3 ott 30 2048 Mar 6 06:52 CIS656 -rw-r--r-- 1 ott 30 5637 Jan 20 14:46 Grading.01.20.06 maan-264 spring06>: CIS456 and CIS656 are directories. Grading.01.20.06 is a file. We see that from the first letter on each line: d for directory. I (ott) am the ``owner'' of each item. I forgot what the ``30'' stands for. ls -lt also gives the last time the file (or directory) was changed. the number before the month is the size. (In case of a directory: not the size of the content, but the size of the book-keeping information.) The information to the left describes what permissions there are. More about that later. Since CIS456 is a directory, we can go there: maan-264 spring06>: cd CIS456 /afs/cad/u/o/t/ott/classes/spring06/CIS456 maan-265 CIS456>: ls -lt total 28 drwxr-xr-x 21 ott 30 2048 Mar 22 16:47 Homework -rw-r--r-- 1 ott 30 386 Mar 22 16:47 projlist -rw-r--r-- 1 ott 30 386 Mar 22 16:46 classlist2 drwxr-xr-x 2 ott 30 2048 Mar 15 13:56 Warnings -rw-r--r-- 1 ott 30 1283 Mar 15 13:13 att_list -rw-r--r-- 1 ott 30 415 Feb 20 12:59 midtermI -rw-r--r-- 1 ott 30 415 Feb 20 12:59 classlist2~ drwxr-xr-x 3 ott 30 2048 Feb 6 12:47 Pgms -rw-r--r-- 1 ott 30 429 Feb 2 17:21 classlist -rw-r--r-- 1 ott 30 429 Feb 2 17:16 rawlist maan-266 CIS456>: And now I go back to my home directory: maan-266 CIS456>: cd /afs/cad/u/o/t/ott maan-267 ott>: