### ##### #### # # ### ##### # # # # ## # # # # # # # # # # # # # # # # # # # # # # # # # ## # ##### #### # # # ##### ## # # # #### # # # # ## # # # # # # # # # # # # # ##### ###### # # # # # # # # # ## # # # # # # # # # #### INTRODUCTION TO UNIX COMMANDS by Mark Galassi Note: this document might be found on the computer you are using, in the file "/usr/local/doc/unix_intro". "ls" (list) will show which files are in the current directory. You can also specify a directory to list. Example: "ls /usr" will list the directory /usr. "ls -l" (long list) will give lots of information on the files, such as the size, read/write/execute permissions, who the owner is and whether the file is a directory. "who" tells you who is logged in to the same computer. To also see what they are doing, type "w". "more file" will display what is in the file. It prompts you for each new screenful. Example: "more /etc/passwd" will show you the password file, with everybody who has a login on the system. Example: "more /usr/doc/unix_intro" will display this file you are reading right now! NOTE: many systems have another paging program called "less" (yes, it's a pun). Less has more features, and is useful for going backwards from a certain point. "cp file1 file2" will make an identical copy of file1 with name file2. IMPORTANT: if file2 already exists, it will be clobbered. "mv file1 file2" will rename file1 to file2. file1 will cease to exist, and file2 will be what file1 used to be. IMPORTANT: if file2 already exists, it will be clobbered. "mv file directory" will move the file from the current location to the given directory. You can move many files with the same command "mkdir dirname" will make a new directory called "dirname", within the current directory. "cd directory" will change to a given directory. "directory" can be a subdirectory of your current directory, or an absolute path (which could look like /usr/bin). Example: "cd /usr/local/src" will put you in the directory /usr/local/src. "cd" without arguments will bring you to your home directory. "passwd" will allow you to change your password. It will prompt you with the right questions, and is easy to use. "grep name file" will look for all lines in "file" with the string "name" in them. This is incredibly useful if you are looking for something. You can also specify lots of files, and grep will search each one. Note: "grep -i" ignores upper-lower case distinctions, "grep -n" tells you the line number. Example: "grep markgalassi /etc/passwd" will tell you about people with login "markgalassi", for example what their home directory is. Here is the result of doing that on my computer: markgalassi:x:1000:1000:Mark Galassi,,,:/home/markgalassi:/bin/bash Example: "grep -i gravity *.tex" will tell you in which of your TeX documents you used the word "gravity" (or Gravity, or graVity etc...). "Mail" reads your mail. It shows a list of messages with message numbers. To look at message 2, just type 2 and so on. To save a message to a file (for example to save message 3 to file "john", type "s 3 john". To delete message number 6, type "d 6". To quit from reading mail, type "q", and you will be back at the shell prompt. Useful detail: at the mail prompt (usually a '?'), you can type '?' (question mark) and get a little help screen. NOTE: on some systems this is called "mailx" or "mail". Also NOTE: this program is obsolete for ordinary email use, but it can still be used to automate the sending of mail to people from a program or script. "mail user" sends mail to a given user. You are prompted for a subject, and then you can type your message. To send the message off, type "control-D" on a line by itself. The message will then be delivered to the user. Example: "mail markgalassi" will send mail to me on the local machine. Do this if you need help, or just to say "Hi!". "Mail user@host.DOMAIN" sends mail to a user on another host. You can also specify what network that person is on with the ".DOMAIN". Example: "Mail mark@galassi.org" or "Mail markgalassi@gmail.com" will send mail to me (!) at these two internet addresses. Domain names that end with .edu .com .gov and .mil are usually on the internet. Example: "Mail user@host.BITNET" will send mail to a user on a BITNET node. [NOTE: BITNET is now almost entirely dead.] Example: "Mail user@host.UUCP" will send mail to a user on a UUCP node. [NOTE: UUCP is now almost entirely dead.] "mutt" is a more user friendly mail program, with many more cute features. It has a built-in help system also. You must learn to use a text editor (preferably emacs) when you send mail with mutt. "man command" gives a detailed description of that command. The "man pages" (as they are called) are quite terse, but they give all the information. On some UNIX systems, to look for a certain topic in the manual pages you can say "man -k keyword" or "apropos keyword". "emacs file" is a most powerful editor. You can type just "emacs" and it will tell you how to get a tutorial. Knowing how to use a text editor is an absolute necessity. "lpr file" will print a file on the default printer. If there are several printers available on your computer you can specify one with "lpr -Pprintername file". THINGS TO BEWARE OF Some characters can have special meaning. Be careful when you use them, and use them only if you know what you are doing. Here is a list of some of them, and what they might do to you. Of course, you can change the character that does a given thing using the "stty" command. Most of these are control characters, and by ^ will mean that you type the control key and the char together. For example, ^D. ^D (End Of File char) might log you out, and terminates some programs (such as sending mail on the command line). ^\ (QUIT char) sends a QUIT signal to the process. It will terminate the program and dump core. ^C is the standard interrupt character. You can use it to stop many programs (unless the program makes provisions to avoid that). ^U (kill char) kills all text on the line you are typing. ^H (erase char) is usually the same as backspace. ^S is the "hold screen" character. It will suspend output until you type a ^Q to resume. WHEN YOU ARE STUCK ... If you find that you type carriage return and nothing happens, it usually means that you have interrupted the computer while running a program that did special stuff with your screen (such as a text editor, or a spreadsheet). The best way to fix the problem is to ask some expert if there is one close by, but you can usually fix these by typing ^J (control-J), followed by "stty sane", and another ^J. This will USUALLY (not always) put your terminal in a "sane" mode again: characters will be echoed and so on.