July 1999
Using UNIX commands -- an introduction
Is there any reason for me to learn UNIX? Those of us who use non-MAC PCs probably have one of the versions of Windows as our operating system. Especially with the later versions, one can perform most tasks by pointing and clicking. MAC users had these capabilities even earlier. Those of us who started to use PCs before Windows had to learn DOS commands in order to create directories, copy or delete files, and so on.
UNIX is the operating system of choice for servers. Folks who want to create and maintain Web pages will likely find themselves in a UNIX environment at some point. Some folks who have become fed up with Windows tendency to "crash and trash" have opted to install freely available PC versions of UNIX (for example LINUX). For on- line information about this type of operating system, which comes in both free and commercial versions,see "http://www.linux.org", "http://www.linux.com", "http://www.UNIXsystems.org" or use a search engine, such as "http://www.yahoo.com" and enter UNIX or LINUX as the search parameter. By the way, Bob Lucky's "Reflections" on free vs commercial activity in the May 1999 issue of Spectrum is worth reading if you haven't already done so.
Can I avoid using UNIX? In many cases, the answer is YES. But there are a few occasions, such as installing password protection (as noted in my June 1999 column), where one needs to log in to the server. If you connect to the Internet via a telephone line and modem and your connection is slow, it may be faster for you to log in and use UNIX commands, including the editor vi, rather than up- and down- loading files so that you can work on them using the Windows or DOS environment of your PC.
However, some of you may want to try the following, just to gain the experience and learn a little more about your server and how it works. The following examples assume a Windows environment on my PC and either a LAN or modem connection to the Internet.
Suppose I have some files on my server "power" and I want to copy or edit a file, or create a directory, or look at file permissions or change them, I can do this by logging in to that server using a Telnet session. I can invoke a Telnet session in several ways, double-click on a pre-configured Telnet icon, double-click on a MS-DOS icon and type "telnet machine_name" where machine_name is "power.eng. mcmaster.ca"(in my case - you substitute your server's name), or click on START, PROGRAMS, MS-DOS Prompt and type "telnet machine_name". You should next see the login prompt which requires you to enter your name and password. You can only log in to a server where you have previously arranged to have login permission from the system administrator of that server. Now we are in a UNIX environment and need to know some basic commands.
UNIX COMMANDS. These commands are used at the UNIX prompt, which may be a symbol such as % or $, or an abbreviated path that shows you which directory you are in.
UNIX is considered to be cryptic in style - error messages and explanations (when they exist) are very compact - when all is well, no system comments are provided - e.g. when you delete a file, there is no reassuring notification. UNIX is case sensitive - the filenames "Fname" and "fname" are different! Files and directories are treated and often displayed in the same manner. In the following explanations, xx, yy, zz are used to denote names of commands, directories, or files.
man xx display manual (information) about command xx
- example: man pwd will show information about the command "pwd"
pwd print (display) the full pathname of the working (current) directory
cd yy change to directory yy
- if yy is a single name, go down one level to that directory
- if yy is a full path spec (e.g. /xx/yy/zz, go to that directory
cd .. change to directory one up
mkdir yy make directory yy
rmdir yy remove (delete) directory yy (yy must be empty)
ls list in short format (names only) contents of current directory but not files starting with "."
ls -a list all contents of current directory
(including the normally hidden "." files)
ls -l list contents of current directory in long format
- includes permissions, ownership, date of last update
cat zz concatenate (display) contents of file zz
cat zz | more pages the display
rm zz remove (delete) file zz
mv xx yy rename file xx as yy, or if yy is a directory move xx into yy
cp xx yy copy file xx to yy (yy can be directory or file name or both) example: cp file1 subdir/file2 will copy file "file1" in the current directory to a subdirectory "subdir" and name the copy "file2"
chmod 700 xx change the access mode of file xx to 700. 700 is a compact code that permits only the owner of the file to read, write, or execute the file. 444 is another value that permits anyone to read the file. The default access mode values are determined by your system administrator (who you may need to contact), and may be different depending on how you create the file (e.g. using a UNIX editor, using FTP to copy a file created elsewhere, and so on).
ftp hostname, mail name@hostname - these are also UNIX commands that you can invoke to transfer files and send mail if you want to do it the primitive way (but you do not have the convenience of the newer user-friendly applications)
FOR MORE INFO. UNIX commands are described in the various
UNIX system manuals. You will probably find it easier to purchase a book
and keep it handy as you learn and gain experience. Reference 2 is
relatively old (in the time scale of computer advances) but still very
useful. Reference 3 covers UNIX in general, while Reference 1 (my
favorite) concentrates on communications features of UNIX.
- The Waite Group's UNIX Communications, 2nd ed 1991, by Bart Anderson, Barry Costales, and Harry Henderson, published by SAMS.
- The UNIX System, by S.R. Bourne (AT&T), 1983 ed, published by Addison-Wesley.
- The Waite Group's UNIX Primer Plus, 2nd ed 1991, by Michell Waite, Donald Martin, and Stephen Prata, published by SAMS.
COMMENT. UNIX is very powerful and comes in different
versions. There are many more commands and most commands have lots of
options. Take care and enjoy the world of UNIX.
Robert T.H. (Bob) Alden is the chair of the IEEE Electronic
Communications Coordinating Committee, and a former IEEE vice president.
In his other life, he is the director of the Power Research Laboratory
at McMaster University in Hamilton, Ontario, Canada.
He welcomes your input via
.
extracted from the IEEE website www.theinstitute.ieee.org
by Bob Alden
|