Takes you to [directory]. Typing "cd" without any arguments will take you back to your home directory. "cd ." keeps you in the same place and "cd .." will take you one level up. There must be a space between cd and the directory name. Directories that do not begin with a '/' are referenced relative to the current directory, as if it began with './'; directories that begin with a '/' are referenced relative to the root directory. So, if I was in my home directory and I wanted to change to a subdirectory named 'data', I could enter "cd data" or "cd ./data" or "cd ~/data" or "../jcjai/data" or a lot of other possibilities.
chmod [permission level] [file-list]
OK, this one requires a little more explanation. Each file has three levels of permissions set on it and each level has three types of protection. When you "ls -al", you see these permissions in the first ten columns. A typical line from a 'ls -al' output might look like:
-rwxrw-r-- 1 jcjai users 1453 Jul 9 09:36 diskuse
This means that the file named 'diskuse', was created on July 29, at 9:36, the owner is jcjai and it belongs to the group users. This information will be useful in the next section. The size of the file is 1453 bytes. For the 'chmod' command, it's the first ten characters that's important. The first column will have a 'd' in it if the item is a directory and an 'l' if it's a link. The next nine represent the read, write, and execute permissions for the user, the group, and the rest of the world, respectively. So in the example, the file diskuse can be read, edited, and executed by jcjai. It can be read and edited by the group users and it can be read by everyone else. To change these file permissions, use the 'chmod' command.
There are two ways to use 'chmod'. The first has the form: chmod (ugoa)(+-=) (rwx) [file-list]. In this form, u stands for user, g stands for group, o stands for other, and a stands for all three (ugo). + means to add the permission, - means to remove the permission, and = means to set only that permission and remove all others. r is for read permission, w is for write permission, and x is for execute permission. So, to remove group and global write permission for the file diskuse, I would enter "chmod go-w diskuse". There are also two related system-wide aliases, '+rx [file-list]' and '+x [file-list]. The first is the same as 'chmod a+rx [file-list]' and the second is the same as 'chmod a+x [filename]'.
The other method sets a file permission for all three levels at the same time, overwriting any previously set permissions. In this method, each level of permission has a number from 0-7 associated with it. The number is the sum of 1 for execute permission, 2 for write permission and 4 for read permission. Thus, 6 is read and write permission and no execute permission. Three of these numbers form the entire file permission, the first for user, the second for group, and the third for others. So, 644 would be read and write for the user, and read for the group and all others. Thus, to change diskuse to be readable, writable and executable for me, readable for the group and nothing for everyone else, I would enter "chmod 740 diskuse".
cp (-ir) [source] [destination]
Copies the [source] file to [destination]. In general, [source] should be a file and [destination] should be a directory. The destination directory must already exist.
| -i | prompts for confirmation before overwriting an existing file |
| -r | recursively copies everything in [source] (a directory in this case) to [destination] (also a directory), creating new subdirectories as necessary |
grep (-iv) [pattern] [file-list]
Searches [file-list] for [pattern]. This is useful for finding some expression in a bunch of files. 'grep' searches for an expression that contains [pattern], so "grep foo *" would return all the lines in all the files that contain foo or anything with foo in it, for example foobar or foofoo. The [pattern] can also be enclosed in single quotes (') to restrict the search. Thus, "grep ' foo ' *" would only return the lines in all the files that contain foo as an isolated word. The pattern cannot contain special characters like * or /, so wildcards do not work. However, 'grep' will match any characters enclosed in square brackets. So entering "grep [Cc]arrot foo.bar" would find Carrot and carrot. Entering "grep [A-Z]arrot foo.bar" would find anything that starts with an uppercase character and is followed by 'arrot', such as Parrot or Tarrot. A period will match any single character (like ?) and a caret indicates any character except those in brackets, so [^0-9] matches any non-numeric character. The 'grep' commands are actually very, very powerful and are far more extensive than what is presented here. They can do some pretty cool tricks. Please read the appropriate man pages for more details.
-i ignores any distinction between upper and lower cases
-v inverts the search to find all lines that don't contain
[pattern]
Lists information about the files in [file-list]. The file-list can be filenames or directories and can include wildcards. If a directory is specified, ls will show information about the files in that directory. When the file-list is omitted, ls displays information about the files in the current directory. There are more tricks to 'ls' than you might imagine and there are also many more options than listed here. See the man page for more info.
| -a | lists ALL of the files in the file-list including hidden files. All files that begin with '.' are hidden and can only be listed with ls -a (or dir -a). |
| -d | lists only the directory names and not the contents. This can be useful in some situations. Say that you have two subdirectories, one named 'temp' and another named 'test'. If you just enter "ls te*", then you will get a complete file list from both 'test' and 'temp'. If you are only interested in seeing whether those two directories exist, then you can enter "ls -d te*" and it will only display the two directory names and not their contents. |
| -l | lists the files in a long format |
| -R | lists recursively, displaying all the files in the file-list as well files in the subdirectories of the file-list and their subdirectories and so on and so on... |
Creates a subdirectory named [directory] in the current directory.
Displays a file to the screen, one page at a time. In the 'more-environment', there are several commands, here are some of the most commonly used ones, see the man page for more commands:
(n)SPACEBAR displays n more lines. Just SPACEBAR advances one
screen.
ENTER skips one line forward.
"q" exits from 'more'
"h" displays a help screen
(n)"f" skips n screens backwards
(n)"b" skips n screens backwards; "b" will go
back one screen
(n)"/"[exp] searches for the nth occurrence of [exp]
"d" advances half a screen
"=" displays the current line number
mv (-i) [source] [destination]
Moves the [source] file to [destination]. It operates like 'cp' followed by 'rm', but there is no backup file when the [source] file is removed. This command should only be used for moving files on the same filesystem (which should not be a problem for most people, so don't worry about it).
-i prompts for confirmation before overwriting an existing file
Shows you the current working directory, '.'.
Erases the files in [file-list]. If you enter "rm *", it will delete all of the files in the current directory, except for those which begin with a '.'. These hidden files can only be deleted by entering "rm .*".
-i causes the system to prompt for confirmation before deleting
each file
-r deletes all files recursively, so files in subdirectories in
the file-list are also deleted
Removes empty directories. The directory must be empty before it can be removed. Note that this means there cannot be any hidden files either. If a directory refuses to be removed, check for hidden files with 'ls -a [directory]'.
Sorts the text files in [file-list], line by line. The output is sent to the screen by default, unless redirected (see '>' below) or with the '-o' option. The sort is in ASCII order, so it treats upper and lowercases as different with uppercase characters coming before lowercase ones. Punctuation marks also have values in this scheme.
| -b | ignores leading and trailing blank spaces |
| -c | checks to see if a file is already sorted. If a file is already sorted, the operation aborts. |
| -d | sorts in dictionary order, ignoring punctuation |
| -f | considers all lowercase characters as uppercase |
| -M | selects the first three nonblank characters, converts them to uppercase and sorts the lines in month order. |
| -n | sorts in numeric order, with negative and decimal values |
| -o[file] | stores the output in [file] |
| -r | reverses the sort direction |
| -u | eliminates duplicate lines in the output. Identical lines in the input file are only output once. |
By default, 'tail' displays the last ten lines of a file. Use the options to change this.
+[number] starts displaying [number] lines from the top of the
file
-[number] displays the last [number] lines of the file
Creates a tape archive file. This command is like 'zip', but without any compression. It creates a single file that contains all the files in [file-list]. By default, the 'tar' file is created on a tape device, unless the '-f' option is used.
-c creates a new 'tar' file, overwriting any existing file by
the same name
-f [filename] specifies a [filename] for the 'tar' file
-r appends [file-list] to an existing 'tar' file
-t lists the contents of the 'tar' file
-v sets verbose mode which shows each file as it's archived or extracted
-x extracts [file-list] from a 'tar' file
-z compresses or expands the 'tar' file with 'gzip'
and 'gunzip'
-Z compresses or expands the 'tar' file with 'compress'
and 'uncompress'
If I wanted to tar all of the files in my account into one 'gzip'ped archive, I would enter "tar -cvzf jcjai ~/" and it would create a file named 'jcjai.tar.gz'.
Displays the amount of disk space used by directories. Without any arguments, 'du' will display the amount of disk space, in kbytes, used by each subdirectory in the current directory.
-a displays totals for all files and subdirectories
-s gives the sum of the disk space
To figure out how much total disk space you are using, type "du -s" in your home directory.
alias (aliasname) (definition)
Defines, what else, aliases. These are basically your own custom shortcuts to commands. Without any arguments, 'alias' gives you a list of the currently defined aliases. 'alias [aliasname]' shows you what [aliasname] is currently defined as. 'alias [aliasname] [definition]' sets [aliasname] to do [definition]. The [definition] can be any single command with whatever options. If the definition includes a space, then the whole definition should be enclosed in single quotes (').
There are three major uses for this. First, you can redefine some very common commands to something shorter. Perhaps you use Netscape a lot and would rather just type "n". Then, just enter "alias n netscape" and voila! Just to be safe, it is usually wise to verify that the alias doesn't exist by entering "alias n". Second, there may be a command that you prefer with certain options. For example, I like 'enscript -2rG' and have it aliased to just 'enscript'. This is done with "alias enscript 'enscript -2rG'". Third, aliases can be used to get rid of long paths. While most applications should be in the path, one way or another, you may find one that's not. In this case, you can define an alias to include the path. For example, there may be a code that's run with '/apps/unsupported/foo/bin/sun4/foo' and it can't be found in the path. You can alias it to just 'foo' with "alias foo /apps/unsupported/foo/bin/sun4/foo".
Note that aliases defined from the command line only live as long as that login session is open. To make aliases that are defined every time you login, add them to your ~/.aliases file.
bg [job number]
fg [job number]
Sends jobs to the foreground or background. Jobs must be identified by the job number (found with 'jobs'). Without any arguments, both 'fg' and 'bg' send the current job to the foreground or background, `respectively. The 'bg' command is most useful for sending a job to the background if you forget to add '&' to some command when running it.
POWER TIP: If you are running something interactively in one window and need some information from another file, you don't have to open another window. Just hit "Ctrl-Z" to suspend the current job, get the information you need, and then hit "fg" to resume the program from where you left off.
Ends the life of a poor, hard-working process. Use this command to ruthlessly slaughter innocent jobs. This can be useful if a job goes out of control or gets stuck in an infinite loop. The pid can be found from the 'ps' output. -signal can be used to kill jobs that just won't die. If plain old "kill [pid]" doesn't work, then try "kill -15 [pid]" and if that doesn't work, try "kill -9 [pid]". 'kill -9' should kill virtually any job. Please do it in this order. What if the job had a wife and kids?
Sets the priority for jobs on the computer. By default, when a command is run, it has a nice value of 0. A higher value will lower the priority of the job and slow it down, but free up system resources for other jobs. Computationally-intensive jobs should be run with "nice +19 [command]" when in batch mode, and "nice +10 [command]" when in interactive mode.
Displays information about active processes. Use 'ps' to get the process ID (pid) number for a job. You will need the pid to kill a job.
-a displays information about all processes including ones that
are owned by other users
-u displays more information in a full display
-x displays information about processes not associated with terminals
Displays the processes running on a computer in the order of highest resource use to lowest. The job using the most CPU power is displayed at the top. The process ids and nice levels are also shown. Hit "q" to quit 'top' and "i" to toggle the display of idle processes. Use 'top' to see if there are any jobs slowing down the computer.
For printing out files. The files can usually be of any kind, the printer should be smart enough to figure out what kind of file it is.
| -P[printer] | specifies which [printer] to send to. If no printer is specified, the default printer is assumed. |
| -#[number] | specifies the [number] of copies to send |
Show the status of the printer and any jobs that have been sent to it. It also shows you the job number which is needed if you wish to kill a print job.
-P[printer] specifies the [printer] you want information on.
Kill print jobs that have already been sent. The job number can be found with 'lpq'.
-P[printer] specifies the [printer] on which to kill the job
- for the job number kills all of your jobs that were sent to the
specified printer
compress [file]
uncompress [file]
Compresses [file] to use less disk space. The old file is replaced with a new with the same name and a '.Z' extension. If the compressed file would not save any room it is not compressed.
Uncompresses a 'compress'ed [file]. The compressed file must have the extension, '.Z'. The uncompressed file is the same name without the '.Z' extension.
Quits a shell. A shell is opened when you log in and each time you open a window. This commands quit one shell and one shell only, so, if you type "exit" in a window, it will only quit that one window.
gzip (-adr) [file-list]
gunzip (-adr) [file-list]
These make or unzip a separate compressed file for each file in [file-list]. The new files have the same names as before with '.gz' added to the end. Like 'zip' and 'unzip', there are many options. I am only including a couple here. See the man pages or type "gzip/gunzip -h" for more information.
-d decompresses [zipfile]
-r recursively stores files in directories in [file-list]
Gives you information about [command]. With '-k', you can specify a keyword and it will find all the commands that have something to do with that keyword. The command descriptions are from the UNIX reference manual (hence the command 'man') and can be somewhat cryptic at times. However, this is the handiest source of online help available.
This command allows you to change your password. You should do this every so often, just to be safe. For your security and the system's, the password should be at least five characters long, shouldn't be a word in the dictionary, and must have at least one non-alphanumeric character in it. This is for your protection and to stimulate your creativity.
Counts the number of character, words, and lines in [file-list].
-c counts just the number bytes
-C counts just the number of character
-l counts just the number of lines
-w counts just the number of words
POWER TIP: 'wc' can be used with 'ls' to see how many files are in a directory. Just enter "ls | wc -l".
There are several wildcard symbols in UNIX:
These can be inside of an argument, for example, a*.exe would include anything that begins with 'a', ends with '.exe', and has anything in the middle. a?.exe would include anything that begins with 'a', is followed by a single character, then ends with '.exe'.
In addition to these two wildcard symbols, square brackets can also enclose a selection of wildcard characters. For example, 'a[ab].exe' would include both 'aa.exe' and 'ab.exe'.
Please note that UNIX IS case-sensitive, so FOO is not the same as foo. If you have a directory named STUFF, then 'cd stuff' will not change to it, only 'cd STUFF' will.
Pipes the output of one program to another program. One common use is with the 'more' command. In some cases, the output of some command exceeds one page and is hard to read as it flies by on the screen, somewhere near the speed of sound. Just 'pipe' the output to more and read at your leisure. For example, I want to 'grep' a file for some phrase and there are lots of lines that contain that phrase. I can pipe the output to more with "grep phrase datafile | more". Technically, '|' redirects standard output from one process to the standard input of the next process.
[command] > [file]
[command] >> [file]
[command] >! [file]
Redirects standard output to [file]. These are like pipe (|), but instead of feeding the output to the input of another command, it stores the output in a file.
> will fail if [file] already exists
>> appends the output to [file] if it already exists
>! will overwrite [file] if it already exists
These can be used with 'echo' to add text to a file. "echo [text] >> [file]" will add [text] to the end of [file].
Redirects standard input to come from [file]. Thus, any input that was expected for [command] will come from [file] instead of the standard input (which is usually the keyboard). This may be useful for some batch type operations.