Basic unix commands and concepts:
Note that all unix commands and filenames are case sensitive: File1 and file1 are *not* the same file to unix. And if you type LS rather than ls, nothing will happen. Same goes for user names and passwords.
Unix concepts:
Piping – A plumbing analogy: In unix you can take the output of almost any command or
program and “pipe” it into another command or program using the pipe symbol |
(a vertical line). For example ls -l | sort –n +4 will pipe the output of the ls -l
command into the sort command, producing a list of files sorted by size.
Just as you can pipe stuff to and from a command or program, you can also send stuff to and from a file using the redirect symbols < and >. For example, ls > listfile redirects the output of the ls command to the file listfile. ls >> listfile does the same thing, but appends to the end of the file rather than overwriting it. Another example: sort < listfile will pipe the contents of the file listfile into the sort command. I usually prefer to say cat listfile | sort instead, because I find it easier to think about if I keep the flow of input and output always going from left to right.
Input from the keyboard is called “standard input.” Input through a pipe is also standard input. Most commands and programs can receive input from either a file or from standard input. So for example cat listfile | sort and sort listfile both produce the same output. Standard output is printed to the screen or can be redirected to a pipe or a file. Standard error is also printed to the screen, but on a different “channel”. Standard error is usually used for error messages and the like, and does not get redirected by > or piped by |.
Arguments – things (such as file names) that are given after a command name. For example ls /home has one argument (/home) that is passed to the command ls. This produces a list of the files in the /home directory.
The backspace key – depending on the terminal type, any of the following may act as the backspace key: backspace, delete, control-h, control-?, control-backspace, control-delete.
Other things you may need to learn about: file permissions, file ownership, file creation mask (in cshrc file), mounting filesystems (including cdroms and floppies), environment variables, terminal types (when in doubt, try vt100), regular expressions and pattern matching, shell expansion and how to “protect” special characters (such as * . $) from the shell when passing them in arguments (using single quotes or \ usually), shell scripts.
Unix commands:
telnet condor.depaul.edu ---- if you want to check your email, etc on condor; you can
also set up a web page by placing files in the public_html directory of your condor
account.
ssh – a secure version of telnet. Telnet is disabled on the lab machines and only ssh can be
used. (If you type telnet it will use ssh instead because I have “aliased” telnet to
refer to ssh. See “.cshrc” below.)
ftp – for transferring files from one machine to another. Example: ftp condor.depaul.edu
(You can ftp out from the lab machines, but not into them from other computers.
I have disabled incoming ftp connections because they are insecure. I use rsync
instead. Another option is to ftp the files you want to condor, then log into the lab machine
ftp the files down from condor.)
rsync – syncs a local directory with another directory (possibly on a different computer). Not
really a “basic” command, but what I use to securely transfer files and run backups.
Example: rsync –e ‘ssh –l dallbrit’ –az /dos-cogsys/output condor.depaul.edu:private
This command will back up the output directory (containing data produced by
cogsys) to my private directory on condor. If you want to know more, look at the
man page for rsync or ask me.
exit ----- logs you out of the current shell
ls --- list the files in the directory
cat – concatenate; prints the contents of its arguments to standard output. Useful for starting a series of piped commands with input from a file.
control-d – the unix end of file marker (like control-z in DOS). Typed on a line by itself, it signals the end of a stream of keyboard input you are piping into a command.
more – presents standard output a screen at a time, going to the next screenful each time you press the spacebar. A good thing to pipe the output of a command into. Also try less, which is a fancier version of more. (Less can scroll up or down; more can only scroll down.)
cd -- change directory (also see pushd which remembers where you came from)
rm --- removes a file or files
cp -- copy a file
man {command} -- see the manual entry for a command; example: man vi
sort – a very useful utility for sorting files or the output of other commands
.cshrc – a file (not a command) that sets options for your login session. You can
change the command prompt, set up aliases (so that if you type “dir” it executes “ls”
for example) and so forth.
csh – the ”shell” that runs in your account. The shell reads in your commands from the command line and executes them. Your account uses csh, or the “C-shell” by default. It is called that because its syntax is similar to the C programming language. The cshell has some handy features for command and filename completion (tab key), repeating a command (up arrow, !), and reviewing previous commands (history).
bash – another widely used shell, preferred by most programmers. If you type “bash” on the
command line and hit enter, you will then be using a bash shell rather than csh.
ps – list processes that are running. Useful for finding and killing programs that have run
amok.
kill [process number] – terminates a process
control-c – interrupts the process currently running in that terminal window. You will use this a lot.
df – lists all the currently mounted filesystems and tells how much free space they have.
chmod – change the permissions of a file. In unix, you can control whether a file or
directory is viewable by other users by changing its permissions. Also use
chmod to make a file executable (for programs or scripts)
find – a powerful utility for finding files by name or type.
Here is an example that lists all the word documents in
the windows partition of the computer:
find /win -iname ‘*.doc’ -print
grep – extracts lines from a file (or standard input) that match a given pattern
xargs – it’s a little complicated, but a very useful utility.
Example: find /dos-cogsys -name ‘art*’ -print | xargs grep ‘testlist’
This first finds all the files in the /dos-cogsys directory whose names start
with “art”. It then takes those file names and for each of them executes the
command “grep ‘testlist’”, which prints each line in the file that contains the
string “testlist”.
awk - a handy text manipulation utility. Most of my scripts make extensive use of awk
sed - stream editor. Used to search for patterns and change text that matches them.
perl - practical extraction and report language. Take bits and pieces of C, sed, awk, c-shell,
and a few other things, put them together in a way that lets you do almost anything
several different ways and you have perl. Perl is great for any kind of text manipulation
and formatting. I use it to generate cogsys tests lists and to put the cogsys output files
into a useable form for analysis. Learn to use perl – it will be a very useful skill.
Most web cgi programs are written in perl, and it is a favorite of system administrators.
Other commands you might use often: wc, who, history, du, quota –v (on condor),
locate, tr, uniq, head, tail, control-z (to suspend a running process), bg (to
put a suspended process in the background), fg (to bring a process to the
foreground), top, ping.
vi - visual editor, for text editing. Necessary for editing files on condor. To edit files that are on the lab machines, you can usually just use the built-in text GUI text editor instead, but vi is really handy to know. You could also use emacs instead of vi; it is a more powerful text editor favored by programmers.
Example: vi filename --- to start editing a file (from the unix command prompt)
example: vi id1s001
vi commands: --- what to do within vi to edit a file
Note: vi starts out in "edit mode", with certain keys doing certain functions. To type in new
text, you first have to get into "insert mode" before typing in the text.
h j k l -- cursor movement; arrow keys also work for this
i -- start inserting text before the current cursor position. This takes you out of edit mode
and into insert mode. Now you can type in text. To get back to edit mode, hit escape.
:w -- write the file to the hard drive. this is how you save your work.
:q -- quit vi. after saving your work, give this command to exit vi.
dd -- delete the current line
dw -- delete the word following the cursor
x - delete one character following the cursor (backspace doesnt work in edit mode)
Note that all these commands only work in "edit mode", not in "insert mode". Insert mode is just for typing in new text.
David Allbritton
Last Updated:
September 8, 2001