This document covers beginner Unix user commands and information.
This document was first written by Alex Batko in 1999; it was updated over the years, and most recently in September 2006.
This document is licensed under the GNU Free Documentation License: http://www.gnu.org/copyleft/fdl.html
This document along with others is available at the following URL: http://socsinfo.cs.mcgill.ca/wiki/Unix_Seminars
Please refer all complaints and comments to "help AT cs.mcgill.ca".
Seminars are given by system staff of the School of Computer Science (SOCS), of McGill Univeristy, as a service offered at the start of each fall and winter term. Apart from systems and network administration, SOCS system staff also provide a daily user support service called the SOCS Help Desk.
For information about upcoming seminars, please consult: http://socsinfo.cs.mcgill.ca/wiki/Unix_Seminars
The SOCS Help Desk is the user support centre for answers to computing questions of students, faculty, staff, and anyone else having a valid account at the School of Computer Science at McGill University.
The SOCS Help Desk is physically located at the McConnell Engineering Building, in room 209N. For help, call 398-7087 or send an email to email@example.com. For more information about the SOCS Help Desk, please consult: http://socsinfo.cs.mcgill.ca/wiki/Help_Desk
When sending mail to the Help Desk make sure to complete the subject field. Write one to four key words that are relavent to your email. Write short messages that get to the point. In most cases you should include the name(s) of the host(s), or computer(s), involved in your particular problem.
For information about issues specific to SOCS, such as user accounts, the network, and services, please consult: http://socsinfo.cs.mcgill.ca
All users must adhere to the McGill Computing Facilities (MCF) Code of Conduct. The MCF Code of Conduct is located at: http://www.mcgill.ca/ncs/policies/code/
Every user is responsible for their account. Users are not permitted to give-to nor share their account password with anyone. The account password must compose of 8 random characters, including atleast one letter, numeral, and symbol, and should not be a word, or set of words of any language. Users must protect their account password. Users must not attempt to circumvent security. Users must not execute binaries, and/or compile and run programs given by someone else. Users must never put a ``+'' in their .rhosts file.
At SOCS, we all adhere to a "congenial atmosphere", please do so as well.
UNIX is an operating system (OS).
UNIX has a convoluted history, but roughly speaking, it was originally invented by Ken Thompson in 1969. Dennis Ritchie, the inventor of the C programming language, is considered to be the co-author of the system. UNIX was reimplemented almost entirely in C during 1972-1974, making it the first source-portable OS. You can read more about UNIX in Wikipedia, a free encyclopdia, at: http://www.wikipedia.org/wiki/Unix
Technically, UNIX is proprietary software originally owned by AT&T, and now partially by Novell, SCO Group, and The Open Group - it's very unclear. Despite UNIX being one of the most influential operating systems in history, nowadays hardly anyone uses UNIX; instead people use variations of the original UNIX that have been created since the early 1980s, including many free variations (that is, free of restrictive copyrights), such as Debian GNU/Linux, RedHat Linux, FreeBSD, and OpenBSD. You can read more about the definition and philosophy of free software at: http://www.gnu.org/philosophy/free-sw.html
It is incorrect to refer to any of these variations as "UNIX"; it is better to say "UNIX-like". In practice however, because 99% of the time people only speak of UNIX-like systems anyway, the intended generalization is understood.
In this document, to acknowledge the distinction between the original UNIX and the loose generalization, the spelling "Unix", with only the first letter capitalized, will be used to refer to any common UNIX-like system.
Unix is a multi-user and multi-tasking operating system. "Multi-" is a combining form indicating "more than one". Therefore, in this context, multi-user means that a system is capable of being used by more than one user at the same time. Multi-tasking means that any user may run more than one task (aka program, or job) at the same time.
"User" is often a combining form indicating "a person or thing that uses"; in this context it is short for "computer-user". A "task" is any piece of work. [*]
If you are unfamiliar with a multi-user operating system you may wonder how so many users can use a computer at the same time.
To understand, first note the following terms. A device is a computer hardware designed for a specific task. A channel is a path along which data can be transmitted.
Next consider the keyboard (an input device) and the monitor (an output device) as a pair forming an input/output channel to a computer. A device having input/output links with a computer is called a terminal. Now imagine many such terminals attached to one Unix machine.
Sharing one computer is possible because Unix is a time-sharing operating system, that is, an operating system with which its users (at different terminals of a single computer running Unix) can, because of its design and high speed, seemingly (or apparently) communicate with it at the same time.
For the sake of order and security, each user of a Unix system has a separate account. An account is something like an office, because it is a place to do work and store things related to that work.
Each account is uniquely identified by a number called a user identification number (or uid for short), as well as an account name, generally referred to as a username, and an associated password (a secret word that ensures admission by proving one's identity).
Account information, along with absolutely all other information in a Unix system, is stored in entities called files, similar in concept to ordinary office files. Files can be grouped into directories, just as office files can be grouped into folders. A directory can contain files as well as other directories, just as an office folder can contain files and other folders. However, unlike office folders, which are limited by physical constraints, directories can be nested to no impractical limit.
To be nested means to be positioned within something. For directories to be nested means for them to be positioned within other directories.
One structural constraint of directories is that all directories ultimately stem from one directory called root (abbreviated as a single forward slash: `` / ''). Another constraint is that any single directory must contain files with unique names, but files in different directories can have the same name without any conflict.  [*] [1 TUPEnvironment, p. 21]
A filesystem is a logical subdivision of hard disk space. Characteristic of a Unix filesystem is its hierarchical structure. Hierarchy refers to any system of things or persons arranged in a graded order, such as the structure of government, or the socioeconomic structure of our society [*]. In this case we are talking about a system, or structure, of directories and files in a nested order, beginning with the root directory. [*][*]
The filesystem is recursively defined in the form of an upside down tree, starting with the 'root' directory at the top. Recall that the root directory is simply named ``/''. It is not contained in any other directory, but from it all other directories descend, directly or indirectly. A file path is a description of a file's residence relative to some directory. A file path relative to the root is called an absolute path, and would start with ``/''. Note that all subsequent slashes in a path name are delimiters that separate directory names.
While introducing the notion of a user account, it was mentioned that each account has an associated uid, username, and password for the sake of order and security. Well, futher to this reasoning, each account is also allocated a unique place on the filesystem to store the account owner's personal files and do work. That place is actually a unique directory within the filesystem, and is called a home directory (commonly abbreviated to home dir, hdir, or home). [*]
A path can be specified relative to a user's home directory, by a leading ``~'', or to parent directory (the directory immediately above any give directory), by a leading ``..''. A path can also be specified from the present working directory (pwd) by a leading ``.''.
No user is permitted to access another user's home directory, nor anything beneath it. Infact, it can be made possible for other users not to be able to even see what is within a user's home directory or their files. Equally so, it is also possible to grant permission for certain users, or all users, to read, write, and/or access a file or directory. The concept of permissions will be discussed within the intermediate-level material.
To use a Unix system, a user must have an account on that system, and must gain access to that account by proving identity by a process of authentication called log-in. A user "logs-in" by inputing a valid username and associated password. [*]
Logging-in is possible in two ways: via a graphical user interface (aka graphic console), or via a text user interface (aka text console). An interface is a common point, boundary, or link between two things - in this case it is a link between a human and a computer.
Regardless of how you login (short for log-in), you must enter your username and password (each followed by pressing the ENTER key). Two things to note are that the username must be typed in lower case, and that when you type your password, the characters will not appear on the screen. The password is concealed in case someone is peeking over your shoulder.
A login session (or session for short) is established upon successful entry of the username and password. "Session" is a "lasting connection", which in this case is between a user and a system.
The appearance of the login session via the text console will be significantly different from the login session via the graphic console. Both have advantages and disadvantages depending on the circumstance, but as far as the following instructional example is concerned, the graphic console requires an additional step to arrive at something that the text console immediately provides.
So if you've logged-in via a graphic console, the additional step is that you will have to open what's called a terminal window (aka terminal, or term). This can be accomplished by using the mouse to click on a terminal window icon, or by selecting a "terminal window" option from a mouse menu, though the specifics will be very system-dependant.
Regardless of login method, the login event will be registered (or logged), in a log file. Following the opening of a terminal window, the things that follow will be the same as what appears on the text console.
After you have logged-in, and in the case of a graphic console, after you have also opened a terminal window, the system might display a message of important information, known as message of the day (or motd for short).
Following the possible motd, you will be presented with a command-line consisting of a command-prompt and a cursor.
A command-line is a row on which commands (instructions for the system) can be entered. A command-prompt (or prompt for short) is a symbol that indicates the beginning of a command-line. When a shell is ready to recieve commands, it displays a command prompt. A cursor is a movable point that identifies a specific position on a visual display unit. In the case of a command-line, the cursor is usually either a blinking or solid underscore or vertical bar, that marks the current typing position.
A shell can read command lines from a terminal (interactively) or it can read them from a file (this is known as a shell script). Shell scripting will be discussed within the advanced-level material.
The symbol that represents the prompt could be something as simple as a single character, like a dollar sign (``$''), or a percent sign (``%''). It could also be the name of the machine you're using in square brackets (``[tron]''), or something even more elaborate.
The command line, prompt, and cursor are visual aids of what's called a command interpreter (or shell for short). The shell understands a certain language known as a shell command language, which is used to access a computer system. Commands entered on the command-line are passed to the shell for execution by the system, therefore the shell is an interface to the system.
At this point, nothing will happen unless you enter a command. Charles Snow, a former instructor at McGill University, once said: "The shell waits with amazing patience and anxiety for you to type something." [*][2000.09.19]
Every command has the same structure: the command name, which tells the shell what command you want the system to execute; and the arguments, which detail what you want the command to do, how you want it to do it, and to what you want it done. Some commands consist of only the command name, and do not take arguments; on the other hand, some commands require arguments.
The arguments are also known as parameters, and are separated from each other by spaces. The parameters are separated by spaces to distinguish one parameter from another. The parameters of the command are further divided into options and names. Options are usually prefixed by a hyphen (``-''), or double hyphen (``--''). Names usually name the files that the command should use in its operation.
command_name [option(s)...] [name(s)...]
Let's assume that the prompt is a percent sign. A simple command to try for the first time is one that invokes a program that reports the date and time. The program is called ``date'', and the command requires nothing more that that. Type "date" and press ENTER. The system will respond by displaying (aka printing) the date and time, followed by another prompt.
% date Tue Mar 4 03:59:55 EST 2003 %
The ENTER key must be pressed to invoke all commands, so from this point on in this document that will be implicit.
A user's initial working directory is that user's home directory. Since we haven't done anything to change it, it will still be that, but we can confirm just out of curiosity. In fact, you can determine your present working directory at any time by typing the command ``pwd'', as follows.
% pwd /home/users/abatko %
The proper way to logout (exit the terminal, or session) is to simultaneously press the CTRL key and D, although if that doesn't work, you can also logout using the command ``exit''.
An editor is a program that enables the creation and modification of text files. For a detailed coverage of the most common text editors at SOCS, read the web page: http://www.cs.mcgill.ca/~navindra/editors/
This is a list of some editors described on the aforementioned web page:
% gedit - Simple text editor for Gnome with syntax highlighting and spell check. % kate - Simple text editor for KDE with syntax highlighting and spell check. % xemacs - XEmacs is perhaps the easiest power editor for newcomers to use. XEmacs splintered off of the GNU Emacs effort some years ago; though today GNU Emacs and XEmacs are mostly still the same, each has a variety of features not supported by the other. % emacs - GNU Emacs is a remarkable editor and its various characteristics such as extensibility, customizability, and innumerous bundled packages are particularly appealing to the programmer. % nano F - Nano is a simple text-only editor, suitable for a novice or anyone wishing to invest only a minimum amount of time in learning an editor. % pico F - Pico is a simple text-only editor, suitable for a novice or anyone wishing to invest only a minimum amount of time in learning an editor. % vi - Vi is one of the most powerful and versatile editors with an abundance of features such as macros, and filter and scripting support. On top of this, vi is available on just about every UNIX-like system, and is very lightweight. It should also be noted that vi has two modes: a command mode, and an insert mode. % vim - VIM is Vi IMproved and has many advantages over standard vi.
If you try vi or vim and you don't know how to quit, press the escape key (``ESC''), followed by ``:q!'' (colon, q, exclamation).
The most important "basic" commands are ones that enable you to deal with the filesystem. Let the symbol ``%'' represent a "command prompt".
% pwd - Display the absolute path name of the present working directory, also known as the "current working directory", or just "working directory".
% ls - List the contents of the present working directory, ordered in columns, and sorted alphabetically. % ls D - List the contents of directory D.
% cd - Change the pwd to the user's home directory. % cd D - Change the pwd to the directory D. % cd - - Change the pwd to the previous working directory. (Note that "previous" does not mean "parent"; it means the directory that was pwd immediately prior to what it currently is. Using a hyphen (``-'') in this manner will only work for cd, it will not work for other commands.)
% mkdir D - Make directory D.
% rmdir D - Remove directory D. This will not be allowed if directory D is the pwd, is not empty, or the permissions of the directory don't allow for it to be removed.
% less F - View the contents of file F, one screenful at a time. To scroll forward press the SPACEBAR, or ``f''. To scroll backward press ``b''. To return to the top of the file, press ``g''. To quit viewing the file, press ``q''.
% cp F1 F2 - Copy file F1 onto file F2. If file F2 is already present, it is overwritten by file F1, otherwise file F2 is created with the content of file F1. % cp F D - Copy file F to directory D. % cp F... D - Copy each given file to directory D.
Note that ``cp'' will overwrite the destination file if it already exists. To be prompted for confirmation before overwriting the destination file, use the ``-i'' flag.
% mv F1 F2 - Move (rename) file F1 onto (as) file F2. % mv F D - Move file F into directory D. % mv F... D - Move each given file into directory D.
Note that ``mv'' will overwrite the destination file if it already exists. To be prompted for confirmation before overwriting the destination file, use the ``-i'' flag.
% rm F - Remove file F. % rm F... - Remove each given file.
Note that ``rm'' will delete the specified files without confirmation. To be prompted for confirmation before removing any files use the ``-i'' flag.
The on-line reference to commands is called the Reference Manual Pages, or manpages for short. Manpages describe most commands available on the system, providing both quick reference and detailed coverage. An interface to this on-line reference maual, is a utility called ``man''. Manpages are separated into nine "sections". Section 1 is the most important section to users, since it describes all user commands (executable programs and shell commands):
The manpages themselves may be subdivided into "parts" most commonly labelled as follows:
NAME - The name of the command being described. SYNOPSIS - A pattern describing all possible invocations of the command. DESCRIPTION - Detailed description of the command. OPTIONS - Description of arguments illustrated in SYNOPSIS. FILES - Description of files associated with the command. SEE ALSO - References to related commands. HISTORY - Brief history of the command's creation. BUGS - Outline of known problems with the command. AUTHOR - Who wrote the command.
How to use the man utility:
% man C - Display the manpage for command C. % man -k K... - Search the short manpage descriptions and manpage names for the keyword(s) K, and display all matches.
The actual sections of the Reference Manual Pages vary from system to system; the following is just a sample:
1 User Commands. (executable programs or shell commands). ex. chmod(1) 2 System calls (functions provided by the kernel). ex. creat(2) 3 Library calls (functions within system libraries). ex. stdio(3) 4 Special files (usually found in /dev). ex. pci(4) 5 File formats and conventions. ex. /etc/passwd 6 Games; (though really there are none). 7 Macro packages and conventions. 8 System administration commands (usually only for root). 9 Kernel routines [Non standard].
Sometimes a command will appear in more than one section. To specify a particular section precede the command name with a section number:
% man N C - Display the manpage from section N of the manual, corresponding to command C.
There are two types of computer resources available for users to get work done, namely workstations and compute servers. Workstations are physically accessible machines for users to sit in front of to do their work. Compute servers are not physically accessible, and are ones designated for remote login (discussed below) for the purpose of running applications for any number of reasons such as more compute power, uninterrupted execution time, special appications, etc.
All labs are located in Trottier building, on the 3rd floor; these are currently accessible by all students holding valid SOCS computer accounts, and taking CS and/or ECSE courses. As far as Unix-like systems are concerned, SOCS labs are populated only by free unices, namely FreeBSD and RedHat Linux.
For more information about SOCS labs, including hours of operation, please consult: http://socsinfo.cs.mcgill.ca/wiki/Labs
SOCS provides several compute servers for those wishing a platform for long-running, or to try out a different version of UNIX than they are used to. The compute servers are only available by remotely logging in.
Some of the compute servers run by the proprietary Unix flavor called Solaris (from Sun Microsystems) - mainly because they are Sun Sparc machines.
For more information about SOCS compute servers, please consult: http://socsinfo.cs.mcgill.ca/wiki/Servers
* skinner * mimi * willy
For more information about SOCS compute servers, please consult: http://socsinfo.cs.mcgill.ca/wiki/Servers
Logging into a remote machine is possible by using a remote login program. Further to remotely access a SOCS machine it is necessary to use a secure remote login program, often referred to as a secure shell client. ``ssh'' is the program available on every SOCS machine for this purpose. To log in from home or elsewhere, you must also use a secure shell client. For more information about ssh please consult: http://socsinfo.cs.mcgill.ca/wiki/SSH
Below is an example of how to log into the compute server mimi for the first time; it is necessary to answer ``yes'' to continuing the connection.
% ssh mimi The authenticity of host 'mimi (188.8.131.52)' can't be established. RSA key fingerprint is 7e:c0:74:f3:ff:36:44:7f:2b:69:9a:da:7d:92:e0:fb. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'mimi,184.108.40.206' (RSA) to the list of known hosts. abatko@mimi's password: ******** [mimi] %
After mimi has been added to "the list of known hosts", this question will not have to be answered unless mimi's "RSA key fingerprint" changes.
Once you're logged in, you can type commands on the remote compute server just as you would on the local host. To exit the remote server, type ``exit''.
[mimi] % date Fri Sep 19 08:49:41 EDT 2003 [mimi] %
Recall that every account is given a home directory on the filesystem to store the account owner's personal files. Filesystem disk quota, (or quota for short) is a prescribed limit to the amount of disk space that an account can use on a given filesystem. Accounts are limited to the amount of space that they can use so that disk space usage can be controlled.
Each account has two filesystem quotas: hard quota, and soft quota.
The hard quota is the maximum amount of disk space that the system permits a given account to use. Reaching the hard quota can have nasty side effects: the system will not permit any operation that requires using additional disk space; attempting to edit files my corrupt them; and logging-in may fail (this problem is discussed below). The hard quota takes effect as soon as it is exceeded.
The soft quota is less than the hard quota and it is the point at which the user will be warned about approaching the hard quota. The warnings depend on the operation performed when attempting to write data, and also on the system that the operation is being performed on. It is important that users resolve the quota problem as soon as possible because of the severe consequences that may result when the quota limit is approached. Exceeding the soft quota for more than seven days automatically turns the soft quota limit into the hard quota limit.
A user can display her/his own filesystem disk quota and usage using the command ``quota -v''. The command displays both quotas and usage in kilobytes, as in the following example:
% quota -v Filesystem usage quota limit /net/u21 16522 19500 20000
It is common that when attempting to login via a graphic console, the login process may momentarily display the graphical desktop environment, and then immediately be thrown back to the login prompt. This behaviour indicates that the account has approached too close to the hard quota for the windowing program to be able to write data to special files in the account's home directory - which is something that some windowing programs do as part of their operation. To resolve this problem it is necessary to login via the text console.
Simultaneously press Ctrl-Alt-F1 to switch from a graphic console to a text console. To switch to a graphic console from a text console simultaneously press Alt-F3 or Alt-F7. Note that the "Ctrl" key is not necessary when going from text to graphic console. If you can't find what you're looking for on either direction, there is no harm in cycling through all the function keys (F1-F12).
Once you're log in, regardless of whether it is via the graphic console or the text console, you will need to delete some files to return to below the soft quota limit. Commands to delete some directories and files are listed below:
If deleting these files doesn't help, you will have to visit a System Administrator for further assistance.
Passwords at SOCS are synchronous amongst Unix, Windows, and Mail accounts. To change your password, you must log into mimi and issue the passwd command:
[mimi] % passwd
Any user whose username is longer than 8 characters must pass the username as an argument to the command:
[mimi] % passwd username
For more information, please consult http://socsinfo.cs.mcgill.ca/wiki/Password
The World Wide Web (WWW) is a universe of network-accessible information. Tim Berners-Lee invented the World Wide Web in late 1990 while working at CERN, the European Particle Physics Laboratory in Geneva, Switzerland.
It has a set of protocols and conventions, and uses hypertext and multimedia techniques to enable anyone to browse it, or contibute to it. Evolution of WWW is coordinated by W3C - World Wide Web Consortium, http://www.w3c.org/
% lynx - A text based, frame and java disabled WWW browser.
If you are logged-in via a graphic console, look around the graphical desktop environment for an icon to laungh a graphical WWW browser. If you can't find an icon, you can enter one of these commands:
% firefox % opera % konqueror % seamonkey % galeon % epiphany
IMAP and POP3 are two different mail paradigms:
The mail system at SOCS is built around an independent mail server mail.cs.mcgill.ca, supporting both POP and IMAP.
``webmail'' is the preferred mail client for most users because it is web-based, intuitive, and full of important features such as spam control and mail filtering.
Note that the incomming mail server is "mail.cs.mcgill.ca", and within the CS domain the outgoing mail (SMTP) server is also "mail.cs.mcgill.ca". If you are outside the CS domain, you can try "mailhost.mcgill.ca".
For more information, please consult http://socsinfo.cs.mcgill.ca/wiki/Mail
Once you've used an editor to create your program, you are ready to complie it. Depending on what language you used to write your program, you will need an appropriate compiler.
Please note that the word "foo" is used very generally as a sample name for absolutely anything, especially programs and files. To avoid confusion, "foo" is never made the name of a real file.
% cc foo.c - C complier. Compiling the program foo.c may result with the creation of an executable program called a.out or an error message from the compiler. % gcc foo.c - GNU project C compiler. Compile the C program foo.c. % g++ foo.cpp - GNU project C++ compiler. Compile the C++ program foo.cpp. % javac foo.java - Java compiler. Compile the java program foo.java into a file called foo.class.
At SOCS, we have several different versions of the java compiler installed on the workstations. Please see http://socsinfo.cs.mcgill.ca/wiki/Java for information on how to switch between versions of java.
To run an executable file (also known as a binary), simply type its name at the command prompt.
% ./a.out - Run the binary a.out.
Compiled java programs (also known as java bytecodes) must be interpreted by a java interpreter.
% java foo - Execute the Java bytecodes.
% ./a.out > foo.txt - Run the binary a.out and send its output to the file foo.txt. % ./a.out >! foo.txt - Run the binary a.out and overwrite an existing version of the file foo.txt.
[mimi] % handin csxxx assx F... - Electronically submit the file(s) F, into assignment box assx, of the computer science course csxxx.
For more information about, please consult: http://socsinfo.cs.mcgill.ca/wiki/Handin
Assignment submition may (depending on course and instructor) also be done via WebCT at: http://www.mcgill.ca/webct/
To print at SOCS, a user must have a positive printing fund balance. The issuer can check her/his balance using the ``balance'' command on any lab machine.
[lab6-1] % balance
It is not possible to print plain text files directly. Plain text files (aka ASCII files) can be printed using the command ``a2ps'' with the -d option to print to the default printer. To print to a non-default printer, use the -P option.
% a2ps -d file.txt % a2ps -P name file.txt
There is a printer in each lab room. The printers are named lp#, where # is a lab room number. For instance, lab 3070 is referred to as lab 7, so the printer in lab 7 is named lp7.
For more information please consult http://socsinfo.cs.mcgill.ca/wiki/Printing
This document was generated using AFT v5.0792