CS 117
Spring 1998
A Few UNIX Commands
Getting documentation
- Type man ls to read the documentation describing ls,
man man to read about man, etc.
- For a list of many of the available commands, you can list the
directories where they are stored: ls /bin, ls /usr/bin,
and ls /usr/local/bin, for example. If you're obsessive,
you could spend a lot of time with these lists and man.
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.
- 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: make a new directory.
- rmdir: remove an existing directory.
Files
Many of these commands also apply to directories.
- ls: List the contents of the current directory.
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's no
"undelete" command, so be careful.
- cat file: "Concatenate" the file--that is, print its entire contents to the screen, all at once. For big files, you'll want to use more file.
- 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.
- !!: Execute the previous command again.
- !something: Execute the most recent command that began with "something."
- <ESC>: If you have typed enough of a file name to uniquely identify the file, pressing the escape key 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.
Jeff Ondich,
Department of Mathematics and Computer Science,
Carleton College, Northfield, MN
55057,
(507) 646-4364,
jondich@carleton.edu