UNIX Command Summary

From FarmShare

Revision as of 16:23, 14 February 2012 by Chekh (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Wow this page is old.

Contents

Introductory information

An operating system consists of commands that let you manage information in the form of files or run programs that perform tasks such as word processing, email, or data analysis.

A UNIX file is a collection of information stored on disk, be it the text of a document, data for statistical analysis, or the executable code for a program. A file is referenced by a name. A filename in UNIX can consist of any combination of characters on the keyboard except for the following: * ? ! | \ / ' " { } < > ; , ^ ( ) $ ~. These characters cannot be used in filenames because they have special meaning to the shell. For example, the first two symbols are used as "wildcard" characters when you're issuing commands: the * will match any string of characters in a filename, whereas the ? matches any single character.

How to issue commands in UNIX

The UNIX environment is interactive. When you type a command at the keyboard and then press the ENTER or RETURN key, UNIX immediately begins to act on the command. More accurately, UNIX interprets the command using a special program of its own called the shell. The default shell is tcsh. All shells produce a shell prompt to let you know that UNIX is awaiting your next command. The shell prompt has the form host:~>, where host is the name of the UNIX system you are using (e.g. Elaine38:~> or Cardinal:~>). Whenever you see this prompt, you know that the UNIX shell is ready for your next command.

UNIX is case-sensitive. That is, UNIX distinguishes between upper and lower case letters in the names of files and programs. Thus, while ls is a valid UNIX command, LS is not. Login names and passwords are also case-sensitive.

Some programs, such as Pico, have their own commands that you type within the program rather than at the UNIX shell prompt. However, the shell prompt reappears whenever you exit such programs.

Basic file commands

These are typed at the shell prompt host:~>.

List the files in the current directory

ls

List all the files in the current directory, even the hidden ones

ls -a

As above, but indicate sub-directories by appending a backslash (/) to their name

ls -F

Make a copy of FILE1 and call the copy FILE2

cp FILE1 FILE2

Rename a file from old name FILE1 to new name FILE2

mv FILE1 FILE2

Move a file from it's present directory into another directory (DIR)

mv FILE1 DIR/

Remove or delete FILE

rm FILE

Display the contents of FILE, pausing after each screenful

more FILE


--More--(18%)

Whenever you see something like the above at the bottom of your screen, you can:

  • press the space bar to see the next screenful of text
  • type b to go back one screenful
  • type q to quit the listing of text and return to the UNIX shell prompt

Correcting typing mistakes: (at the shell prompt)

Erase the last character you typed

Delete or Backspace

Delete the last line you typed

Ctrl-u

Basic directory commands

These are typed at the shell prompt host:~>.

In UNIX, your files are organized in directories and subdirectories. When you first log in to your account, you are placed in your home directory which you can refer to with the character ~.

Go to the directory called DIR

cd DIR

Go to the directory above the current directory

cd ..

Create a new directory called DIR

mkdir DIR

Remove the directory DIR (must be empty first; if not, use rm -r)

rmdir DIR

Go to your home directory

cd or cd ~

Move or rename a directory from old name DIR1 to new name DIR2

mv DIR1 DIR2


Use the / character to separate directory and file names when specifying a path.

Printing

You can print UNIX files and mail messages to your own printer and a network printer. The latter is easier, but requires that you walk to the network printer to pick up your output.

Printing On a Network Printer

To print a UNIX text or PostScript file, type the following command at the system prompt: lpr -PNAME FILE ->

where NAME is the name of the printer, e.g.,polya0.

Printing to Your Own Printer

To print a UNIX file on your own printer, you must first "download" it to your desktop computer. Exactly how you do this depends on which communication package you use, as well as which type of computer you have.

Useful commands

Ends your work on the UNIX system

exit

Clear the screen

Ctrl-l or clear

Stop the program currently running

Ctrl-c

Retrieve the last shell command you typed

Ctrl-p

Pause the currently running program

Ctrl-z

Look up the UNIX command COMMAND in the online manual pages

man COMMAND

Find all paths containing FILE in the current directory or below it

find . -name FILE -print

Searche for and display all lines in file that contain PATTERN (case insensitive)

fgrep -i PATTERN FILE

List background jobs started during your current login session

jobs

List all jobs (background and foreground) started during your login session

ps

Display disk usage in kbytes by directory, starting in the current directory and working down

du

Display total disk usage

du -s

Display your current disk space usage and quota in kbytes

fs listquota

Count the lines, words, and characters in FILE

wc FILE

Report possible misspelled words in FILE

aspell FILE

Look up a word via the online version of Webster's dictionary

webster WORD | more

UNIX shell shortcuts

The UNIX shell keeps a record of the commands you type during your login session. Here are a few commands that take advantage of this history facility. All are typed at the shell prompt host:~>.

List all commands typed so far (default maximum number=20)

history

Repeat the last command

!!

Repeat command n from the history list

!n

Repeat last command beginning with PATTERN

!PATTERN

Repeat last command but replace PATTERN1 (usually a typo) with PATTERN2 (the correction)

^PATTERN1^PATTERN2


This document was based on originals prepared by Lynn Gale and Patrick Goebel, Center for Advanced Study in the Behavioral Sciences.

Personal tools
Toolbox
LANGUAGES