Wandering around the filesystem: The UNIX filesystem is organized hierarchically below the directory "/" (called the "root directory"). Every directory contains two subdirectories "." and "..". "." refers to the directory itself, and ".." refers to the parent directory. The essential commands for using directories are: ls - listing directory and file statistics mkdir - creating directories rmdir - removing directories cd - changing to a different directory pwd - print working directory Examples: ls / ls mkdir example_dir cd example_dir pwd cd .. pwd ls While wandering around the UNIX filesystem, you will run into the following file types: Directories (which we just covered) Regular files Symbolic links Hard links Character special files Block special files Named pipes Regular files: Regular files can be created in lots of ways. One of the most important ways is by using an editor. Three popular editors are emacs, vi, and pico. Pico is perhaps the easiest to start using, so if you are unfamiliar with a UNIX editor, you should use it. Use your favorite editor to put the following into a file: This is an example of a text file. The following commands are useful for working on files: cat - print the file contents to the screen more - print the file contents to the screen, one screenful at a time. less - a more useful version of "more" file - prints the file type ls - lists file statistics cp - copy a file mv - move a file (or directory) rm - removes a file "mv" is also used to rename a file. After creating the above file, look at the output from ls, and from "ls -l". Command options: UNIX commands typically have a special type of argument (arguments are the part of the command that follow the command name) called command options or command flags. They are typically one letter, and follow a dash (-). Usually, the order of the options doesn't matter, and separate options can usually be combined in to one. The available options for a command can usually be found in the manual page for that command. Use the command "man" to view an applications manual page: man more and occasionally by using the argument "--help". --help is an example of a GNU style command argument. Two dashes (--) are used instead of one, and what follows the two dashes is a word, not a single letter. Symbolic links: Symbolic links are files that reference a different file on the filesystem. Common operations like editing a symbolic link are applied to the file that they point to, but operations like removing, or renaming are applied to the link, not to the file. Symbolic links are created with the command "ln -s". Hard links: Hard links are typically less useful than symbolic links. They merely associate another filesystem name with a specific file. The command "ln" (without the -s) is used to create them. Notice that the file isn't removed until all hard links to it are removed. As an example, make a hard link to a file and examine how the output of "ls -l" changes. Named pipes, and special files: We'll deal with these later. File statistics: File type Owner, group Permissions Time and size File type Look at the output from "ls -l" in a directory with a file, a subdirectory, a hard link to the file, and a symbolic link to a file. You'll see something like this: cs501@dante:foo% ls -l total 1 drwxr-xr-x 2 cs501 cppcs 1024 Jan 11 12:56 dir -rw-r--r-- 2 cs501 cppcs 0 Jan 11 12:56 file -rw-r--r-- 2 cs501 cppcs 0 Jan 11 12:56 link lrwxrwxrwx 1 cs501 cppcs 4 Jan 11 12:56 symlink -> file There is one line for every entry in the current directory. First there is "dir" --- notice the "d" at the beginning of the line --- that means that the file is a directory. On the 5th line, the "l" means that the file is a symbolic link. The - means that the file is a normal file. The next nine characters describe the permissions for the file. They are separated into 3 groups of 3. The first group is for the owner of the file, the second is for the group of the file, and the third is for all users. r w and x refer to read, write, and execute. If a user can read a file, they can see the contents. If a user can write to a file they can change the contents, and if a user can execute a file, they are able to "run" it. We will get to this shortly. For a directory, being able to read the directory means that you can list its contents, being able to write to a directory means that you can add or remove files to or from it. And being able to execute a directory means that you can try to access the files in it. The next field of the output from "ls -l" describes the number of hard links there are to a file (or directory). Don't try to make sense out of the number of hard links to a directory, yet. The next fields are the owner of the file, then the group of the file, then the size of the file, the last modification time of the file, and finally the file name. Notice that for symbolic links, the destination of the link is also printed. Changing file statistics: chmod - change permissions (chmod u+rwx,g-rwx,o=rwx file) chown - change owner (chown owner file --- need to be root) chgrp - change group (chgrp group file --- need to be in the group) touch - set last modification time (touch file) The other statistics that could be changed are the file type (this is set when you create the file), the size --- this can be changed by editing it, and the name --- you change this with mv. Processes and Jobs: UNIX is a multiuser, multitasking operating system. We've seen an example of its multiuser functionality with file ownership. Here, lets look at its multitasking capability. By multitasking, we mean that a UNIX operating system can handle more than one program running at a time. The fundamental abstraction is that of a process. A process is described by a process ID (or PID), an owner, and various performance statistics (how much memory it uses, etc). To look at process statistics, use the "ps" command: % ps PID TTY STAT TIME COMMAND 287 p1 S 0:00 -csh 358 p1 T 0:01 vi shell_notes 382 p1 R 0:00 ps Different versions of UNIX use different flags for different ps output. Under Linux, the -x argument is the right one: % ps -x PID TTY STAT TIME COMMAND 270 ? S 0:00 /usr/bin/tcsh -c /home/cs501/.xsession 278 ? S 0:00 sh /home/cs501/.xsession 280 ? S 0:00 xbiff -geometry 50x50+0+0 281 ? S 0:00 xclock -geometry 50x50+60+0 283 ? S 0:00 xscreensaver -no-splash 286 ? S 0:00 icewm 287 p1 S 0:00 -csh 358 p1 T 0:01 vi shell_notes 381 p1 R 0:00 ps -x To see all of the processes of all of the users use the "a" option: % ps -ax [snip] Processes are started by running applications (like "ls", though it will likely be finished before you can see it in the output of "ps"). They stop when the operating system claims them. One reason that the operating system might claim them is if they signal it that they are done. This is done when they exit. Processes can also be sent signals. Signals can be sent with the kill command, or if the process is a "job" --- if it was started by the current shell, they can be sent some signals by the shell. For example, if you start a command and you don't want to wait for it to finish, you can usually press Control-C (hold control, and press c) to kill it. You can also use Control-Z to stop it without killing it. Some shells have ways to deal with stopped jobs. You can use "bg" to send a stopped job into the background (thus returning to the shell), or "fg" to bring a backgrounded job into the foreground. Jobs can also be started in the background if their command ends with a "&": % ls /usr/bin >out & The shell will notify you when the job has completed.