Unix/Linux basics
Room 232 computers -- set up
Reboot
F12
SATA1 -- Linux disk
Login: Use your NAU ID (e.g. det35)
Password: ChangeIt
Change password:
- Open terminal window
- Type "passwd"
- Enter new password when prompted
Preferences --> Windows --> Follow mouse
Applications --> Accessories --> Right click to add to top panel
All these machines are served by cepheus.phy.nau.edu
This means it doesn't matter where you sit in this room
You can log in to cepheus from other machines too if you like
Unix/Linux basics
Unix commands generally obey this structure:
%> command [optional arguments or flags] inputfile [sometimes an output file]
Here, %> represents the Unix prompt. An example would be
%> cat datafile
or
%> cp -p firstfile secondfile
In the first example, there are no optional arguments, and only the
inputfile is given. In the second example, there is both an optional
argument and both an input and output file are required.
File system setup
''Files'' are the basic unit of a unix file system. A file can be a data listing; a plot; an image; a text document; an HTML document; a series of commands; a program written in a program language; or even some information about the unix system itself. Files can have any kind of name; typical name extensions include ".txt" (text file), ".pro" (IDL program), ".ps" (postscript file), ".pdf" (PDF file), etc.
Files sit in ''directories''. Directories can contain other directories too (called ''subdirectories''). There is no limit to the number of levels of subdirectories you can have, nor is there really a limit to the number of files you can have within a given directory. Directories end in "/".
Your ''home directory'' is where you land when you first log in to a computer, or first open up a new terminal window. This is your starting place, and often contains various useful setup files.
The very top of the file system is "/". Here lies a lot of other system-level stuff that controls how various low-level programs work. Generally, you don't want to work higher in the file system than your home directory, which is usually something like /Users/username/ or /home/username/ .
Good computer practice suggests that you should use directories. In your home directory, therefore, you shouldn't have all your files with no subdirectories. Instead, you might put software in a "software" directory, data in a "data" directory, plots in a "plots" directory, etc. etc. There's no one right way to do this, of course -- the key is that you should be able to find your way around and not lose files or information. Any system that makes sense to you is okay.
Where am I?
. [one period] -- this means the current directory.
.. [two periods] -- this means the directory above.
~/ -- this means your home directory.
/ -- this means the top of the directory tree.
* [star] -- all files (i.e., in the current directory)
Basic Unix commands
man -- stands for ''manual'' page (like a help page). You can look up how to use (ie, syntax, arguments, optional flags) any (most) Unix commands by typing man command (for whatever ''command'' you are interested in) at the Unix prompt. Sometimes very useful, sometimes completely frustrating. Sometimes includes examples.
info -- oftentimes more useful than the man pages. Type info command to get information on how to use a command. Often includes useful examples.
cd -- change directory. Requires one argument -- the name of the directory to change to. You can use relative paths (cd ../.. goes up two directories) or absolute paths (cd /home/trilling/data/junk/). cd with no argument takes you back to your home directory.
pwd -- returns the current directory. Takes no arguments. Good to use if you're not sure which directory you are working in.
ls -- lists the contents of a directory. With no arguments, it lists the arguments of the current directory. You can also supply a directory argument: ls /home/trilling/data/junk/. You can also use many different flags: -l gives a long list, -a lists all files (including "hidden" files, -t lists the files in chronological order, -r reverses the order, etc. You can combine these flags all together: ls -lart gives a long listing of all files in reverse chronological order (puts the latest file last). This is the default ls command that I use.
cp -- copies files. Requires a "from" and a "to": cp fromfile tofile. There are a number of optional arguments (like -p, which preserves the time and date stamp on a given file).
mv -- moves ''firstfile'' to ''secondfile'' as follows: %> mv firstfile secondfile. You can use this to rename a file, or to move a file into a new directory, for example.
rm -- removes a file. Best to use with default of -i, which inquires whether you really want to remove the given file.
mkdir -- create a new directory. Can either take relative path (%> mkdir newdata creates a new directory in your current working directory) or an absolute path (%> mkdir /home/trilling/newdata/).
rmdir -- removes a directory. Unix won't let you do this unless the directory is empty.
cat -- prints the file to the screen, i.e., %> cat filename.
head -- prints the beginning of a file. By default, the amount printed is the first ten lines (example: %> head filename prints the first ten lines), but you can get as many lines as you want with an optional argument (example: %> head -20 filename gives you the first 20 lines).
tail -- prints the end of a file. By default, the amount printed is the last ten lines. Examples are as above.
more -- prints out a file, one page (screen) at a time. Use the space bar to advance to the next screen.
Network commands
ssh -- stands for Secure Shell. Allows you to log in to another machine securely (using encryption). Syntax is ssh username@other.computer.name. You will be asked for your password on the other machine.
scp -- stands for Secure CoPy. Allows you to securely copy file(s) from one machine to another using encryption. The syntax is basically the same as for cp. You need a "from" and a "to" location. Examples: scp -p username@other.computer.name:/home/username/somefile . [notice the dot at the end, which means this directory] copies a file from there to here. Alternately: scp -p local.file username@other.computer.name:/home/username/directory/filename puts a file from here to there.
Other useful commands
Ctrl-C -- kills a process/command.
Ctrl-Z -- pauses a process/command. Use fg to get the process back.
& -- put this after a unix command to run your job in the background
More Unix/Linux design issues of interest
An important thing about unix commands is that you can string them together to make very long commands that are simply a series of simpler commands. For instance, I often, in a single command line command, use ''grep'', ''awk'', ''sed'', and ''sort'', as well as some directional commands and the like. You will learn how to do these too. Each of these commands by themselves is powerful, but the most powerful use is combining them together.
Inputs and outputs -- how to move stuff around
You can use various direction-related characters in Unix commands. "<" specifies an input file and ">" directs an output to a file. You can type
%> < infile awk '{print $1}' > outfile
to write column 1 of ''infile'' to the output file ''outfile''.
You can also use "|" (which is called a pipe) to direct commands, and in particular to link a bunch of commands together. This is really like a pipe -- you pipe the results of one command into another command. You can type
%> < infile awk '{print $1,$2}' | sort --key=2
to write out the first two columns of ''infile'' and then do something to the output of that first command (in this case, those two columns) -- here what we do to this output is sort them (see below). You can string together many Unix commands on a single command line
this.
More useful Unix commands
wc -- stands for Word Count. Returns the number of lines (first output), words (second output), and bytes (third output) in a file. I find this surprisingly useful. For example, sometimes I want to see how many lines of data I have in a file; wc can tell me this without my having to open the file.
sort -- sorts data (for example, a file or output from another command). Sort has some useful optional arguments: -n means numerical sort, and --key=columnnumber means to sort on column number columnnumber. -r sorts the output in reverse order. You can string these together (for example, -nr if you want to sort numerically in reverse order).
nl -- writes the line number (Number Line) at the beginning of each line. Again, surprisingly useful: nl infile puts a 1 in front of the first line, 2 in front of the second line, etc. I often use this if I want a line counter for the data file. A neat tool in your unix toolbox.
cut and paste -- these work on columns of data. -d indicates the delimiter between your columns and (for cut) -f indicates which columns you want. Example:
%> < infile cut -d ' ' -f 1
will look for columns delimited by a space (that's what ' ' means), and print out the first column (that's what -f 1 means). Paste is similar:
%> paste -d ' ' file1 file2
this pastes the columns of ''file1'' and ''file2'' next to each other, using a delimiter of a space (' ').