Where can I buy a Unix guidebook? What do you recommend?
Any bookstore, including places like B. Dalton. I learn these things through different associations than you would so can't give a personal recommendation. I've know people who liked "UNIX for Idiots".
Why do we need all of these files? What does the computer do with them?
Files are simply a place to store information on the computer's disks. They are given names so that we can easily find them. We will primarily use files in 5 ways. Although you don't think about it, most commands that you enter at your terminal simply cause the CPU to execute machine instructions stored in a file with the command's name (try the command "ls /bin" to see some of these files). Each Fortran program that we write to perform some calculation will be stored in a file. When we compile the file the resulting instructions that can be used by the CPU are stored in a separate file. We tell the machine to execute the commands in that file to do the calculation. For some projects we will create files that contain data to be used in a program. We will also create programs that put their results in specific files for later use.
I'm confused about directories.
Directories are simply a way of maintaining order and ownership of files on disks. You don't want to see every file on a disk, and don't necessarily want everyone to look at all of your files. If my analogy to file folders didn't help, try thinking of the disk as a building. You enter the front door and might find a few signs to read (files that can be viewed with utilities such as "more"), and in the elevator you see numbered buttons on the wall ("ls" provides you with eyes on the computer) and punch a labeled button to go to a selected floor (use "cd" to move to a subdirectory or file folder in a disk file system). When you step out of the elevator you see a few more signs posted and see numbered doors to rooms (a lower level of subdirectories). Some of the rooms may be locked. If a room belongs to you (check "ls -alF" to see if it is yours), you can lock out or grant access to others with "chmod". You enter a room ("cd" again), find more notices on the wall to read, and a pen ("vi" editor) on a desk that you can use to leave your own notes in the room. You can protect these notes from prying eyes with "chmod". You might call the maintenance crew to clear all the useless notices off of the wall ("rm") or ask them to remodel and give you some connecting rooms (mkdir). If there are connecting rooms that you no longer want, the maintenance crew can get rid of them for you. An empty room can be removed with the command "rmdir". If the room has any contents you can yell "rm -r (room name)", but may regret the wanton destruction.
How can a file and a directory be the same?
Perhaps I gave you too much information too early. If I create a subdirectory called "subdir1", in fact I create a file called "subdir1" containing information that will let the system find the files I've put in "subdir1". These details aren't useful to you at this point (and probably never will be).
Why aren't the subdirectories used by Unix to identify the current directory and the next one higher marked with a * ?
Although all directories are marked as executable in the list of access privileges, they are simply marked with a / when the "-F" option is used by ls to indicate their function. You don't really execute an entry for a directory.
How do I delete blank lines in a program when using vi?
Position the cursor on the blank line while in command mode (hit the Esc key if you're not sure) and type "dd". If you have 2 blank lines in a row, put the cursor on the first one and type "2dd".
In a command like "cd /" do we need a space after the slash?
No! When entering full file path specifications such as "/home/jhm/test/test.f" the presence of blanks will confuse the computer.
How do I copy files? How do I get to files shared by the group?
The Unix copy command is "cp". Before making massive changes to a Fortran program (say the program "test.f"), you might want to issue the command "cp test.f test.fo" to create a backup copy. If user jhm123 is keeping the latest copy of your group's program in the chain homework/hw3/cannon.f, you can copy it to your current directory with :
cp ~jhm123/homework/hw3/cannon.f cannon.f
cp ~jhm123/homework/hw3/cannon.f .
For you DOS folks, the period at the end of the last form is required by Unix, telling it to drop the copy into the current directory with the name cannon.f. If you are used to DOS I recommend that you include a line in your .alias file containing "alias copy cp".
How do I mail files from Unix?
Say you want to mail file "grp11.hw3" to me at email@example.com. Simply issue the command:
mail firstname.lastname@example.org < grp11.hw3
On my end I receive the file by typing "mail". mail gives a numbered list of files in my mailbox. If your file is item 14 in my mailbox, I type the command "w 14 grp11.cannon". I then type "q" to end my mail session, and can look at the new file "grp11.cannon" in my current directory.
How do I protect files?
File protection is handled with the "chmod" command or by using "umask" in your .cshrc file. If you don't want anyone looking at the file "cannon.f" issue the command:
chmod og= cannon.f
This removes all access privileges from others (o) and your group (g). This is not your class group, but a broader definition including all students. You can protect whole directories with something like "chmod og= hw3". If for some reason you want to give others write access to a file use "chmod o=w cannon.f".
How do I delete files and directories?
To delete files use the "rm" command. "rm cannon.f" deletes cannon.f. "rm *.f" deletes all files with names ending with ".f". If a subdirectory "hw3" is empty you can delete it with "rmdir hw3". You can also get rid of "hw3" with the command "rm -r hw3", but this takes out "hw3", and all of its contents including any subdirectories existing in hw3. If you like the computer to check with you for confirmation on each delete, use the "-i" option.
Are there any restrictions in naming of directories and aliases?
The full name of a directory tracing back to the root must be unique. However, it is possible to have both "/tmp_mnt/avenger/jhm123/sub1" and "/tmp_mnt/avenger/avy321/sub1". Some characters that are used for special purposes by csh such as &,*,[,], and \ may cause you grief. With aliases it is possible to redefine commands that are normally used by csh or the underlying Unix operating system, so exercise a little caution. This overwrite feature can be useful to force your favorite options when you execute a utility. Take a look at the file ".alias" in your home directory for an example of this redefinition. You should set your favorite aliases in the ".alias" file, so that they are automatically defined when you login. Please note that ".alias" is not something Unix automatically uses, it is executed by this system's default ".cshrc" file when csh or tcsh are started.
What is a shell?
A shell is just another computer program. It accepts commands that you type into your keyboard, and passes them on to the Unix operating system (perhaps with some translation).
Can I use tcsh?
Yes. Try "man tcsh" for information on tcsh. Once you are logged on, type "tcsh" to start this shell. Commands are the same ones you have learned, but using the up and down arrow keys will let you scroll through commands used since starting tcsh. For a given command use the left and right arrow keys to position yourself in the line for changes. Normally what you type is inserted in the line. Holding the "Ctrl" key and hitting "d" (sometimes referred to as "^d" in instructions) deletes the character under the cursor. "Ctrl" with "k" deletes the rest of the line beyond the cursor point. When you are using tcsh, the first time you type "exit", you will be returned to your original csh session. Another "exit" is required to logout.
How much help can you get from the "man" command?
It varies wildly. Usually there is far more than you want to know, and your problem is sorting out the few nuggets of gold. As my class example of the use of the "-k" option with man showed, sometimes it is difficult to locate information based only on a general idea of what you want to do.
I would like to learn further Unix shortcuts.
I will be introducing various Unix tricks during class, but my goal is to just make you functional in Unix. There are a large number of good Unix books in the Library and bookstore, if you want to become a Unix guru.
I am not comfortable with commands preceded by a - sign.
These are not true commands, just options that modify the behavior of basic Unix commands. I will continue to give examples. You should try the options to appreciate their behavior.
I did not understand the "cat" command.
The cat command is used for 2 purposes. One is to simply to quickly display the contents of a file on the terminal screen. Typing "cat test.f" will show you everything in test.f, but won't stop for you if the file has more lines than available on the screen (screen normally shows the last 24 lines). The primary use of cat is to combine the contents of several files into a single file. "cat a.f b.f c.f d.f > list.f" combines everything in the 4 files "a.f", "b.f", "c.f" and "d.f" into the file called "list.f", assuming "list.f" does not already exist. If the file "list.f" already exists, you can replace it with the command "cat a.f b.f c.f d.f >! list.f". If what you really want to do is add other files to the end of "list.f", you issue the command "cat a.f b.f c.f d.f >> list.f". Use of >, >!, and >> in any Unix command has the effect of redirecting output, that would normally go to the screen, to a disk file. You can get more information by typing "man cat". I was moving too rapidly when going over "cat:". When my explanations become too fast or terse, feel free to get my attention by shouting "Question!" at high volume.
How can you put alias commands into a file that is run at each login?
You can add alias command lines to your ".cshrc". Also look at your ".cshrc" file for a line like "source .alias" or "source .alaises". If it exists (or you add it), you can put lines in the ".alias" or ".aliases" file. The command "source .alias" simply tells the Unix shell to execute the commands contained in the text file ".alias".
What does "Unknown tilde escape mean"?
It means that mail is processing an input line that begins with a "~", but is followed by a letter that it does not recognize as a valid "tilde" command.
How do you erase files in your mailbox?
Use the "d" command. "d" deletes the current message. "d 10" deletes message number 10. "d 10-20" deletes messages 10 through 20.
Can Unix read a txt file created by an MS-DOS software appliciaton?
Yes, but it needs to be moved by mail or FTP in ascii text mode to take care of details in file record structure.
Is there a way to repeat the previous command in Unix
In csh (your default shell) "!!" will repeat the previous command. "!f7" will repeat the last command line that began with the letters "f7". The better way out is to type "tcsh" right after you login (you will have to type "exit" twice to get all of the way out of the machine). The arrow keys will let you scroll through previous commands.
When using diff do both files have to be in the same directory?
No, but it is easier. In referring to a file you must give enough information so that diff can find it. Say you are in a directory with a file "hw6.f" and there is a subdirectory under your current directory called "test", containing another file called "hw6a.f". You can compare them from the current directory by typing:
diff hw6.f test/hw6a.f
If you happen to be in the subdirectory "test" you could do exactly the same thing by typing:
diff ../hw6.f hw6a.f
What else can we do with dbx?
You can list lines in your original Fortran program (list n1,n2 where n1 and n2 are line numbers). You can tell it to stop execution at a given line number (stop at n1). This is referred to as setting a breakpoint. You can continue executing from the last stop until the next breakpoint (cont), or just execute the next line of Fortran (step or next). There is much more. I'll give an example after the exam and you can check "man dbx"
Maintained by John Mahaffy : email@example.com