Unix Information - ndgriffeth/Class-Notes-and-Lectures GitHub Wiki
Linux and Mac OS X are both versions of Unix.
The most important things you need to know are
1. The file system.
2. The shell.
3. Some commands.
4. How to create and edit files.
On a Unix system, everything is a file. Documents are files, directories are files, executable programs are files. This is also the case on almost every system you work with today, but that's because this approach worked so well on Unix.
One of the important advantages of the Unix approach to file systems is that you can create a file with one program (e.g., a text editor) and process it with another program (e.g., a compiler). If a system assumes that the file extension is assigned by the program that creates the file, and the system automatically adds the extension, there can be difficulties. Sometimes you have to change the extension by hand in Windows systems.
The file system has a hierarchical structure. The top-level directory, also called the "root" directory, is written "/". Certain directories are typically included under the top level. These are described in http://www.granneman.com/techinfo/linux/thelinuxenvironment/topleveldirectories/.
For the sake of examples below, we will assume an (overly simplified) file system containing the following directories and subdirectories:
/ - bin - echo
- cp
- ls
- mv
- sbin - fsck
- mount
- umount
- home - user1 - docs - doc1
- doc2
- src - prog1.cc
- prog2.cc
There are two kinds of file names, fully-qualified names and relative names. A fully-qualified name gives the name of each directory from the root down to the file as part of the name. Since there is only one root directory, this unambiguously identifies the file. Examples of fully qualified names in the above system are
/bin/mv
/sbin/moung
/home/user1/docs
/home/user1/src/prog1.cc
The relative name refers to the file with respect to the "working" directory, i.e., the directory where the user currently resides. If user1 has just logged in, his working directory is his home directory "/home/user1" and relative file names correspond to fully qualified names as follows
docs/doc1 corresponds to /home/user1/docs/doc1
progs corresponds to /home/user1/progs
Note that fully qualified names start with "/" and relative names do not.
The shell is a program that runs when you open a terminal window. It reads the commands that you type in the window and translates them to actions for the Unix operating system to perform. It also keeps track of your "environment." An important aspect of your environment is your working directory, i.e., the directory that you are currently using. When you open a terminal window, you are in your "home" directory, usually /home/< username >. You can move from one directory to another using the command "cd".
When interpreting a line that you type, the shell treats the first word of any line that you type as the name of a command (important commands are described later on this page.) The shell has built-in commands, but is not limited to its built-in commands. If the first word of a typed line is not one of the built-in commands, the shell assumes that the command name is the name of a file and looks for the file using another aspect of your environment, called your "path". Your path is a set of Unix directories that should be searched when looking for a command. You can see its current value by typing "echo $PATH" as a command ("echo" is a built-in).
The commands are listed by command name below. To use a command, you type a command with its arguments. Some commands have no arguments, many have one, many others have two, and a few have three or more.
cd Change directory
Example: "cd /" changes the working directory to the root directory.
ls List files in the current directory
mv Move file
Example: "mv x y" moves the file named x to a file named y (note, this amounts to renaming x)
cp Copy file
Example: "cp x y" copies x to y
rm Remove file
cat Copy input (from the keyboard) to output (on the console)
more Copy the file specified as the argument to the console, with paging
mkdir Make a directory file (in which you can place other files)
rmdir Remove a directory file
man Print a manual page, ie, a page explaining how to use a command
Example: "man cd" prints the manual page for the command "cd"
Note that you get a lot more detail than I'm giving you here!
sudo Treat me as a super-user when you execute a command
Example: "sudo mv /tmp /tmp1" makes it possible for a non-superuser to execute "mv /tmp /tmp1"
Since these directories belong to the root user, that would not be allowed otherwise.
su Make me super-user
Example: "sudo su" is the way you change from normal user (with sudo permissions) to "root"
(the superuser).
apt-get Update the system, install new software, etc.
If you're not the superuser root, you need to prefix this by "sudo"
ifconfig Print information about available network interfaces
ping Ask another computer to respond to you (tests connectivity)
dig Ask for the IP address that goes with a domain name (nslookup works too)
traceroute Find a route to an ip address or domain name (I don't think it will work from Lehman)
nmap A tool for scanning a network
The simplest way to create and/or edit a file on any Unix system is the editor "nano." See http://mintaka.sdsu.edu/reu/nano.html for a minimal introduction. The nano manual is here: http://www.nano-editor.org/dist/v2.0/nano.html. You can also get the same information by typing "man nano" in a terminal window.
On Ubuntu, there is also a GUI program "gedit" that lets you create text documents, and on Mac OS X you can use the GUI program "TextEdit" to create text documents -- but make sure that it's in Plain Text Mode, not Rich Text. When we create Web pages, we will need plain text, with none of the goo added by fancy word processors.