Sunteți pe pagina 1din 66

The UNIX/Linux environment

Welcome to the multi-user environment of the UNIX operating system. UNIX is a command-line computer operating system that uses client/server technology. This means that the desktop computer is the client connected to the mainframe server. You can write and run programs, send and receive e-mail, read Usenet News, access UNMs library database (LIBROS) and more, from any desktop computer connected to compute services via the UNM Network. When you connect to the UNM Network from a Windows or Macintosh computer, or a dedicated terminal (vt100), using the hostname linux, you are automaticaly connected to the server with the lightest load. These compute servers give you access to the shared network technology at Information Technology Services(ITS). ITS' UNIX environment is comprised of IBM RS6000 machines running AIX 4.3.1. ITS also maintains Linux clusters, each with dual 733 Mhz processors and 1GB of memory. UNIX system services include: the World Wide Web, e-mail, printing, calendar and scheduling, news and mailing list services. E-mail service provides IMAP from eight Linux systems via two Network Appliance File Servers. File services for accounts reside on a Network Appliance 760.

Internet services
You can connect to, and/or use a variety of Internet services from UNIX. Internet services that are supported by UNM are: SFTP Secure File Transfer Protocol. Performs file transfers, usually between a server and a desktop computer, but also between two desktop computers, including computers connected via the Internet. With an anonymous FTP connection, you can access large numbers of electronic archives through the Internet. Lynx A text-based Web browser available through UNIX. Lynx cannot display images or access sound files. Mailing Lists These are electronic discussion groups which use a mailing list format, sometimes called listservs. Mulberry

A powerful, easy to use electronic mail program that offers a complete e-mail system for sending, receiving, storing and printing email, as well as more sophisticated mail functions. You can search your messages, attach files, create multiple address books, and search for addresses on the UNM network. Pine Program for Internet News and Email. A command line email program available from UNIX. Newsgroups Newsgroups (Usenet Newsgroups) are similar to mailing lists because they also cover specialized interests. However, newsgroups are arranged hierarchically, with more narrowly defined topics. World Wide Web The World Wide Web is a huge network of interconnected computers and servers, providing access to text, images, sound and video.

Concepts and terminology


bash shell The UNIX bash shell is a program that acts as a command language interpreter. The bash shell translates command lines that you type into system actions, such as the execution of a program. commands Commands are executable instructions directly input by you. The bash shell reads a typed line, splits it up into the command name and arguments (something that might modify the command), then tells the UNIX operating system to execute the appropriate command program. When the command program terminates, the bash shell shows a prompt (usually $ ) on the screen indicating that the last command has been executed. IMAP Internet Message Access Protocol is a standard protocol for accessing e-mail from a server. Email messages are stored on the server until deleted. Keyboard The keyboard is referred to as a standard input device. Monitor When you type something on the keyboard, it appears on the monitor. The monitor is referred to as standard output. NetID When you run the New program at UNM to sign up for a computer account, the computer asks you for a NetID. When a login prompt appears, or user-ID is requested, you type your NetID for identification. This identification combined with unm.edu becomes your e-mail address (see Chapter 8, PINE). Operating system A computer operating system is the interface between computer users (students, faculty and staff) and the computers hardware and software. The operating

system distributes resources and services among users and controls the execution of programs. The operating system is part of the system software a set of complex computer instructions that manage the resources. Program A computer program is a series of commands and instructions that the computer reads, then uses to perform a task. The computer system does not understand high level languages like Pascal, BASIC, C and FORTRAN. Before the computer can follow a users program, a compiler, interpreter or assembler must translate the program into machine language. Only after translation can the program be executed. Prompt When the computer is waiting for you to type a command, it displays a prompt signifying that it is ready for command. The UNIX prompt is $ (the dollar sign). Other programs can also have different prompts. Shell A shell is a command interpreter that executes the appropriate program according to the command you enter. The shell determines what directories to include in your path. It searches your path, and if there is more than one program with the same name, it executes the program it finds first. There are several shells available on UNIX, including the Bourne shell (sh) and the Korn shell (ksh). Since every new account is initially given the bash shell, this manual assumes that you are using the bash shell command interpreter. SSH Secure Shell is an industry standard protocol for secure access between a desktop computer and a remote server. Both the desktop and server connections are authenticated via a digital certificate and the password is encrypted. SSL Secure Sockets Layer is an industry standard protocol for secure access between a desktop computer (or other portable computing devices) and Web and mail servers. SSL is built into Web browsers and e-mail programs. SSL uses encryption between the desktop and server via a digital certificate. System A computer system refers to the hardware, software, termi- nals and printers anything connected to or running on a computer. UNM network This refers to the series of cables linking many UNM com-munity computers and shared together to create a network that is shared by the entire UNM community. The UNM network is also known as the Campus Data Communication Network (CDCN). URL Uniform Resource Locator. The address of a Web page or site, e.g., http://www.unm.edu In most ITS documentation, the http:// is often deleted because modern browsers understand the address beginning www. You may seem some addresses with

http://, these are addresses that don't require www, but often will not work without http://.

How this document works


UNIX uses client/server technology, which means you can connect from a Macintosh or Windows desktop computer. The key to press on a Windows keyboard to invoke a command is <Enter>. The key to press on a Macintosh keyboard to invoke a command is <return>. To simplify this document, <Enter> is used to indicate both <Enter> and <return>. <return> will appear only in instructions for Macintosh proprietary applications. Similarly, the Control key on the respective Windows and Macintosh keyboards are different, <Ctrl> for the former and <control> for the latter. Again, to simplify this document, the carat <^> is used to indicate both <Ctrl> and <control>. <Ctrl> will appear only in instrustructions for Windows proprietary applications, and <control> will appear only in instructions for Macintosh proprietary applications. <^c> means that you press and hold down the Control key (see paragraph above) and then press the <c> key (then release both keys). You do not need to press the <Enter> key after Control key combinations. Helvetica Italics (or other sans-serif, depending on browser settings) are used for system promps, (e.g., $ ) and for system messages (e.g. Mail sent). Helvetica Boldface denotes input required from the user. For the example, Command: m the user should type m at the Command prompt $. Helvetica Boldface Italic denotes information to be entered that will vary with each user. For example, lookup name, after the command lookup, the user should type a name (in this example a NetID, e.g., tinker) and then press <Enter>. <h> means press the h key only.

Note: UNIX is a case-sensitive operating system, which means that uppercase and lowercase versions of the same letter are interpreted as different characters. It is important that you enter the commands exactly as they are described. To simplify key combination instructions, if an uppercase letter is required it will appear as an uppercase letter, meaning that the <Shift> key (<shift> on a Macintosh) is required to complete the command. For example, <J> means <Shift + J>.

ITS' Computer Pods


ITS operates five pods and nine computer-equipped classrooms on campus for all UNM students, staff and faculty. All pod facilities are staffed by Student computer consultants (Scons) who will assist you with general computing questions. Please note that a valid UNM ID is required to use ITS pods, and only University-related work is permitted in the pods. Pod computers can be both workstations, for tasks such as word processing; and terminal emulators, when connected to ITS' shared network technology. ITS pods are located in the following buildings: ESC Engineering and Science Pod 277-0459 ITS Pod Room 148, ITS building 277-8143 Lobo Lab Room 1012, Student Union Building 277-8825 Johnson Center Room 1114, Johnson Center 277-2004 DSH Pod Room 140-144 , Dane Smith Hall 277-0085 For complete information on locating pods and their services, see the ITS Computer Pod Guide, available in each pod or from the Support Center, in Room 1005 of the ITS building, 2701 Campus Boulevard NE. You can also find pod information online at (its.unm.edu/pods). Services for persons with disabilities Computers allow unique opportunities for the disabled to learn and work. Each ITS pod is equipped with work areas and software to accomodate persons with impaired vision and/or mobility. Check with the scon on duty about these services.

What you need


Create a NetID A NetID is your key to computing and information resources at the University of New Mexico. As a student, staff or faculty member at UNM, your NetID gives you access to

shared systems operated by Information Technology Services (ITS), including a computer account with 50MB of disk space for Web pages, and e-mail folders and mailboxes. Your NetID gives you access to UNMs dial-up lines. In addition, your NetID provides access to most of the UNM General Librarys online databases and indices. Your NetID is for your use during your stay at the University. You start the NetID creation process. A special NetID Creation program is available at the ITS Web site. This program allows you to create your own NetID and password. You can access the program from home or at any ITS computer pod on campus. A scon can assist you with the program. Using any Macintosh or Windows computer in an ITS pod, double click the New NetID icon. Or, start a browser and go to its.unm.edu/new If you want to create your NetID from an off campus location, you must have Internet access and Netscape 4.79 or Internet Explorer 6.0, or higher. The URL (web address) will be the same. Run the NetID Creation program The program will prompt you for some required information for ITS records. You will need to supply your birth date, your UNM identification number, a NetID (the name you with to be recognized by, such as tinker) and a password. If the information you supply does not match University records, you will not be able to create your NetID. The NetID you type will appear on the screen; but the password will not. If the NetID you request is already in use, you must select a different NetID. After you successfully complete the program, your personal account will be ready for you in approximately 15 minutes. You can check the validity of your new NetID and password at that time by logging in to a UNM online service. If you have trouble, please call the ITS Support Center at 277.4848. About Passwords The choice of a good password is important for secure computing. An ideal password is impossible to guess and easy to remember. If someone guesses your password, that person will have complete access to your account to all private electronic mail and information stored there. An intruder can also use your account for illegal activities. Dont pick an obvious name, address, telephone number or initials. Common words should not be used because there are programs that can automatically search through dictionaries and try each Remember, an ideal password is impossible to guess, easy to remember and complex enough so that an automated password cracking program wont reveal it.

Password Basics

Your password must contain no fewer than six and no more than eight alphabetic and numeric characters. abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ Your password must contain at least one numeric or special character surrounded by letters. 0123456789#$_

Your password must begin with a letter. If your password is rejected because it does not meet the above criteria, read the error message and create a password that embeds at least one or more numbers or special characters. Never write your password down, or share your password with anyone. Change your password every month.

Password patterns The following are pattern examples for creating a password. Create your own letternumber-letter or letter-special character-letter combination. ab12yz abc12xyz abcd12yz ab$#yz abc$#xyz abcd$#yz Password Strategies Numbers as letters Use numbers and characters as letters or words. 1 for L, 3 for E, 2 for two, to, too, or Z, 4 for for or fore, 8 for B, be, or bee, C for see or sea, @ for at, zero for oh or O, $ for money or dollar, # for number or pound. Mnemonics Mnemonics uses formulas or rhymes to make it easier to remember a password. The first letters of a phrase or song as a mnemonic password: My four children are wonderful when theyre sleeping would be: M4cawwts Forgotten password

If you are a student and forget your password, but remember your student PIN number and UNM-ID number, you can reset your password online at its.unm.edu/passrenew. At the Student Password Renewal Program page, type your NetID, UNM Student ID number, Student PIN and click Continue. Type a new password and confirm it by typing it again. If you do not remember your UNM Student ID number and PIN, bring your UNM ID to the Computer Accounts Office, Room 2005 in the ITS building and ask a staff person to reset your password. Office hours are Monday through Friday, 8 a.m. to noon, and from 1 p.m. to 5 p.m. For security reasons, the Accounts Office staff will not change passwords over the telephone. If you are a faculty and staff member and forget your password, contact the Computer Accounts Office, 277.8130 or 277.8131 Change your password online To change your password online; go to its.unm.edu/password. At the Password Change Program page, log in with your NetID and current password. You will be prompted to enter a new password, and to confirm it by typing it again. Allow 15 minutes for your new password to activate. You can also change your password in UNIX. Change your password in UNIX See Chapter 2 Connecting to UNIX for instructions for connecting to UNIX and starting an SSH session. Follow these steps after you connect to linux: 1. At the $ prompt, type passwd and press <Enter>. 2. After the message Changing password for your-account-name. Please enter your current password appears, type your current password and press <Enter>. 3. At the New password prompt, type your new password and press <Enter>. 4. At the Retype new password prompt, type the new password that you typed in step 3, and press <Enter>. If both entries match, the following message will appear: Password changed. The change may take up to 2 hours to be reflected by various programs (finger, login, etc.). Please be patient. Thank you.

5. At the $ prompt, type exit and press <Enter> to end your session.

Help Resources
ITS Publications Help is available at the following Web sites; you will find: How Tos simple guides for performing specific procedures. A core set of How Tos can be found in several pods, the complete collection of How Tos can be found on the web, go to its.unm.edu/howtos. Quick References guides to frequently used commands. www.unm.edu/cirt/quickrefs Reference guides and its.unm.edu/introductions online tutorials step-by-step instructions.

ITS Newsletter feature stories and information updates about computing at UNM. its.unm.edu/cirtnews/Current/ Although some of this documentation is only for use in the pods (e.g., How Tos, Tutorials, User Manuals), the ITS publications are free and yours to keep. And dont be afraid to ask for help nothing about computing is obvious when youre using new equipment or software. Student Computer Consultants Scons student employees, identified with name tags, who are on duty in the pods to assist you. ITS Support Center Find the ISC Web site at its.unm.edu/support. Students employees and staff members answer phone calls regarding UNMs computing resources. The Support Center is located in Room 1005 of the ITS building. There are a number of ways to get help from the ITS Support Center, you can:

Query the knowledge base at http://fastinfo.unm.edu Visit the ISC. Youre welcome to stop by during business hours, Monday through Thursday, 8:00 a.m. - 7 p.m. and Friday, 8:00 a.m. - 5 p.m (semester in-session hours). Call the Support Center at 277.4848.

If ITS Publications and Online help utilities (see next section) dont resolve your problem and you dont want to contact the Support Center, another available resource is to send email to ucoord@unm.edu. You should include the following information in your e-mail message:

Your name, e-mail address and telephone number. Your department or program. A detailed description of what you are trying to do. In the description, include any error messages you saw. Also explain in your message everything you have tried on your own.

You should receive a response within 24 - 48 hours.

Online help
ITS Web sites its.unm.edu/unix The manual lookup help utility The manual lookup help utility provides online information from the UNIX programmers manual. The manual lookup program can provide descriptions of specified commands and keywords that may appear in a variety of commands. The man command (short for manual lookup) is used with a specific command name to access information about that command. Type man commandname and press <Enter>. Information about the command will appear. To leave the man utility before the end of a file, press <q>. For example, if you want information about the mv command, at the $ prompt type: man mv and press <Enter> A screen similar to the following will appear:

The man command will display one screen of information at a time. To advance to the next screen, press the <spacebar>. When all the information has been displayed press <q> to return to the $ prompt. You can also use <^d> to scroll through the information 11 lines at a time. If you wanted to search all the UNIX commands for a specific keyword, you can type the man command with the -k option like this: man -k keyword and press <Enter> For example, if you want a list of commands that use the keyword sftp, type: man -k sftp and press <Enter> A list similar to the following will appear:

For more information on the man command, type: man man and press <Enter> The apropos command utility The apropos (appropriate to) command provides a list of available documentation on general topics by keyword. It functions like the man -k command. For example, to find documentation about copying files, at the $ prompt type: apropos copy and press <Enter> Information similar to the following will appear:

If you try this example, youll notice that several screens of information scroll by before apropos stops. To see the screens of information you missed, at the $ prompt, type: apropos copy | more and press <Enter> Note: find | (pipe) on the key with \ (backslash), press <shift + \>. The first screen of information for copy will appear:

You can now press the <spacebar> to view one screen of information at a time, this is what the | (pipe) more command allows you to do. You can also press the <Enter> key to move one line at a time. To leave apropos before the end of a document, press <^c> or <q>. When you find the command you want, return to the $ and type man or apropos and the commandname, e.g., man scp and press <Enter> to view the information for that command.

Chapter 2: Connecting to UNIX

Chapter Contents Connect to UNIX with the Connect to UNIX Connect to UNIX with UNIX Commands Using your keyboard in UNIX UNM with network Windows Macintosh

This chapter provides information that will assist you in connecting to your UNIX account. Steps are listed here for logging in to and out of your account when you have connected to the UNM network. This chapter also discusses UNIX commands, and using your keyboard. SSH is a secure protocol for accessing remote computers. At UNM, SSH communciation software is installed on all pod computers. SSH Secure Shell preconfigured shareware is available at www.unm.edu/download. Whether you have direct UNM network access on campus via Ethernet, connecting via dial-up or a broadband alternative from home, the SSH application will work. There are other communications packages available, such as the software that comes with a modem; however, these packages may not be SSH enabled and might interfere with the functions of UNIX. For example, some utilities on UNIX, such as the Pico or the Vi editor, use functions keys, and some communications packages that come with modems configure the function keys to perform communication tasks. Consequently, these function keys will not be available to the Pico editor. Consult the documentation that came with your modem for details. You will not be able to connect to the UNM network if your communications software is not SSH enabled.

Connect to UNIX with the UNM network


The UNM network is the backbone of UNMs computing system. From it, you can connect ITS' shared network technology. Connect to the UNM network (after properly configuring the connection using an SSH application); at $ with the ssh linux.unm.edu command. There are several ways of reaching the UNM network. The various connection methods are described in the following subsections. Connect to the UNM network You can connect to the UNM network on campus via ethernet. You can connect to

the UNM network from off campus via another ISP with a dial-up or broadband connection. or dial in directly to the UNM network. Regardless of how you connect to the UNM network, you will need a NetID and password to access your account space and shared network technology. The secure terminal emulation program SSH is available for both Macintosh and Windows at its.unm.edu/download. SSH, or a secure terminal emulation program like it, is necessary so your computer can emulate a DEC vt100 terminal. If the communications program you are using cannot emulate a vt100, you will encounter keyboard mapping problems. That is, some of the keys necessary for UNIX will not be mapped to your keyboard, which will prevent you from performing some basic UNIX functions. Ethernet To establish a network connection at a UNM campus location, you will need an active Ethernet wall port, a computer with a NIC (Network Interface Card) and TCP/IP installed. It would be an exception to the rule for a computer off the assembly line to not have a NIC and TCP/IP installed. If you are familar with TCP/IP settings, you can conifgure a DHCP connection. Dynamic Host Configuration Protocol (DHCP) is available at most, but not all, UNM campus locations. For assistance, contact the ITS Support Center, 277.4848, or see its.unm.edu/howtos. Wireless networking Wireless networking is available at most UNM buildings. For information about connecting to the wireless network, see its.unm.edu/wireless. Dialing in to the UNM network Windows Go to its.unm.edu/download, get setupdun and install. If the icons do not appear on your computers desktop, go to Start> Settings> Network and Dial-up Connections. Double click on the icon corresponding to the amount of time you need to be connected, (15 minutes or 1 hour), and click the Connect button. Dial Up Networking will automatically dial in to the UNM Network, and will continue redialing until connected.

Macintosh If you are manually configuring a dial-up connection, the following information will assist you in configuring your software: 1-hour 346-4001 (56 Kbps max.) 1 hour limit 15-Minute 346-4000 (56 Kbps max.) 15 minute limit The UNM Domain Name Servers are: 129.24.8.1 and 129.24.8.4 Search domain: unm.edu Line Line

Note: If you dial-up from on campus, you need to dial 9, (9 and a comma) before the telephone number (e.g., 9,3464001). If you dial in from outside of Albuquerque, you may still access all of ITS' online computer services, but you will be billed for a long distance call by your long distance service provider.

Connect to UNIX with Windows


Using SSH Secure Shell SSH (Secure Shell, aka Secure Socket Shell) provides a secure connection to the UNM network and Linux. SSH uses encryption to protect your NetID and password. With an unsecure connection, such as Telnet, any information that is being transferred between the desktop computer and the UNM network is potentially vulnerable to hackers looking for passwords or other information. To access the UNM network and your Linux directory from home, first connect to the UNM network using either the UNM_1 or UNM_2 dial-up lines. When connected, start SSH Secure Shell. To access SSH from a UNM campus computer pod, double click the SSH Secure Shell icon located on the desktop. The program will prompt you for your User Name, type your NetID and click Connect. A prompt will appear for your password, type your password and click OK. At the TERM = (vt100) prompt press <Enter>. The $ (Linux) prompt will appear.

Note: The first time you connect a Host Identification dialog may appear, click Yes. If you have an unconfigured copy of SSH Secure Shell, start the program and click Quick Connect. A Connect to Remote Host dialog will appear. At the Host Name field, type linux. In the User Name field, type your NetID. Click Connect. The $ prompt will appear.

Note: If you are connecting to the UNM network via an alternate ISP, type linux.unm.edu in the Host Name field. If you are not using a pre-configured SSH program at home, go to www.ssh.com and download the most recent SSH Client. Look for a file name similar to: SSHSecureShellClient-3.2.0.exe (the build number may be different, e.g., 3.3.0). Install the client, the interface is similar to the Telnet utility you may have used before. If you need assistance configuring the SSH client contact ucoord@unm.edu. If you plan to download and/or upload files, see the subsection Using SFTP to transfer files in Chapter x, Transferring Files, of this document before you connect to UNIX. Log out of the system When you have finished working, you need to log off of Linux and the UNM network. To log off, at the $ prompt, type exit and press <Enter>. To quit SSH, click File> Exit or, click the X at the top right corner (of the window).

Note: If you do not complete the appropriate steps, your connection to the UNM network will not be released properly. This may cause your phone line to remain busy or your connection to the system to remain open. If the connection remains open and you try to connect to another shared network, you will not be able to do so.

Connect to UNIX with Macintosh


Using MacSSH SSH (Secure Shell, aka Secure Socket Shell) provides a secure connection to the

UNM network and UNIX. SSH uses encryption to protect your NetID and password. With an unsecure connection, such as Telnet, any information that is being transferred between the desktop computer and the UNM network is potentially vulnerable to hackers looking for passwords or other information. Mac OS X SSH is available at the command line via OS Xs Terminal program. The Terminal program is usually located in Applications> Utilities. To place a shortcut in the Dock, click and drag the Terminal icon to the Dock. In the ITS pods, a Terminal shortcut is available in the Dock. Click the Terminal icon to start. At the prompt, (similar to [dhcp-test-078] cirtuser$ ) type: ssh linux -l NetID and press <return> (l = lowercase L) If you prefer (this may be easier to remember), you can alternatively type: ssh NetID@linux and press <return> If you connect to UNM via another ISP, type: ssh linux.unm.edu or ssh NetID@linux.unm.edu and press <return>. At the password prompt, type your password and press <return>. At the TERM = (vt100) prompt, press <return>. The $ (Linux) prompt will appear. To access the UNM network and your UNIX directory from home, first connect to the UNM network using either the UNM_1 or UNM _2 dial-up line. -l NetID

Note: The first time you connect with SSH you may be asked to accept a certificate. Type yes and press <return>. For secure computing at home with OS 9.x, go to its.unm.edu/download and select the appropriate version, either 68k or PPC, for your Macintosh. Install MacSSH. The

interface is similar to the Telnet utility you may have used before. Click the Secure Shell v2 box before attempting a connection. Log out of the system When you have finished working, you need to log off of Linux and the UNM network. To log off, type exit at the $ prompt, and press <return> . To quit MacSSH or Terminal, press < +q>

Note: If you do not complete the appropriate steps, your connection to theUNM network will not be released properly. This may cause your phone line to remain busy or your connection to the system to remain open. If the connection remains open and you try to connect to another shared network, you will not be able to do so.

UNIX commands
After any messages, the Linux prompt appears. The prompt you see depends upon which shell or command interpreter you are using. By default, your acount uses the Bash shell. Bash is a command interpreter that uses $ (a dollar sign) as a prompt. The shell interprets commands you type and executes the appropriate program to perform the desired action. The Bash shell has some basic rules. If you want a complete list and descriptions, at the $ prompt, type the following commands: man bash and press <Enter>

Using your keyboard in UNIX41


Depending on the way you connect to the UNIX system, you may find that familiar keys do not necessarily work the same. UNIX is case sensitive, which means that uppercase and lowercase versions of the same letter are interpreted as different characters. Typing commands in lowercase is the norm. For example, the backspace key is set (by default) to <delete> or <control + h>. The backspace key, along with others, can be redefined in UNIX according to your

preference. To see a list of keys that use the stty (set terminal parameters) command, at the $ prompt, type: stty -a and press <Enter> information similar to this will appear:

The following list describes a few of the functions and their associated default key(s). The default keymap often depends upon the method you use to connect to the system and the terminal emulation.

Note: The ^ symbol denotes the <Ctrl> key (<control> on a Macintosh). For example <^c> indicates <Ctrl+c> (<control+c>).

Function erase kill werase susp

Key <^?> <^x> <^w> <^z> <^y>

Description

suspend the current program return to suspended program

inter stop

<^c> <^s> <^q>

interrupts execution

the

current

command,

stops

puts current command "on hold," preventing the screen from scrolling resumes scrolling signals End of File that is used in many applications

eof

<^d>

Special UNIX characters


The following are special characters that you can use in UNIX to make typing easier, manipulate commands and work with files.

Note: Because these characters are used for UNIX commands, do not include any in a filename.

Character <Enter> <return> ! ^ : / ; | >

Function executes (starts) command executes a previous command in history matches shortes string possible path directory separator, variable modifier root directory delimiter command separator sends the standard output of the first program to the input of the second redirects standard output

< >> * ? & \ ' ` " $ . # ~ -

redirects standard input appends new output to file a string wildcard a character wildcard executes a command in the background reads the next character literally reads the next substitutions string literally, preventing all

performs command substitutions reads the next string literally, allowing variable and command substitutions references a variable executes a command (only at the beginning of a line) descriptive comment specifies your home directory, unless used to access remote directory with that argument used prior to listing command line options

Chapter 3: Using Files and Directories


Chapter Contents Naming Understanding Using Specifying a directories a dotfiles on directory UNIX UNIX path file

Using the History Changing a command without retyping it

utility

Each computer account is assigned a working space on the UNIX system. This working space is called the home directory or "directory." This directory is named after the NetID that you selected when you created your account. For example, if your NetID is tinker, your home directory name is tinker.

Naming a UNIX file


You store information in your directory in the form of files. A file is some type of information (e.g., a program, program data, mail messages, etc.) that you can retrieve by name. When creating a file, you must assign a unique name to the file. The name usually consists of two parts: filename The name can contain any combination of uppercase and lowercase letters, numbers and the special symbol _ (underscore). Do not use any spaces in your filename, use the underscore to indicate a space. UNIX will not recognize a filename containing a space. You should try to use a filename that describes the content of the actual file and that is not too long. Try to limit your filename to no more than 12 characters. An often used option is the addition of an extension that begins with a . (period/dot) followed immediately by characters which may consist of letters and numbers. An extension is normally used to identify the application that the document was created with. Usually an extension on a filename is optional, but some files are required to have a designated extension in order for the system to recognize the file.

extension

Extension

Type of file

.c

C source file

.f .out .txt

FORTRAN-77 source file Object file created by compiler Text file

examples of filenames and extensions

cs_educ_2.def 02.458

calendar.hlp ill_copyright_notice.txt

Understanding dotfiles
If a filename is preceded by a period ( . ) in UNIX, it is called a dotfile and is a hidden file. These dotfiles control the behavior of system processes such as logging in and out and running utilities and programs. Dotfiles wont be displayed in your list of files unless you specifically include the all command as part of the list command. To list all files, including your dotfiles, at the $ prompt type: ls -a and press <Enter> The .cshrc and .login files are especially important because they hold many of your initial settings when you log on to the system. These two files are read each time you log into the system. Below is a list of frequently used dotfiles and the function of each. .bashrc This file determines the behavior of the shell and shell scripts. .cshrc This is the first file the system reads when you log on. This file starts the C shell as your command interpreter and sets a number of other environment variables. You can modify this file to change the environment to your choosing. .forward This file directs your e-mail. It specifies where your mail is being forwarded to. .login

This is the second file the system reads when you log on. Again, this file sets your environment and can be modified to suit your needs. It contains your default printer, your default text editor and your path statement. .logout This optional file can be used if you want to execute a particular command every time you log out. If you want to clear the screen every time you log out, you would create a .logout file which has clear as one of the lines. .pinerc This file contains all the configurations for PINE, an electronic mail program. It is copied to your root directory the first time you type the pine command. .newsrc This file contains a list of all newsgroups throughout the Internet, is created after you invoke rn or tin for the first time. An exclamation mark after a newsgroup means that it is inactive, while a colon signifies that you subscribe to this newsgroup. To see an abbreviated list of files, excluding dotfiles, at the $ prompt, type: ls and press <Enter>

Using directories on UNIX


When a file is created in UNIX, it is stored in a directory. Directories are created to house files of a particular type. For example, a Mail directory is created to hold files that are saved when using an electronic mail program. In the UNIX system, almost everything is a file not only program code, data, and text but also the directories containing information about other files, some of which might also be directories. When you first log in to your account, no directories are created. You are initially given a few files like .bash and .login. The more you use your account, the more files you will acquire. Directories are used to organize files by function, purpose, type, etc. UNIX organizes directories in a hierarchical structure similar to a horizontal family tree. At the very bottom of the tree is the root directory, and its name is written as a / (forward slash). As your account grows, so do the directories on the tree. These subdirectories may also contain other subdirectories. The UNIX tree structure looks similar to this:

This structure expressed in the form of a complete path would look like this: /nfs/user/t/tinker/projects When you log in to UNIX, you are automatically placed in your home directory, which is tinker in the following examples. In UNIX, you can create new subdirectories within your home directory. You can organize your files in these subdirectories. You can view your home directory from any other directory with the ls command and either the system variable $HOME or the ~ (tilde) followed by your NetID, e.g., ~tinker. For example, if you are in your public_html directory and wanted to see the files in your home directory, at the $ prompt, type either: ls $home or ls ~NetID (e.g., ls ~tinker) and press <Enter> Creating a new directory To create a new subdirectory, use the mkdir command followed by the name of the new subdirectory. For example, if you want to create a subdirectory in your home directory with the name revised, at the $ prompt, type: mkdir revised and press <Enter> If your NetID is tinker, your home directory is named tinker, and you can create a new directory named revised while in your home directory. The tree structure would be similar to:

The complete path would look like this: /nfs/user/t/tinker/revised The new directory revised is a subdirectory of the tinker directory as is the projects directory i.e., both are within and one level below the home directory, tinker. You can also create a subdirectory within a subdirectory. For example, if you create a subdirectory under the revised directory called wip, the tree structure will look similar to this:

To create the wip directory under the revised directory, confirm you are in the revised directory. At the $ prompt, type cd revised. Then you can create the wip directory, i.e., mkdir wip and press <Enter>. Because the wip subdirectory is under the revised subdirectory, the revised subdirectory is considered the parent directory of the wip subdirectory. The complete path would look like this: /nfs/user/t/tinker/revised/wip

Accessing a directory

To create files in a subdirectory of your home directory, you must first access the subdirectory. For example, if you were in your home directory and wanted to change to your revised subdirectory, at the $ prompt type: cd revised and press <Enter> To change back to your home directory, type cd and press <Enter> To change to the wip subdirectory of the revised subdirectory from your home directory, type cd revised/wip and press <Enter> When you specify revised/wip in the cd command, you are specifying the path to the subdirectory (i.e., what directories lead to the subdirectory you want to access.) The $ prompt will re-appear without an error message if the command was successful. You can also check to see if you are in the correct subdirectory by typing: pwd and press <Enter> and /nfs/user/t/tinker/revised/wip would appear for this example.

Note: If you are in your home directory and you enter the pwd command, you will get a reply similar to /nfs/user/t/tinker, which indicates the path to your home directory from the root directory. The last name listed is always the name of your current directory. To change to the parent directory of a subdirectory (i.e., backup one directory at a time), at the $ prompt type: cd .. and press <Enter>

Moving a directory

To move one subdirectory into another, use the mv command. This command allows you to move subdirectories to other locations in your account. For example, if you want to move a subdirectory named parents into a subdirectory named letters, type mv parents letters and press <Enter> At the file level, this command will rename a file. For example, if you want to change the name of fileone to filetwo, type: mv fileone filetwo and press <Enter> See Moving Files or Directories, in Chapter 4, Managing and Manipulating files, for more information about changing file names.

Removing a directory To remove a subdirectory and all the files it contains, change back to the parent directory of that subdirectory to be removed, and type : rm -r subdirectory and press <Enter> For example, if you want to remove the subdirectory revised, confirm you are in the home directory, at the $ prompt type: cd and press <Enter> then at the $ prompt type: rm -r revised and press <Enter> The rmidr command will also remove a directory, but it must be empty, all files must be deleted first. See Chapter 4, Managing and Manipulating Files for instructions to delete individual files. When all the files have been removed from the subdirectory, change back to the parent directory of the subdirectory and type: rmdir subdirectory and press <Enter>

Specifying a directory path


A .login file is executed each time you log in to your account and is contained in your home directory. To view the file, type:

more .login and press <Enter> Inside the .login file is the path statement that includes the directories UNIX will search to locate commands that you type in at the prompt. A typical path looks like this:
setenv PATH /usr/ucb:/bin:/usr/bin:/usr/local/bin:/usr/new:/usr/bin/X11:/usr/local/gnu/bin: $HOME/bin:.:/etc:

Each name that is separated by a colon is a directory where a search is made for commands.

Note: Leave no spaces between characters in a path statement. Spaces in the path statement will cause the path to end at the first space. The useful command, whereis, tells you the directory where a particular command is located. If you type whereis, followed by a command name that you want to find, such as ls (list); at the $ type: whereis ls and press <Enter> A response similar to the following will be displayed: ls: /bin/ls /usr/share/man/man1/ls.1.gz The ls command is found in the /bin directory. The /bin/ls directory is where the actual command is. See the subsection, Modifying your environment, in Chapter 5, Other Commands, to learn how to change your path to include other directories.

Using the History utility


If you are tired of retyping a command and would like to repeat a previously typed command one, six, thirteen, or even twenty commands previous, you want to use the history utility.

The history command is written in your .cshrc file and makes the shell track your last 20 commands. The command looks like this in the .cshrc file: set history=20 notify noclobber You can increase or decrease your history setting by editing your .cshrc file with Vi or Pico. The savehist command will save your history every time you log out, so the next time you log into your account, your history will be intact. To add the savehist command, open your .cshrc file in Vi or Pico and insert a new line after the set history command and type: set savehist=20p and press <Enter> The number you enter for savehist should be the same as the set history number. To view your history list, at $ type history. You will see a list of numbers followed by the corresponding command. If you want to execute a command that corresponds to one of the numbers, at the $ prompt, type: !n and press <Enter> Where n is the number associated with the command. To repeat the last command you entered, type: !! and press <Enter> The ! (bang) followed by a letter will also repeat the last command. The letter represents the first letter of the last command you typed. For example, if you start the PINE program, check your e-mail, and quit; then at the $ prompt you type env and press <Enter> to view your environment, when the $ prompt appears again, type !p and PINE will start again.

Changing a command without retyping it


Some command strings in UNIX can become long. For example: more .cshrc | grep hi <Enter>

This command searches your .cshrc file for all the instances of the word hi. If your search only gave you one hit and you want to search the file again for the word ru rather than hi, you can do a command line search rather than retyping the entire command. At the $ prompt, type: ^hi^ru <Enter> The character before and after hi is a caret (^). This character replaces the first instance of hi with ru. The command will execute again, substituting hi with ru. Command line search and replace is useful if you type a long command, but especially helpful if you mistype the command. For example, if at the $ prompt you type: moer .cshrc | grep alias <Enter> the following message would appear: moer: Command not found. Since you should have typed more, you can either retype the entire command, or at the prompt, just type: ^er^re <Enter>

Note: The computer will search for the first instance of the character(s) inside the carets, and replace it the character(s) specified after the second caret.

Chapter 4: Managing and Manipulating Files


Chapter Contents Disk Listing Display the Concatenating quotas files contents of files a file

Copying files Compressing and uncompressing files Removing files Restoring files Moving files or directories Using the scratch directory for temporary storage Using wildcards Downloading files to your desktop

Conserving ITS shared network technology disk space and your individual disk allocation (e-mail and home directory) is everyones concern. This chapter contains information on managing and manipulating (e.g., listing, copying, moving, deleting, etc.) files within your directory. There are a variety of commands available to manage and manipulate the files in your directory. For example, if you wish to add the data in one file to the data in a second, the cat command will concatenate (i.e., combine) the two files so that all the information stored in the same place. This section will cover the most frequently used file commands.

Disk quotas
Each computer account (NetID) provides 50MB of UNIX system disk space. To view your current quota status, at the $ prompt, type quotas. A list similar to the following will appear:

All measurements are in Kilobytes. To convert to Megabytes divide the measurement stated by 1000.

Note: If you reach your quota limit, any files you modify or attempt to save will be reduced to an empty file. You should immediately remove any unwanted files. You can also move files to the temporary /scratch directory

to download or compress files. See the subsection, Using the scratch directory for temporary storage in this chapter. If you have a legitimate academic need, you can request a higher quota by contacting the UNIX coordinators via e-mail, ucoord@unm.edu. Anyone requesting a higher quota must be able to justify the need for more disk space. There are two options available for summarizing disk usage. To obtain disk usage summaries, there are two options available to you: Disk Usage Command

By directory By directory summary

du -k ~ | sort -n | more du -s -k * | sort -n

Listing files
UNIX provides the ls command to list the names of files in your directory. At the $ prompt, type ls and press <Enter> A screen similar to the following will be displayed:

Note: Files in the directory list will be listed alphabetically. Files and directories that begin with uppercase letters (i.e., capitalized) are alphabetized before those that begin with lowercase letters. If no directory name is specified, it will automatically list the files in your current directory, which is usually your home directory.

You also have files in your account that will not be revealed by the ls command. These files are hidden files or .dotfiles. Dotfiles are used to control the behavior of system processes such as logging in to and out of, and running utilities and programs. You can include these in a directory listing by typing: ls -a and press <Enter> A screen similar to the following will be displayed:

You can also use the ls -al command to list additional information about all your files or a specific file in your directory, including the files size, permission status, the time and date the file was created, and so on. For example, if you type ls -al and press <Enter> a screen similar to the following will be displayed:

The first column in the screen above displays the files privileges. Permission modes are set for the owner, the owners group and all users on the machine. The mode field consists of 10 characters. The first character indicates the type of entry: d for a directory and - (hyphen) for a plain file. As you become more experienced, you will learn about other types of files. You can add the -lt option to the ls command to list the information about all your files in order by date and time. For example, when you type: ls -lt and press <Enter> a screen similar to the following will be displayed:

To save your directory listing to a file so you can print it, type: ls -lt >filename and press <Enter> where filename is the name you give the file. There are many other qualifiers (i.e., options) that can be used with the ls command which provide directory output in different formats. For additional information, type: man ls and press <Enter>

Display the contents of a file


There will be times when you will want to view the contents of a file without starting a text editor. You can do this with the more command. For example, if you want to view your .login file, type more .login and press <Enter>

Note: You cannot modify a file with this command. You can only view it on the monitor.

The more command displays the contents of the file one screen at a time. The display ---More--- will appear at the bottom of the screen, indicating that there is additional information. To display the next screen, press the <spacebar>. To display the previous screen, press <b>. If you know you may be displaying a large file and want the option of discontinuing the display at anytime, add the -d option to the more command, type: more -d .login and press <Enter> After one screen of text has been displayed, you will be prompted with Press space to continue, q to quit. You can also press <h> to get help. To view a file beginning where a given string is found, type more +/string .filename and press <Enter>

Concatenating files
The cat command will allow you to combine (concatenate) the contents of one file to the end of another. The structure of the command is as follows, type: cat file1 file2 > destinationfile and press <Enter> This command will place file2 at the end of file1 and store the combined files as destinationfile. For example, if you want to place the text in the file bibliography at the end of the file named paper1 and store the merged text in the destination file finalpaper, type: cat paper1 bibliography > finalpaper and press <Enter>

Note: file1, file2 and destinationfile must be three different filenames. Repeating a source filename as a destination file in this command can cause the source file to be destroyed before it is read.

Copying files

The cp command allows you to copy an existing file to a new file. When the command is completed, there will be two identical files with different names. For example, if you want to make a copy of the file distribution_list and name it dlist2, type: cp distribution_list dlist2 and press <Enter> The cp command is also useful if you want to copy a file from one directory to another. For example, if you want to copy the file sources.txt from your home directory to the subdirectory revisions, (cd to the top (home) of your directory) type: cp sources.txt revisions and press <Enter> If you are concerned about copying files to other locations where a file with that name may already exist, you may want to use the -i option with the cp command: cp -i sources.txt revisions and press <Enter> When you use -i, you will be prompted with overwrite revisions/sources.txt? if the file already exists in the directory. If you type y for yes the file will be overwritten. If you respond with anything else the command will be cancelled.

Compressing and uncompressing files


Compressing files for later use The gzip command reduces the size of a text file by nearly 50%. This is useful for files that you are not currently using, but might need at a later date. Compressing files is also an easy way to free space in your account. To compress a file, type: gzip filename and press <Enter> The file will be replaced by a compressed file with a .gz attached to its name (e.g., filename.gz). You can also use wildcards to compress a set of files (e.g., compress *.exe). When you are ready to use the file again, you must first restore it to its original form using the uncompress command. To uncompress a file, type: gzip -d filename To uncompress a set of compressed files, use the wildcard character (e.g., gzip *.*)

Note: The gzip and tar commands require temporary space in your current

directory. This can cause you to exceed your quota and lose files if you are already close to that limit. If this is the case, first move your files to the scratch directory before compressing them. See the subsection, Using the scratch directory for temporary storage in this chapter for more information.

Archive and compress a directory To compress an entire directory of files, you must first create an archive of the files using the tar command. Follow these steps: 1. At $ type: tar cf myarchive.tar mydirectory and press <Enter> 2. At $ type: gzip myarchive.tar to compress the archive file, the gz extension will be added (e.g., myarchive.tar.gz). Press <Enter> 3. Remove the the original directory and files, at $ type:

rm -r mydirectory and press <Enter> Uncompress and unarchive a directory When you need the files and directory again, follow these steps to uncompress and unarchive your files. 1. At $ type: gz -d myarchive.tar 2. At $ type: tar xvf myarchive.tar 3. Remove the archive file, at $ type: rm myarchive.tar and press <Enter>

Removing files
To remove a file from your account, use the rm command. The filename must be specified, type: rm filename and press <Enter> For example, if you have a file called research.data and you want to remove it to free up some disk space, type: rm research.data and press <Enter>

Note: Once you have removed a file, it is gone unless you have a backup on tape or disk (see the Restoring files subsection for one option that is available to you). ITS recommends that you use the -i flag with the rm command, for example: rm -i research.data and press <Enter> This will prompt you for a confirmation before removing the file.

Restoring files
If you accidentally delete a file, you can restore it by typing, at the Linux ($) prompt: snapshot filename and press <Enter> You will be prompted for the version you want to restore.

Note: cd (change directory) to the directory where the file you want to retrieve was located. You can also restore a directory with snapshot (you will most likely want to be at top of your directory), at $ type: snapshot directoryname and press <Enter> These commands will work for files no more than 14 days old. For files that are more than 14 days old, and no more than 13 months old, you can request ITS to recover the file(s) from tape backups. Since restoring from tape backups is a labor-intensive process, we ask that you request this service only for files or directories relating to academic research and/or those which are job related. In addition, requests are limited to a single date. If the file is older than thirteen days, you will need to contact a UNIX coordinator, e-mail ucoord@unm.edu with your restore request. Include the file or directory name you wish to restore. Email INBOXes (incoming mail) however, are backed up only for disaster recovery purposes, and are not archived. Individual inboxes cannot be restored. Important e-mail messages should be saved to folders where they can be restored if lost.

Moving files or directories


The mv command is useful when you are trying to reorganize your disk space. The mv command allows you to move files and directories to other locations in your account. You can also use the mv command to rename a file or to move it from one directory to another. For example, if you want the file project39 renamed to project39_ final, at the $ prompt, type the mv command like this: mv project39 project39_final and press <Enter>

Note: Unlike the cp command, which creates a duplicate file, there will be only one file after you use the mv command. The project39 file will no longer exist; the data will now be stored as the new name. If you want to move the file introduction to the directory presentation, type mv introduction presentation and press <Enter>

Note: You can also use the mv command to move one directory into another directory by specifying the directory names in the command.

Using the scratch directory for temporary storage


Every Linux host has access to a temporary storage directory named /scratch that all clients can access. This directory is shared by all the Linux hosts. Files placed in this directory are kept for three days and then are automatically deleted. To access the /scratch directory, at $ type: cd /scratch and press <Enter> If you plan to store multiple files in this directory, the best practice is to create a subdirectory for yourself. Name the subdirectory your NetID. To create a scratch subdirectory, at $ type: mkdir /scratch/NetID and press <Enter> To move to that directory, at $ type: cd /scratch/NetID and press <Enter>

Use the mv (move) command to move files from your account to the temporary directory (after the cd command above) by typing: mv ~NetID/filename /scratch/NetID and press <Enter>

Note: Remember that the /scratch directory is only a temporary storage solution and files placed there will be automatically deleted after three days. If your files are critical, move the files back to your account or to removable media. For more information on the move (mv) command, see the subsection, Moving files or directories in this chapter.

Using wildcards
When working with some of the UNIX commands (e.g., cp, ls, mv, etc.), you may be able to use wildcard characters. Wildcard characters enable you to qualify Linux commands easier than typing out the full filename. The wildcards are * (asterisk), ? (question mark) and [ ] (brackets). * (asterisk) The * (asterisk) is the zero or more characters wildcard. It is used to represent all or part of a filename and/or extension. For example, if you want to list all the files in your directory that have the extension .p, at $ type: ls *.p and press <Enter> Linux will provide you with a list of files that have different filenames but have the extension .p. For example, the following files could be listed: prog1.p record.p progsalary.p report.p If you want to erase all the files with the extension of .p in your directory, at $ type: rm *.p and press <Enter> Be very careful using * with the rm command. ? (question mark)

The ? (question mark) is the single character wildcard. It is used to represent specific character positions in a filename and/or extension. For example, to list the files in any directory that start with pr, have the sixth letter of s and any extension, type: ls pr???s.* and press <Enter> The three question marks (?) at the third, fourth, and fifth character positions mean you don't care what those characters are. Therefore, the following files might be listed: prcoms.c prepos.txt prcm1s.def prjcts.p [ ] (brackets) The [ ] (brackets) is the one or more characters wildcard. It allows you to find a single character in a filename from a specified set of characters. For example, to list the files in a directory that start with project2, project3 and project4, type: ls project[2-4] and press <Enter> The following files would be listed: project2 project4 project3 You can identify a range of characters as shown above or identify the exact characters like this: ls project[234] and press <Enter>

Downloading files to your desktop


You may also download files with Secure FTP and save to your hard drive or removable media. Macintosh: See How To #715, SFTP with OS X (Command Line) or, How To #716, Use Fugu for secure file transfer. Windows: See How To #616, Use Secure File Transfer.

Chapter 5: Other Commands


Chapter Contents Special Processing Processing Controlling Modyfing your UNIX environment commands status loads jobs

This chapter provides information on a variety of UNIX commands with functions from checking your process status to modifying your UNIX environment.

Special commands
These commands may assist you while you are working in Linux: quotas this command displays information on the disk space assigned to your account. The command will display how much file storage you have and how much you have used. du -k this command displays how much disk space you have used in your home directory. It will list all files, including subdirectory files, and their sizes. If you add the -s flag to the command, it will display the total storage used. date displays the current date and time. cal displays current months calendar. ssh hostname securely log in to the UNM network, via an encrypted connection, without logging out of your current connection. finger NetID locate the owner of a particular NetID. Displays the persons NetID, office or program name, telephone number, home directory path, etc. Finger also works with last names. chfn change the permanent information kept by UNIX about your NetID. This information appears when someone uses the finger command. It allows you to store department and personal data, such as your telephone number. users

lists the NetIDs of users currently logged in to the system (the server you are connected to). which command displays the directory where the specified command is located. spell filename spell check the contents of a file. UNIX will display words that it has reads as incorrectly spelled.

Processing status
One of the best features of UNIX, and one of the most difficult to understand, is that it manages so many peoples work at the same time. At the prompt, type: uptime and press <Enter> UNIX will display the number of people currently logged in, as well as the computers average load. Often, the average load is a function of the number of people logged in; but more precisely, it is the amount of information being processed sent by all the people logged in. The display will look similar to this:

Processing loads
The system works one persons request for a brief period and then moves to the next person's request. These requests are called processes. A process asks the Central Processing Unit (CPU) to perform a particular action. The system assigns a Process Identification Number (PIN) to each process running. Sometimes the CPU can complete the process at once. At other times, it has to execute small portions of the process and finish the job later. The length of time the CPU requires to complete the task depends on the size of the process as well as the average load on the computer at that particular time.

Because many people can be logged in at one time and the operating system handles each process, you can request more than one process at a time. If you are not using a graphics workstation or Secure Shell, which allow multiple connections to UNIX and can execute multiple commands at one time, you need to move to a different window so that the computer will treat each open window as a stand-alone session. For example, the process status command shows which of your processes the CPU is working on. Type ps and press <Enter> Something similar to this will appear:

Even though you are only using the system at one location, the CPU is running two of your jobs. One is the C shell command interpreter and the other is the command you just typed. UNIX allows you to run as many jobs as you require.

Controlling jobs
Some commands for job control include: bg fg & jobs kill n suspends a job and puts it in the background brings a suspended job to the foreground runs in background (the & is appended to another command) shows what jobs are running terminates job number n

Modifying your UNIX environment


An alias makes a word represent a command or a series of commands. For example, if you prefer to use the DOS command dir rather than the UNIX command ls to list your files, you can use an alias to change the command. So, whenever you type dir, the bash shell will interpret it as ls. The command is changed in your .cshrc file, in this example, type: alias dir ls and press <Enter> This statement translates as enter command (dir) to execute the ls command. An alias can also represent a series of commands, type: alias dir ls -alF | more and press <Enter> This example uses some of the command line options of ls: -a -l -F includes dotfiles in the directory listing includes other information such as the size and time the file was created puts an * after each executable file and a \ after each directory to show a visual difference

These options direct the output to the more command, which pauses after each screen is filled with information.

Chapter 6: Text Editors


Chapter Contents The Pico editor Navigating Deleting Manipulating Importing Searching a Pico text files text for text file

Using Spell Saving and exiting a file The Vi editor Inserting Navigating a Deleting Manipulating blocks Searching for Changing text globally Saving and exiting a file text vi text of (Find

Check

file text text & Replace)

There are two popular ITS-supported text editors that will allow you to create and edit files in UNIX. This chapter provides instructions for both, Pico and Vi.

The Pico editor


Pico is a quick and efficient text editor, and can also be used to edit program files in UNIX. This section introduces some of the basic Pico commands. You may also want to refer to How To #410, Use Pico to edit text on UNIX. When you edit an existing file, you are actually editing a copy of that file. Pico maintains two versions of the file the version you are editing and the original version. The original version is not updated until you save the file. When you have logged in and the $ prompt appears on the screen, type pico to create or edit a file. You can specify a filename when you start Pico or assign a name when you save the file. For example, if you want to revise the file named examples.list, at the $ prompt type: pico examples.list and press <Enter>

Note: If you open Pico and UNIX doesnt recognize your terminal type, you will see a message similar to: Incomplete termcap entry. If so, at the $ prompt, type: source .login and press <Enter>. (Dont forget the dot (period) before login.) Then type: pico filename and press <Enter>. Where filename is the name of the file you want to edit, or the name of a new file you want to create. When Pico starts, a screen similar to the following will appear:

Pico displays the first 19 lines of the file. The left side of the status line at the top of the screen indicates which version of Pico you are using. The middle of the status line indicates the name of the file you are editing. On the right side, the word Modified will appear to indicate that you have made modifications since the last time the file was saved. On the third line from the bottom, Pico displays some information about the file you are editing and other messages (e.g., the number of lines in the file). This line is also used for additional command functions. The other lines near the bottom of the screen list command keys. Pico commands are used with the control key (i.e., <Ctrl> or <control>), represented by the caret (^). The control key is used like the shift key: press and hold the control key and then press the next characters key. For example, <^x> means hold the <Ctrl> (or <control>) key down and press the letter <x>.

Note: If a capital letter is required for a command, it will appear as a capital letter in the key combination. The command key letters at the bottom of the Pico screen appear in caps for ease of reading and to mirror what you see on the keyboard. For consistency, this document only uses a capital letter if the shift key is required as part of the key combination, e.g., <^P> = <Ctrl + Shift + P>.

Navigating a Pico file Pico allows you to view different parts of your document on the screen. Some of the commands work at the position of the cursor in the document. <^n> or <down arrow> <^p> or <up arrow> <^f> or <right arrow> <^b> or <left arrow> <^a> <^e> <^v> <^y> <^l> <^c> moves the cursor down one line

moves the cursor up one line

moves the cursor one character to the right

moves the cursor one character to the left

moves the cursor to the beginning of the line moves the cursor to the end of the line moves the cursor down one screen of text moves the cursor up one screen of text (lowercase L) refresh the current screen display the current position of the cursor in the file

Deleting text <backspace> <^d> deletes the character to the left of the cursor deletes the character at the cursor position

<^k> <^u>

deletes the entire line where cursor is located undeletes the last lines deleted and places them at the cursor position

Manipulating files You can manipulate (rename, delete, copy, etc.) files in your account by using <^r> (ReadFile) and the <^t> (To Files) commands. To Files accesses a list of files and directories in your account. The information appears in a browser-type screen. To access the browser screen: 1. Press <^r> 2. From the ReadFile menu, select <^t>. A browser screen appears.

The browser contains two sets of columns. Each set contains the name of the file or directory, followed by either the size of the file (in kilobytes) or a specification (e.g., dir, to indicate that it is a directory). 1. Use the <arrow> keys to highlight the file you want. 2. Select the letter of the command you want. For example, if you highlighted the file security, and you wanted to rename it to security.info, press the letter <r> for Rename.

3. Most of the commands prompt you for additional information. In the above example, the rename command will prompt you with Rename file to. At that prompt, type security.info and press <Enter>. Pico renames the file and refreshes the browser list. 4. To exit the browser screen, press <e>. 5. To exit the ReadFile menu, press <^c>.

Importing text Pico allows you to insert a file from your UNIX directory into a working file, starting at the cursor position. To import a file: 1. Position the cursor where you want the text to be inserted. 2. Press <^r>. 3. Type the name of the file at the File to insert from home directory prompt. 4. Press <Enter>. Pico inserts the text at the cursor position and displays the number of lines inserted.

Searching for text Using Pico, you can search for specific text within a file. The search begins at the cursor position. To perform a search: 1. Press <^w>. 2. At the Search prompt, type the text you want to locate. 3. Press <Enter> to start the search. The cursor appears at the first occurrence of the text.

Using Spell Check You can also spell check the text in your file. However, Pico does not provide a

dictionary to verify the correct spelling. Therefore, Pico locates suspected misspelled words and expects you to correct the errors. To spell check: 1. Press <^t>. When a suspect word is located, the prompt Edit a replacement appears, followed by the word to be checked, which appears highlighted in the file. 2. Type the correct word and press <Enter>, or, if the word is spelled correctly, press <Enter> to accept the current spelling. 3. Pico then locates the next suspect word in the file. When Pico has checked the entire file, the message Done checking spelling will appear.

Saving and exiting a file Save early, save often! While you are working, you should save your file often to avoid losing text. You can save with these commands: <^x> saves your file and exits both the file and the editor. If you have modified a file, this message will appear: Save modified buffer (ANSWERING NO WILL DESTROY CHANGES) (Y/N)? Type <n> for no to have changes ignored and exit the file. If you want to save and exit the file, type <y> for yes. When you see the message, File name to write (type the name of your file if not previously named) press <Enter>. <^o > saves your file, continues in editing mode and allows you to change the name of the file if you want it stored under a different name.

The Vi editor
Vi is a quick and efficient text editor and can also be used to edit program files in UNIX. Vi allows you to change, add, or delete contents of files. This section introduces some of the basic Vi commands. A more complete reference guide to Vi commands is availiable online at: www.unm.edu/cirt/unix/unixhelp/vi/ref.html.

When editing an existing file, you are actually editing a copy of that file. Vi maintains two versions of the file the version you are editing and the original version. The original version is not updated until you save the edited version. After you log in and the $ prompt appears, you can use the vi command to create or edit a file. When using the vi command, you should specify a filename. For example, if you want to revise the file named examples.list, at the $ prompt type: vi examples.list and press <Enter>

If you want to edit a new file, type a name for the new file. A screen similar to the following will appear:

Vi displays the first 22 lines of the file. The tildes (~) indicate that there are no characters on the line. Vi displays information about the file you are editing and other messages on the status line at the bottom of the screen. If you open an existing file, the status line will contain the file name, the number of lines in the file and the number of characters in the file. For example, if examples.list contains 5 lines of text, made up of 330 characters, the status line would be examples.list 13L, 340C. The numbers near the right of the screen, e.g., 3, 9 show the line and character location of the cursor (line 3, character 9). If you start vi and do not specify a file name, Vi will open a new file with a blank status line. Most Vi commands are used with the <^> or the < : > (colon) key. The control key is used like the shift key; hold down the control key while pressing the next character. For example, <^p> means to press and hold the <Ctrl> key and then press the letter <p>. Note: If a capital letter is required for a command, it will appear as a capital letter in the key combination. For consistency, this document only uses a capital letter if the shift key is required as part of the key combination, e.g., <^P> = <Ctrl + Shift + P>.

Inserting text

When you start Vi, you are automatically placed in the command mode. Therefore, if you begin typing right away, Vi will interpret your keystrokes as commands. To change modes, press <Esc> (<esc> on a Macintosh). Although the following letter commands appear to overwrite text on the screen, nothing is actually changed in the file. Since only the screen display is affected, the overwritten text will be redisplayed when you press <Esc> and return to the command mode. <i> <I> <a> <A> <o> <O> <J> inserts text before the cursor position inserts text at the beginning of the line appends text after the cursor position appends text at the end of the line inserts a new blank line under the cursor position inserts a new blank line above the cursor position joins the line that the cursor is on with the line following it. When you are typing text, Vi automatically wraps the words to the next line. However, if you want to start a new line before Vi wraps the words, press <Enter>.

Navigating a vi file Vi allows you to view different parts of your document on the screen. Some of the commands work from the position of the cursor in the document. To use the following commands, you must be in the command mode. To change to command mode, press the <Esc> key once. When you are in the command mode, you can move around the file by using the following keys: <l> or <spacebar> <h> moves the cursor one character to the right

moves the cursor one character to the left

<w> <e> <b> <n + b>

moves the cursor to the beginning of the next word moves the cursor to the end of the current word moves the cursor one word to the left moves the cursor n (number) words to the left. For example, if you want the cursor to move six words to the left, type 6b. moves the cursor one word to the right moves the cursor n (number) words to the right. For example, if you want the cursor to move six words to the right, type 6w. moves the cursor down one line

<w> <n + w>

<j> or <Enter> <k> or - (hyphen) <n + -> <n + Enter>

moves the cursor up one line

moves the cursor up n (number) lines. For example, if you want the cursor to move up six lines, type 6- (6 + hyphen). moves the cursor down n (number) lines. For example, if you want the cursor to move down six lines, type 6 and press <Enter>. moves the cursor to the beginning of the current line moves the cursor to the end of the current line moves the cursor down (forward) one screen of text moves the cursor up (back) one screen of text moves the cursor down half a screen of text moves the cursor up half a screen of text

0 (zero) <$> <^f> <^b> <^d> <^u>

<^y> <^e> <^l> <H> <G> <n + G>

moves the screen up one line of text at a time moves the screen down one line of text at a time redraws the current screen (lowercase L) moves the cursor home to the top of the screen moves the cursor to the last line of the file moves the cursor to line number n of the file. For example, if you want the cursor to move to line number 75, type 75G

Deleting text To use the following commands, you must be in command mode. To change to command mode, press the <Esc> key once. When you are in command mode, you can delete text, spaces or blank lines while editing. <x> <dw> <dd> <d0> (zero) <d$> or <D> <dG> <p> <P> deletes a character (a number can be used to repeat a factor, e.g., 3x or 3dd) deletes a word deletes a line deletes back to the beginning of the line deletes to the end of the line deletes to the end of the file puts previously deleted text after the cursor puts previously deleted text before the cursor

To delete multiple lines of text: 1. Position the cursor at the first line of text to delete. 2. Carefully count the number of lines you want to delete.

3. Type the number of lines followed by dd. For example, if you want delete nine lines, type 9dd.

Note: If you delete some text by mistake, use the undo command, <u>, or the put command, which can be repeated. The put command is described in the following section, "Manipulating blocks of text."

Manipulating blocks of text Vi refers to moving and copying lines of text from one position to another as yanking and putting. When you move or copy text, Vi creates a temporary storage buffer to hold a copy of the text while navigating your file. The text that is placed back into the document, using the put commands, <p> or <P>, is retrieved from the temporary storage buffer.

Note: You should NOT use the arrow keys to move the cursor around in your document; strange characters may appear in your file. To move lines of text from one position to another, do the following: 1. Press the <Esc> key once to change to the command mode. 2. Position the cursor on the first line of text you want to move. 3. Count the number of lines to move. 4. Type the number of lines to move, followed by dd. For example, if you want to move six lines, type: 6dd. 5. Move the cursor to the position in the file where you want to place the lines. 6. Press <p> to put the lines after the cursor, or <P> to put the lines before the cursor. To copy lines of text from one position to another, do the following: 1. Press the <Esc> key once to change to the command mode. 2. Position the cursor on the first line of text you want to copy. 3. Count the number of lines to copy. 4. Type the number of lines to copy, followed by yy. For example, if you want to copy three lines, type: 3yy.

5. Type <p> to put the lines after the cursor, or <P> to put the lines before the cursor. Commands to yank and put back (like block and copy original text remains) <yw> <yy> or <Y> <y0> (zero) <y$> yanks a word and puts it in the buffer yanks entire line and puts it in the buffer yanks from cursor to beginning of line and puts it in the buffer yanks from cursor to end of line and puts it in the buffer

If you want to move or copy a number of times, you can name the temporary storage buffers where you want to place your text. Buffers are named with a single letter from a to z. The buffer name must begin with a double quotation mark, i.e., . If you do not begin the buffer name with , Vi may interpret it as a different command.

Note: You do not have to use buffer names, (a, b, c...) in sequential order. For example, if you have lines at the beginning of the file and you want them moved or copied to the end of the file, you can use two separate buffers to hold the lines as follows: 1. Position the cursor on the first line of text you want to move. 2. Count the number of lines to move. 3. Type a double quote mark (), the buffer letter and the number of lines to move and dd. For example, type a6dd if you want to move six lines and place them in buffer a. or 1. Position the cursor on the first line of text you want to copy. 2. Count the number of lines to copy. 3. Type a double quote mark (), the buffer letter and the number of lines to copy and yy. For example, type b9yy if you want to copy nine lines and place them in buffer b. Move the cursor to the position in the file where you want to place the lines.

Type ap to put the lines after the cursor, or aP to put the moved lines before the cursor.

Searching for text Vi allows you to search for specific text in a file. The search begins at the cursor position. Therefore, you will need to specify whether to search forward or backward through the file. To perform a forward search: 1. Press the <Esc> key once to change to the command mode. 2. Type < / >, the forward search symbol. 3. Type the text you want to search for. 4. Press <Enter> to start the search. The cursor moves to the first occurrence of the text. If Vi cannot find any occurrence, this message will appear: The pattern does not exist. To perform a backward search: 1. Press the <Esc> key once to change to the command mode. 2. Type <?>, the backward search symbol. 3. Type the text you want to search for. 4. Press <Enter> to start the search. The cursor moves to the first occurrence of the text. If Vi cannot find any occurrence, this message will appear: The pattern does not exist.

Changing text globally (Find & Replace) Vi will also search for specific text in a file and replace it with text you specify. The search begins at the cursor position. To find and replace text: 1. Press the <Esc> key once to change to the command mode. 2. Type :%s/ the command symbol for a global change search.

3. Type the oldtext. 4. Type < / >, the text separator. 5. Type the newtext. 6. Type < / > again. 7. Type <g> to indicate you want Vi to replace it globally. The complete command string in this example would be, :%s/ oldtext/newtext/g 8. Press <Enter>.

Note: If Vi cannot find an occurrence of the text, this message will appear: No match exists for the substitute pattern.

Saving and exiting a file Save early, save often! While you are working, you should save your file often to avoid losing text. When you are ready to save your file, press the <Esc> key once to change to the command mode. When you are in the command mode, use one of the following commands to save your file: :w :w filename :wq or ZZ :q :q! saves your file and continues editing saves your file with a new name and continues editing saves your file, exits the file, and exits the editor quits the Vi session without saving the file (you may receive an error message) quits the Vi session without saving any changes made after the last :w or command (overrides error message)

Chapter 7: Printing

Chapter Contents Guidelines Printer Commands names

The UNIX print command can be used for printing to most ITS-supported printers, including those located in ITS computer pods and the black and white production printer in Printer Output.

Guidelines

Preview as many drafts as possible on the computer monitor. Print only one copy of your document; if additonal copies are required, please use a copy machine. If you have problems formatting your document ask the scon for help. Documents of more than 20 pages should be queued to ITS' Printer Output. These print jobs can be picked up ouside Room 2118 in the ITS building. Please be considerate of other pod patrons, confirm you take only your prints from the printer output bin and leave prints belonging to others in the bin.

Printer names
Printers: HP LaserJet 8150 (unless noted). cirtpod dshpod-prt dsh142-prt dsh143-prt escn or esc2 escs or esc1 lobolab-prt lobocls-prt ITS Pod Dane Smith Hall pod Dane Smith Hall Classroom 142 Dane Smith Hall Classroom 143 Engineering & Science Northside Engineering & Science Southside Lobo Lab, SUB Lobo Lab classroom, SUB

fury

ITS Printer Output*

*IBM Infoprint 70. Pick up print jobs outside Room 2118 in the ITS building.

Commands
Type print commands at the UNIX ($) prompt. Printer names are listed above. lpr queues will print to the designated Windows printer in the selected ITS pod. The basic print job. At the $ prompt, type: lpr -Pprintername filename e.g., to print a basic potrait (tall) orientation print job in the ITS pod, type: lpr -Pcirtpod filename

To print multiple pages "up" on a sheet of paper. Replace lpr with mpage At the $ prompt, type: mpage -Pprintername -2 filename e.g., mpage -Pcirtpod filename would print 2 pages "up" on one sheet (one side) of paper at the ITS pod. By default, mpage orientation is landscape (wide). The number "up" can be 2, 4, or 8, e.g., -2 or -4 or -8

To print landscape (wide) orientation At the $ prompt, type: mpage -Pprintername -1 -l filename (-1 numeral one, -l lowercase L) e.g., mpage -Pcirtpod -1 -l filename would print landscape (wide).

Chapter 8: File Transfer


Chapter Contents Windows Macintosh

File Transfer is the ability to move files between a desktop computer and a server. As the popularity of GUI operating systems grew, support for command line file transfer programs (FTP) virtually vanished. Secure FTP was implemented by ITS in January, 2004, requiring the use of a secure file transfer program.

SFTP for Windows is available in the ITS computer pods and can be downloaded for personal use from ITS' Download page. Click SSH under the Windows heading. This will download both SFTP and the Secure Shell program for secure command line computing (replaces Telnet). Additional information and Help: How To 616 , Use Secure File Transfer Secure File Transfer

SFTP for Macintosh. Fugu was selected by ITS Macintosh consultants as a GUI alternative to the command line SFTP "built into" OS X. Fugu is available on the Macintoshes in ITS computer pods and can be downloaded for personal use from ITS' Download page. Additional information and Help: How To 716, Use Fugu for secure file transfer How To 715, SFTP with OS X

Secure File Transfer

S-ar putea să vă placă și