Lab 7
UNIX II
Objectives:
Learn the usefulness of aliases.
Learn how to find files and programs.
Learn how to run more than one program at a time and switch between them.
Learn about pipes and redirection.
Learn how to socialize with others.
Learn other useful UNIX commands.
alias <name you can remember>="<command you can't remember>"
For example, you can prevent accidental deletion of files with the following alias:
alias rm="rm -i"
the -i means interactive, so the rm command will ask you for comfirmation before deleting a file. If you would later like to bypass the alias (say, because you want to delete 50 files), you can type:
\rm <files>
the backslash tells the system not to use your alias.
Place your alias commands on separate lines at the very end of your .profile or .kshrc. Then log out and log back in.
Finding Things
Finding Files
If you are a disorganized person or just forgot the name of a file created long ago, you can use the find command to find it again.
The generic format is something like:
find <starting dir> -name "<wildcardname>" -print
For example, to find all "*.html" files anywhere in your home directory, it would be:
find ~ -name "*.html" -print
However, this will also try to find matches for directories ending in .html. To limit find to strictly files, add "-type f":
find ~ -type f -name "*.html" -print
grep <pattern> <file>
for example, if you have a file named "lamb.txt" containing
Mary had a little lamb,
Little lamb, little lamb.
Mary had a little lamb.
Its fleece was white as snow.
and you wanted to find all lines that contained "Mary", you would type:
grep "Mary" lamb.txt
You would get:
Mary had a little lamb,
Mary had a little lamb.
Read the man pages for more details about grep.
Finding Programs
you would then type the following to run elm:
This command allows you to see which jobs you have started. It works like this:
Just typing "ps" at the prompt tells you which ones you have started in this telnet session.
The output will look something like this:
PID TTY TIME CMD
22740 pts/49 0:00 elm
22718 pts/49 0:02 emacs
22753 pts/49 0:00 sh
22752 pts/49 0:00 man
22754 pts/49 0:00 less
22710 pts/49 0:00 ksh
Control Commands
Note: ctrl means the control key.
ctrl - c
quits some programs. You will use this command a lot when you start writing C programs. ;)
ctrl - z
suspends all programs that do not explicitly try to catch this control command. It is a useful command because you need to suspend the program you are currently running before you can start up another program in the same telnet session.
For example, if you are running elm and want to start up tin without quitting elm, you would type ctrl-z. Then you get your acme prompt back, so you can type "tin". We'll tell you how to get elm back in a minute.
NOTE: pico has some strange annoyances. If you just run "pico" or "pico <filename", you cannot suspend pico with ctrl-z and start up another program. You must run pico as "pico -z" or "pico -z <filename>" to allow suspending with ctrl-z. You can also suspend pico with ctrl-s, but you will not want to. When you suspend pico with ctrl-s, your telnet session will refuse to respond to all keystrokes you type! If you type ctrl-s by accident, type ctrl-q to break out of it.
jobs
"jobs" tells you what programs you are running. If you are not at a prompt, type ctrl-z to suspend your current program. Type "jobs" at the prompt. You should get something like
[3] + Stopped (SIGTSTP) man man
[2] - Stopped (SIGSTOP) elm
[1] Stopped (SIGTSTP) emacs
The number on the left tells you the job ID number. Read on to find out how you would get a program back.
fg and bg
"fg" stands for foreground. You can put a suspended program in the foreground by typing
fg %<jobID>
So if you want to get elm back in the above example, you would type
fg %2
"bg" stands for background. When you suspend a program, it is not running anymore. However, sometimes you might want a program to actually run in the background while you run another program. To put a suspended program in the background, type
bg %<jobID>
So using the above example, if you want to put emacs in the background, you would type
bg %1
If you know that you would like to start a program in the background, you can put an "&" after the program name. For example, typing
elm &
will start elm in the background. To put it in the foreground, use the "fg" command.
It will tell you who is hogging the system resources and making your life miserable.
kill
If a program has gone berserk and is no longer responding to you, you can kill it! And, unlike in Windows, the program will actually die! This is another very useful command for when you start programming in C.
How to Kill a Program
Type "ps -u gtXXXXX" if you want to make sure the program is gone.
Spying and Socializing
lu
To look up the gt-account of anybody at Georgia Tech, just type
lu <Firstname> <Lastname>
finger
You can check whether someone has read your email by typing
finger gtXXXXX
finger also tells you other interesting info, such as whether that person is online and when he/she logged on.
If you finger your own account, you may notice that it says you have "No Plan." If you do have a plan, sig, or quote you would like everyone to see whenever they finger your account, create a text file called ".plan" and put that in there.
who
To find out where people are logged in from and when they logged in, type "who" at the prompt. Do this now.
w
To find out what other people are doing, just type "w" at the prompt. To see what you are doing, type "w gtXXXXX".
talk
To chat with someone who is online, use talk or ntalk. They work the same way. You use them like this:
talk username@domain
username is gtXXXXX and domain is acmex, acmey, or acmez.
This message will appear on the other person's screen:
Message from Talk_Daemon@acmex.gatech.edu at 15:04 ...
talk: connection requested by gtXXXXX@acmex.gatech.edu.
talk: respond with: talk gtXXXXX@acmex.gatech.edu
If someone requests to talk to you, you will get that same kind of message. To talk with the other person, just do what the message says. Type
talk gtXXXXX@acmex.gatech.edu
Check the man pages for more options.
Note: Think about what you want to say before you start typing. The other person can see what you type as you are typing it!
write
If you just want to send a short message to someone who is logged onto the same machine, use
write gtXXXXX
type your message and end it with ctrl-C.
You can only write to people that are on the same machine. So if you are on acmex and the other person is on acmey, log into acmey before trying to write. Also, writing to someone clutters up his/her screen, so be selective in when you do so. Check what the other person is doing before you start writing all over his/her screen. If someone sends a message and clutters up your screen, redraw the screen with ctrl-L.
mesg
When you are tired of random people asking to talk to you and writing messages across your screen, you can turn messages off with
mesg n
To turn them back on, use
mesg y
Almost there...