UNIX Notes

Thursday, June 18, 1998 (continued)


alias
Reason for aliases: to make new commands.

alias
-show aliases already set.

alias dir ls -l
-dir is now the alias for the command ls with the option of -l.

alias type cat
-Never make DOS aliases for UNIX commands! Also, use the alias feature sparingly: it doesn't help you learn the UNIX commands and you may unintentionally overwrite an existing UNIX command!

To remove an alias:
unalias type
-removes 'type' alias for cat command.

A bit more useful is creating aliases for more complicated commands:
alias howmany 'who | wc -l'

Upon logout, aliases are lost. However, they can be defined within .cshrc (Don't set them within .login because some other shells don't support aliases.)

diff

diff
-to find the differences in 2 or more files.

diff first second
-shows differences and gives the ed commands to make 1st file look like 2nd. (Ex: 5a 10,11 means "at line 5 append lines 10 and 11.")

uniq

Warning: this is a root level command! (It doesn't check for command permissions.)
Use with caution...
uniq filename1
-shows file with no repetative lines.
For example:
Before uniq: After uniq:
line 1
line 1
line 1
line 4
line 1
line 4

Do NOT perform uniq on two or more files, uless you wish to perform the world's fastest uniq!!

(FYI - in the following command
uniq firstfile >! firstfile, the ! causes the < to override the noclobber feature...)


set filec

set filec
-enables file name completion.

Usage: When referencing a filename from the shell prompt, you can begin typing the filename and, at some point before finishing the entire name, press [ESC] and the filename will be completed with the rest of its name. If there are more than one file that shares a common thread (i.e.: common.chris common.andy common.jim) the file name completion feature will complete the entire common thread then allow the user to complete the unique part of the name.

For example, typing:
co[ESC]
(assuming the afore-mentioned files are in the directory) will produce:
common.
then shell waits for further input, such as:
andy
in order to reference the file common.andy. It would be wise to remember this available feature when creating files in the first place. Just keep in mind that different UNIX systems treat this command in different ways.

tr
tr 'abcd' 'ABCD' < myfile
-looks in the input file myfile and translates (byte by byte) the character(s) in the first argument into the character(s) in the second argument.

Translate works
byte by byte