CSCI 1320 (Principles of Algorithm Design I):
Unix Hints and Tips (Command Line Interface)

Caveat: Last updated in 2007. Use with caution!

Useful commands

This is a list of commands mentioned in class, plus a few other useful ones. For complete information about any command, read its man page (see the description of the man command below).

Format for command descriptions

In typing a command, do not include the square brackets used to denote optional text.

Commands

Other tips and useful shortcuts

Interrupting programs

Redirecting input and output

Many programming languages (C among them) have an idea of "standard input" and "standard output". By default, reading from standard input means reading what is typed in at the keyboard, and writing to standard output means printing to the screen. But Unix allows you to "redirect" both input and output, i.e., to read standard input from a file and/or write standard output to a file. Input redirection can be useful in program testing (so you don't have to type in your test data over and over). Output redirection can be useful in capturing program output for printing.

Command-line shortcuts

Note: Whether the following tips work depends to some extent on how your environment is set up (what shell you are using -- shells were discussed briefly in class). If they don't work for you, talk to your instructor or a more knowledgeable user to see what might be wrong. But try them -- you can save yourself much typing if you know some of these shortcuts.

Customizing your environment

Unix permits you to customize your environment extensively. The following assumes that you have started with the default setup on the CS lab machines.

Adding command aliases

You can add aliases (short names) for commands you use frequently by modifying the file .bashrc in your home directory. You can even redefine existing commands. For example, inserting the following lines:
alias cp='cp -i'
alias mv='mv -i'
alias rmi='rm -i'
alias l='ls -alF'
redefines the cp and mv commands to always use the -i option, and defines new commands rmi (rm with the -i option) and l (ls with options -alF). (Note that ls -alF is the same as ls -a -l -F.)

File security

By default the files you create on the lab machines should be readable and writable only by you. File security and how to control it is briefly described in J. Oldham's tutorial on Unix file security. A way to check that no one else can access your files is to have a friend try; if he/she gets the message Permission denied, all is well.