A Few UNIX Commands

Getting documentation

Directories

The UNIX shell keeps track of your "working directory" or "current directory." The current directory is the directory (or, if you prefer, the folder) where you are currently working. All file- and directory-related commands will be performed relative to the current directory. For example, ls will list the contents of the current directory only.

The following commands will help you work with directories.
cd destination Change directories. Move from the current directory (folder) to destination.
cd .. Move to the parent of your current directory.
cd Move to your home directory.
cd . Move to the current directory. (Aren't you glad I shared this one with you?)
mkdir moose Make a new directory named "moose" inside the current directory.
rmdir moose Remove the existing directory named "moose." This won't work if there is anything already inside moose. There's a way to delete a directory and its contents, including subdirectories, but that's a dangerous thing to do--check the manual page if you really want to know.

Files

The following commands will help you use files. Many of them also apply to directories.
ls List the contents of the current directory, not including files whose names begin with a period (the "hidden" files).
ls -l Give a long-form listing, with lots of information about each file and directory.
ls -a Do a normal ls, but include all files whose names begin with a period.
ls -F Do a normal ls, but mark all executable files with a * and all directories with a /.
ls -laF Do all of the above.
mv oldFile newFile Move (or, more precisely, rename) the file oldFile to the file newFile.
mv file directory Move a file into a directory.
cp oldFile newFile Copy the file oldFile to the file newFile.
cp file directory Copy a file into a directory.
rm file Remove (that is, delete) a file. THERE IS NO TRASH CAN, NO RECYCLE BIN, AND NO "UNDELETE" COMMAND--SO BE CAREFUL WHEN YOU USE RM.
cat file Print the file's entire contents to the screen, all at once. For big files, you'll want to use more file. The name "cat" comes from the word "concatenate," which means to string two or more things together, one after the other. You can use the cat command to do just that by typing cat file1 file2 file3 or similar commands.
more file Print the file on the screen, one window's worth at a time. While you're using more, the spacebar will move you forward one screen, b will move you back one screen, the return key will move you forward one line, /something will move you to the next line that contains "something," and q will quit.

Command shell goodies

The command shell is the program that prints the prompt and executes your commands. There are several common command shells, but the one you will be using on our version of Linux offers several extra features that can make your life easier.
!! Execute the previous command again.
!something Execute the most recent command that began with "something."
<ESC><ESC> If you have typed enough of a file name to uniquely identify the file, pressing the escape key twice will complete the file name for you.
* The * represents any string of characters. Thus, ls b* will list all files whose names start with b. (UNIX is case-sensitive with respect to file names, by the way, so ls b* will not list files whose names start with B.) Similarly, ls *b* will list all files whose names contain a b.

A few more handy commands

diff file1 file2 Prints a summary of the line-by-line differences between the two files.
wc file Prints the number of characters, words, and lines in the file. Read the man page to learn what wc thinks a "word" is.
telnet, finger, ftp These and many other commands provide powerful tools for using the Internet without a mouse.




Jeff Ondich, Department of Mathematics and Computer Science, Carleton College, Northfield, MN 55057, (507) 646-4364, jondich@carleton.edu