tutes-dump/dump/node5.html.docuwiki

234 lines
18 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[[node6.html| {{../img/latex2html/next.png?37x24|next}}]] [[unx.html| {{../img/latex2html/up.png?26x24|up}}]] [[node4.html| {{../img/latex2html/prev.png?63x24|previous}}]] [[node1.html| {{../img/latex2html/contents.png?65x24|contents}}]] [[../|{{../img/latex2html/root.png|root}} ]]\\ ** Next:** [[node6.html|5. Learning More]] ** Up:** [[unx.html|Introduction to Unix &]] ** Previous:** [[node4.html|3. What is Unix?]]   ** [[node1.html|Contents]]**\\ \\ [[|**Subsections**]]
* [[#SECTION00510000000000000000|4.1 The Command Line Shell]]
* [[#SECTION00520000000000000000|4.2 Listing Files]]
* [[#SECTION00530000000000000000|4.3 Moving Around the File System]]
* [[#SECTION00540000000000000000|4.4 The VI Cursor Commands]]
* [[#SECTION00550000000000000000|4.5 E-mail]]
* [[#SECTION00551000000000000000|4.5.1 mutt]]
* [[#SECTION00552000000000000000|4.5.2 Graphical E-mail Readers]]
* [[#SECTION00553000000000000000|4.5.3 My Own E-mail]]\\
* [[#SECTION00560000000000000000|4.6 Viewing Files]]
* [[#SECTION00570000000000000000|4.7 Surf the Web]]
* [[#SECTION00580000000000000000|4.8 Upload & Download]]
* [[#SECTION00581000000000000000|4.8.1 FTP]]
* [[#SECTION00582000000000000000|4.8.2 scp]]
* [[#SECTION00583000000000000000|4.8.3 rcp]]
* [[#SECTION00584000000000000000|4.8.4 When FTP Doesn't Work]]\\
* [[#SECTION00590000000000000000|4.9 Editing Files]]
----
====== \\ 4. Some Basic Commands ======
====== [[| 4.1 The Command Line Shell]] ======
When you login to a unix system, you'll be on a command line. It'll have a prompt like ``"$"'' or ``"bash-2.04$ "'' or maybe ``"%"''. There are other variations.
The command line is how you communicate with the //shell//. The shell is a program that reads commands from a command line & runs other programs. It does some other things, but they are mostly details. The main point of a shell is to run programs.
The traditional, original shell on unix is called the Bourne shell. If you're wondering why it's called the Bourne shell, ask yourself who might have written it.
The Bourne shell program is named "/bin/sh", but that program on most modern unices is actually a pointer to the Korn shell or the Born Again shell. Those two shells are more modern than the Bourne shell, but they are backward compatible with it.
There are other shells, including C shell ("/bin/csh") & the restricted shell. You can change your shell on many unices with the "chsh" command. Since a shell is just a program, no magic behind it, you can use damned near any program you want as your shell. You could use Perl as your shell, I've used clisp as a shell (just for an experiment), or you could write your own shell.
The important thing about a shell is that most of the things you type to it are interpreted as requests to run a program. If you type ``"ls"'', you're asking your shell to run a program called //ls//. If you type ``"bogie -k lap -f lap woo woo -d hickie"'', you're asking it to run a program called //bogie// with all that other crap as //command line arguments//.
Enough about shells for now.
====== [[| 4.2 Listing Files]] ======
On unix, the //ls// program gives you lists of files.
If you just type ``"ls"'', you'll get a list of the files in the current directory. Like this:
bash-2.04$ ls
#unx.tex# RCS unx.aux unx.bbl unx.blg unx.log unx.tex unx.tex~ unx.toc
bash-2.04$
Notice that //ls//, when used in this plain way, doesn't show you files sizes or permissions or anything like that. Unix is traditionally tery terse. Programs show you only the information you requested, plus error messages. You don't have progress messages like ``2003-12-06T16:16 beginning to read files'' and ``2003-12-06T16:17 reading first file'' and other nonsense cluttering your screen. The programs just print what's important.
If you want //ls// to print the details about the files, give it the ``"-l"'' option. That's a minus sign ("-") followed by a letter //el// ("l"). Like this:
bash-2.04$ ls -l
total 52
-rw-r----- 1 gene gene 9181 Dec 6 16:18 #unx.tex#
drwxrwx--- 2 gene gene 4096 Dec 6 14:03 RCS
-rw-rw---- 1 gene gene 1390 Dec 6 14:47 unx.aux
-rw-rw---- 1 gene gene 49 Dec 6 14:47 unx.bbl
-rw-rw---- 1 gene gene 878 Dec 6 14:47 unx.blg
-rw-rw---- 1 gene gene 4201 Dec 6 14:47 unx.log
-rw-r----- 1 gene gene 6387 Dec 6 14:47 unx.tex
-rw-rw---- 1 gene gene 1212 Dec 6 13:49 unx.tex~
-rw-rw---- 1 gene gene 658 Dec 6 14:47 unx.toc
bash-2.04$
The first column, which has all those minus signs, //r//s, &amp; //w//s, shows the [[http://www.dartmouth.edu/~rc/help/faq/permissions.html|file permissions]]. The next column is the number of links to the file.[[footnode.html#foot89|<sup>4.1</sup>]] The next column is the user who owns the file. The next is the group of the file. Then there's the number of bytes in the file. Then the date the file was modified. Then the file's name.
Here's an exercise: Type ``"echo *"'' on the command line, like this:
bash-2.04$ echo *
#unx.tex# RCS unx.aux unx.bbl unx.blg unx.log unx.tex unx.tex~ unx.toc
bash-2.04$
Now go figure out why or how //echo// differs from //ls//.
====== [[| 4.3 Moving Around the File System]] ======
All unix systems have a file system whose root directory is "/". Your home directory is somewhere inside a directory in the file system. Maybe your home directory is "/home/you" or "/usr/hm0/you" or whatever. The details depend on the unix. To learn your home directory, type ``"echo $HOME"'', like this:
bash-2.04$ echo $HOME
/home/gene
bash-2.04$
Unix has a notion of a //current working directory//. To see what your current working directory is, type ``"pwd"'', like this:
bash-2.04$ pwd
/home/gene/library/website/docsrc/unx
bash-2.04$
To change your current working directory, use the //cd// command. Give it the name of the new directory you want. If you want to move to the current working directory's parent, use ``".."''. Here are some examples:
bash-2.04$ pwd
/home/gene/library/website/docsrc/unx
bash-2.04$ cd .. # move to parent
bash-2.04$ pwd
/home/gene/library/website/docsrc
bash-2.04$ cd .. # move to parent again
bash-2.04$ pwd
/home/gene/library/website
bash-2.04$ cd share # move into the "share" directory
bash-2.04$ pwd
/home/gene/library/website/share
bash-2.04$ cd /tmp # move to this absolute directory
bash-2.04$ pwd
/tmp
bash-2.04$
====== [[| 4.4 The VI Cursor Commands]] ======
[[node5.html#editors|vi]] is an editor, but its cursor-movement commands are often used by other programs. Figure [[node5.html#fig-vi-commands|4.1]] shows //vi//'s cursor-movement commands.
**Figure 4.1:** The cursor-movement commands from //vi//
| {{img2.png?242x99|\begin{figure}\begin{tabular}{\vert r\vert l\vert} \hline {\bf command} & {\bf a... ...ve cursor up \\ \hline l & move cursor right \\ \hline \end{tabular}\end{figure}}} |
The //vi// commands might not make much sense at first, but notice that you can use all of them with the fingers from the right hand. They may not be the most mnemonic commands, but they are very functional.
Some programs besides //vi// which use the //vi// cursor-movement commands include:
* the mail reader called [[node5.html#mutt|mutt]], but just the //j// &amp; //k// keys in its menus
* "/usr/games/worm", an old game &amp; an excellent way to learn the //vi// commands
* VIPER, a //vi//-emulator for [[node5.html#editors|emacs]]
====== [[| 4.5 E-mail]] ======
Most unix systems give you multiple options for how to read your e-mail.
If you want to read your e-mail with a text-only program you run from the command line (which is how I read e-mail), some common programs are //mutt// and //pine//. Just type the name of either of those programs. If you see a list of e-mail, it means the program is available, &amp; you are running it. If you see an error message that says ``command not found'', it means your shell couldn't find it, maybe because it's not available on your unix.
You can figure out the basics of //mutt// or //pine// just by using them. People become almost religiously devoted to their favorite e-mail programs, so you can learn more detailed or subtle ways of using a mail program by asking someone who prefers that program. People are usually happy to tell you more than you want to know about how to use their favorite e-mail program. So pick one of them, figure out the basics on your own, &amp; then go find a long-time user of that program &amp; strike up a conversation about it with him.
I've never used //pine//, so I can't tell you how. I sometimes use //mutt//, so here is some super-quick info on using //mutt//.
===== \\ 4.5.1 mutt =====
The official documentation about //mutt// is at http://www.mutt.org/.
When you run //mutt//, you'll see a list of e-mail messages. Each line on your screen will show a subject, a date, &amp; who sent the message.
One of the messages will be selected. To view the selected message, type the Return, Enter, or Space-bar key (I can't remember which). You'll see the body of the message.
When you are viewing the body of a message, type the Space bar to page down. When you come to the end of the message, type the Space bar to view the next unread message. If there are no more unread messages, you'll see the list of messages again.
When you are viewing the body of a message, you can type ``"q"'' to quit that view &amp; return to the list of messages.
In the list of messages, the ``"j"'' key moves the cursor down &amp; selects that message. The ``"k"'' key moves the cursor up &amp; selects that message. The ``"q"'' key exits //mutt//.
===== [[| 4.5.2 Graphical E-mail Readers]] =====
If you want to read your e-mail with a graphical e-mail reader, maybe the one in your web browser, you'll need a more elaborate setup. You'll need to instruct your mail client to use your unix account for sending &amp; receiving messages. It sends messages via the Simple Mail Transport Protocol (SMTP). It downloads messages that you receive via the Post Office Protocol version 3 (POP3). Of course, the unix system where you have your account must be configured to allow these operations. You'll need to refer to the documentation for that computer system to do all this, but it can be done if the unix system allows it.
===== [[| 4.5.3 My Own E-mail]] =====
For the record, I usually use the //rmail// mode in Gnu Emacs for reading &amp; sending e-mail.
====== [[| 4.6 Viewing Files]] ======
If you have a file you want to read, use the //less// program to read it. For example, if the file is called "README" &amp; is in your current directory, type ``"less README"''. If that gets you a ``command not found'' error, try ``"more README"''.
You'll see the first part of the file on your screen. (If it's a really short file, you'll see all of it on your screen.) To see the next screen-full, type the Space bar. To see the previous screen-full, type the ``"b"'' key. To quit viewing the file &amp; return to the command line, type the ``"q"'' key.
====== [[| 4.7 Surf the Web]] ======
A good web browser to use on a text-only command line is //lynx//. You can give it an URL to read on the command line, like this: ``"lynx http://lisp-p.org/"'' or ``"lynx http://google.com/"''. Use the Space bar to page down, the ``"b"'' key to page up, the arrow keys to select hyperlinks, &amp; the Return or Enter key to follow a hyperlink. Use the ``"q"'' key to quit.
Unless the unix system where you have an account is very trusting, you probably cannot run a graphical web browser on it. Technically it can be done using the graphical system called X (which is common on unices), setting permissions with the //xhost// program, &amp; setting your DISPLAY environment variable, but it usually is not allowed on a public access unix.
====== [[| 4.8 Upload &amp; Download]] ======
===== \\ 4.8.1 FTP =====
To transfer files between your home computer &amp; a remote unix, use the program called //ftp//. Your home computer almost certainly has a copy, even if you run Microthought Winders at home.
To run //ftp//, first go to a command line. Then type ``"ftp ftp.freeshell.org"'' to connect to the FTP server at SDF.
The //ftp// client has a command line interface. Here are some of the commands it understands:
**cd //directory//**Change directory on the remote FTP server. **dir**Print a lsit of the files in the current directory on the remote FTP server. **ascii**Tell FTP to assume that files you transfer are text files. **binary**Tell FTP to assume that files you trnasfer are binary files. **hash**Tell FTP to print an octothorpe character (#) for each block it sends or receives. It helps you see the progress of the file transfer. **put //filename//**Upload a file. **get //filename//**Download a file.
In general, use the //cd// command to enter the correct directory on the remote FTP server. Then set the correct mode (//ascii// or //binary//). Then use //get// to download a file or //put// to upload one.
The //ftp// client program supports many more commands. Use ``"man ftp"'' for more information about FTP.
In case you are interested: FTP refers to the File Transfer Protocol; it was one of the three requirements that created the Arpa Net which became the Internet. //Ftp// is also the name of the File Transfer Program which implements FTP.
===== \\ 4.8.2 scp =====
//scp// is the Secure Shell Copy Program. It's name is also a reference to //rcp//, the Remote Copy Program.
Use //scp// like you would use //cp//, but it can copy from one computer to another.
For example, if I want to copy "myfile.cpio.bz2" on my computer into the "tmp" directory in my account on SDF, I would run this: ``"scp myfile.cpio.bz2 gms@freeshell.org:tmp/"''. The //scp// program will probably prompt me for my password, then it will copy the file.
Run ``"man scp"'' to get more information about using //scp//.
In my experience, //scp// takes longer than //ftp// to transfer files, &amp; it gives up easily. If either computer or the network is slow, //scp// gives up quickly. So I prefer //ftp//.
Ed Chang has told me that there is an implementation of //scp// for Microthought Winders called WinSCP, at http://winscp.sourceforge.net/eng/about.php. I haven't tried it myself, but it sounds like it might be pretty good.
===== \\ 4.8.3 rcp =====
You can't use //rcp// on SDF, so this section applies when copying files between other unix systems.
An old but pretty cool program for copying files between two unices is //rcp//, the Remote Copy Program.
For //rcp// to work, you must first configure the ".rhosts" files in your accounts on the unix systems. Then you can copy files from one system to another with the //rcp// program.
For example, if I want to copy "myfile.cpio.bz2" on the local computer into the "tmp" directory in my account on a computer called "overthere", I would run this: ``"rcp myfile.cpio.bz2 overthere:tmp/"''. The //rcp// program will copy the file; it won't ask me for my password.
===== [[| 4.8.4 When FTP Doesn't Work]] =====
If you don't have FTP on your home computer, you can transfer files via e-mail.
First, make sure you have an e-mail account that allows you to send files as attachments. You might use the e-mail account that your ISP supplied with your Internet connection, or you might create a Web e-mail account on Yahoo!, Hotmail, or any of the many other systems that provide free Web e-mail accounts.
To transfer a file from your home computer to SDF, you create an e-mail message on your e-mail account that is //not// on SDF. Attach the file; with a Web e-mail account, it'll allow you to upload the file into the e-ail message. Then send the message. Give it a minute to arrive, then login to your account on SDF. Receive the message with an e-mail program which knows how to deal with attached files. Mutt &amp; pine both know about attachments. Use that e-mail program to save the attachment to a file.
To transfer a file from SDF to your home computer through e-mail, login to SDF &amp; send the file to your non-SDF account as an attachment to an e-mail message. Then receive the message on your non-SDF e-mail account &amp; save the file to your home computer's file system.
====== \\ 4.9 Editing Files ======
There are two great religions in the modern world: //emacs// and //vi//.
The two most popular file editors on unix are //emacs// and //vi//.
//Emacs// is more properly called Gnu Emacs because emacs is a way of programming file editors, &amp; Gnu Emacs is just one editor written in that way. I believe Gnu Emacs was the first big production product of Gnu. Richard Stallman wrote it himself. It is a Lisp with screen-handling functions built-in. It's a great big powerful editor, an operating environment, &amp; I love it. To try emacs, type ``"emacs"'', wait for the screen to update, then type the Escape key, the "x" key, then ``"info"'', then press Return. Carefully read &amp; follow the instructions you see on the screen. It's kind of difficult to learn emacs from the start, but once you do, it's great.
The other popular editor on unix is //vi//. I don't use vi much. Two web sites that discuss it are [[http://www.eng.hawaii.edu/Tutor/vi.html|Mastering the VI editor]] at the Department of Engineering at the university of Hawaii, and the [[http://www.thomer.com/vi/vi.html|Vi Lovers Home Page]].
----
[[node6.html| {{../img/latex2html/next.png?37x24|next}}]] [[unx.html| {{../img/latex2html/up.png?26x24|up}}]] [[node4.html| {{../img/latex2html/prev.png?63x24|previous}}]] [[node1.html| {{../img/latex2html/contents.png?65x24|contents}}]] [[../|{{../img/latex2html/root.png|root}} ]]\\ ** Next:** [[node6.html|5. Learning More]] ** Up:** [[unx.html|Introduction to Unix &amp;]] ** Previous:** [[node4.html|3. What is Unix?]]   ** [[node1.html|Contents]]**
Gene Michael Stover 2005-07-07