0% found this document useful (0 votes)
4 views29 pages

Unix Fundamentals Chapter 01

The document provides an overview of UNIX, including its history, architecture, popular shells, and basic commands. It explains the significance of UNIX as a multi-user operating system created in C for portability and highlights its evolution, including the development of Linux. Additionally, it covers the use of terminal windows, logging in and out, and basic process management commands.

Uploaded by

gauravsom789
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views29 pages

Unix Fundamentals Chapter 01

The document provides an overview of UNIX, including its history, architecture, popular shells, and basic commands. It explains the significance of UNIX as a multi-user operating system created in C for portability and highlights its evolution, including the development of Linux. Additionally, it covers the use of terminal windows, logging in and out, and basic process management commands.

Uploaded by

gauravsom789
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

UNIX Fundamentals Workshop 9

______________________________________________________________________________

Chapter One

A Quick Tour of UNIX


In This Chapter
History
Architecture
Popular Shells
Using Exceed
Logging In / Logging Out
Processes
User and System Date Information
Files
Directories
Scripts
Cleanup
10 UNIX Fundamentals Workshop
______________________________________________________________________________
UNIX Fundamentals Workshop 11
______________________________________________________________________________

In This Chapter – a brief overview

Command Action

cp file1 file2 copies the contents of file1 to file2

date display current system date and time

echo text print or ―echo‖ text to screen

ls display contents of directory

logout / exit logout or exit the system

mkdir directory create a directory

mv file[s] directory move file(s) to given directory

mv file1 file2 renames file2 to file2. If file2 already exists, its contents
will be overwritten with the contents of file1.

ps list processes owned by current userid

pwd print current working directory

rm file[s] remove given file(s) from directory

rmdir directory remove an empty directory

stty –a list current terminal settings

who list users currently logged on to system

whoami / who am I list current userid


12 UNIX Fundamentals Workshop
______________________________________________________________________________
UNIX Fundamentals Workshop 13
______________________________________________________________________________

History:

UNIX is a robust multi-user operating system that was created with the future in mind.

Before its creation, most operating systems were written in assembler, which is a low-level language
that produces vendor specific instructions. The resulting operating systems were proprietary, and
left the consumer with no choice but to purchase expensive hardware and software on which to run
their enterprise. The proprietary nature of the systems also left them unable to communicate with
other vendor‘s systems without additional software. The proverbial left hand and right hand weren‘t
even on the same planet, much less able to communicate in the same language.

UNIX changed everything. It was originally created by Dennis Ritchie and Ken Thompson of
AT&T. They used ―C‖ to write the majority of the operating system. ―C‖ is a high level language
that is extremely portable. It is therefore relatively easy to port UNIX and its applications from one
hardware vendor‘s system to another, which explains why you can find UNIX on pretty much any
available hardware (even a mainframe).

They also included in UNIX many powerful tools that, when combined with each other, give the user
a great deal amount of control over their programs and environment. It is much more than a simple
file system and process control center. Unfortunately, it is the robust nature of UNIX and its seem-
ing complexity that make mastering it a daunting task. Unfortunately, it was written by geeks to be
used by geeks – so there isn‘t much fluff to help you along when you are first getting started.

AT&T‘s version of UNIX (System V) was distributed to many academic institutions for a small fee,
but they were not able to provide support for their distribution. The University of California at
Berkeley (UCB) created a UNIX of their own based on AT&T‘s original work. This is commonly
referred to as BSD UNIX. UCB added some important features to the original work by AT&T.
They created the vi editor, as well as provided the TCP/IP networking protocol with their version of
UNIX.

As time passed, more and more hardware vendors took one of the two original versions of UNIX and
modified it to be shipped with their own hardware. A tweak here and a tweak there, and soon, the
UNIX culture had become defined by the incompatibilities of each vendor‘s offering.

There have been several attempts to standardize UNIX in recent years. Some of these include
AT&T‘s System V Interface Definition (SVID), POSIX (the Portable Operating System Interface to
Conputer Environments), as well as the Single UNIX Specification.

Linux is a free version of UNIX that, among other systems, can be run on Personal Computers. It is
distributed under the GNU Public License that requires all Linux source code be made available to
the public. Red Hat, SuSE and Mandrake are some of the most well known Linux distributions.
There are also free databases to run on Linux, such as MySQL. It is a relatively inexpensive endea-
vor to setup a Linux machine as a Web Server with access to a database on a low cost Personal Com-
puter. Support is getting easier to come by as well, as the Linux community is one that can easily be
14 UNIX Fundamentals Workshop
______________________________________________________________________________
accessed via various newsgroups on the Internet. All of these advantages combined are why Linux
is being used more and more by businesses around the world.

Note: You can easily download a Linux distribution and install it on your PC. Most distributions
will detect a Windows installation, and automate the process for you that creates a dual-boot machine.
UNIX Fundamentals Workshop 15
______________________________________________________________________________

Architecture

The UNIX kernel is central to all operations and services available. Users and their processes do not
actually have access to the machine‘s hardware directly, but must interact with a system call interface
(API) that the kernel provides. The kernel has many jobs – including, but not limited to:

communicate with the system hardware


manage system memory
schedule system processes
enforce security mechanisms
maintain the location of physical files on the hard disk
control task swapping, prioritizing and process management
provide an interface for user processes via the shell process

In order to communicate with the kernel, a user requires an interpreter known as the shell process.
The shell is the interface between the UNIX kernel and the user. There is only one kernel process on
a UNIX system, but it keeps up with all shell and system processes.
16 UNIX Fundamentals Workshop
______________________________________________________________________________

Popular Shells

Name Abbrev Description

Bourne sh Original UNIX shell written by Steve Bourne of Bell Labs.


Available on all UNIX systems Does not have the interactive fa-
cilities provided by modern shells such as the C shell and Korn
shell.

C csh Written at the University of California, Berkeley. Provides C-


like language with which to write shell scripts.

TC tcsh Public domain shell. Provides the features of C shell with emacs-
style editing of command line.

Korn ksh Written by David Korn of Bell labs and now standard shell
provided on UNIX systems. Delivers all features of C and
TC shells with a shell programming language similar to that
of Bourne. Default shell used at SAS.

Bourne bash Public domain shell written by the Free Software Foundation
Again under their GNU initiative. Intended as full implementation of
SHell IEEE Posix Shell and Tools specification. Widely used within
or Bash the academic community. Provides all interactive features of C
and Korn. Its programming language is compatible with Bourne.

Note: The majority of examples in this book are written to be used with the Korn Shell (/bin/ksh).
UNIX Fundamentals Workshop 17
______________________________________________________________________________

Shell Comparisons

Bourne C TC Korn BASH

command history No Yes Yes Yes Yes

command alias No Yes Yes Yes Yes

shell scripts Yes Yes Yes Yes Yes

file name completion No Yes* Yes Yes* Yes

command line editing No No Yes Yes* Yes

job control No Yes Yes Yes Yes

* not default setting for shell

Note: A more detailed comparison chart is available at http://sww.sas.com/~legeros/Work/


Unix/shell-comp-chart.html.
18 UNIX Fundamentals Workshop
______________________________________________________________________________

Terminal Windows

Xterm Terminal Window

The shell runs inside a terminal window, an application that accepts user-entered input for the shell.
Terminal windows available at SAS include Xterm and Jterm. For the purposes of this class, we will
be using the Xterm, as that is what will be available at customer sites.
UNIX Fundamentals Workshop 19
______________________________________________________________________________

Diagram

Terminal Window

Shell

Kernel
20 UNIX Fundamentals Workshop
______________________________________________________________________________

Xterm

Xterm

The terminal-window application Xterm is typically available on all UNIX systems. The Xterm ap-
plication can be invoked from Windows using special emulation software called Exceed. The Exceed
application Xstart invokes UNIX applications, using either desktop icons or the Start Menu.
UNIX Fundamentals Workshop 21
______________________________________________________________________________

Opening an Xterm Window

To open an Xterm window using Hummingbird Exceed:

1. Select from the taskbar:

Start  Programs  UNIX Applications  Xterm

-or-

Select the Xterm icon on your desktop:

The Xstart dialog box displays.

2. Enter your UNIX username and password.

3. If necessary, enter a host name (mkt.fyi.sas.com).

4. Choose OK.

Note: Use the Tab key to change fields in the Xstart dialog box.

Note: If you already have an xterm window open, issuing the xterm & command also opens an
additional Xterm window.
22 UNIX Fundamentals Workshop
______________________________________________________________________________

Diagram

Windows

Exceed
Xstart

Xterm

Korn Shell

Kernel
UNIX Fundamentals Workshop 23
______________________________________________________________________________

X-Windows and Exceed


The program X-Windows creates and controls the appearance of application windows on UNIX, as
displayed both on UNIX workstations and Windows via Exceed.

Diagram

Windows

Exceed
Xstart

X-Windows

X-Term
Korn Shell

Kernel
24 UNIX Fundamentals Workshop
______________________________________________________________________________

Larger Fonts

To open an Xterm or Jterm window with larger-sized fonts, add the following X-resource option

-fn some-font

to the Xterm or Jterm command, either entered at shell prompt or via Exceed Xstart window.

Examples

Shell xterm -fn 10x20 &


Prompt

Xstart
Window

Finding Fonts

To display a list of font choices, enter the xlsfonts command.

To sample a particular font, enter the xfd -fn some-font & command.
UNIX Fundamentals Workshop 25
______________________________________________________________________________

Exceed

The Windows application Exceed emulates the X-windows UNIX environment. Exceed tools availa-
ble by selecting Start  Programs  Hummingbird Connectivity v7.1 from the Taskbar include:

Application Description

Client Wizard Easily enter information needed to start a UNIX program (or X client) and
optionally create both startup files and corresponding shortcuts.

Launch Pad Launch applications and manage your program windows. Also includes a
Virtual Desktop that effectively increases the size of your Windows desk-
top display area.

Ping Send Internet Control Message Protocol (ICMP) echo request packets to
network host.

Remote Tools Execute commands on and copy files to another computer on the network,
using the RSH and REXEC protocols.

Telnet Connect to another computer on the network, via terminal emulation.

Xconfig Configure the X server. Options: input, communication, video, protocol,


security, screen definition, performance, X selection, font, troubleshooting,
transports, and system administration settings.

Xstart Create and install icons, to easily start frequently used UNIX programs,
with username and password preset, if desired.
26 UNIX Fundamentals Workshop
______________________________________________________________________________

Marking and Pasting

Exceed also enables easy marking and pasting of text between application windows on UNIX and
Windows.

Note: If using a two-button mouse, press both buttons simultaneously to emulate middle mouse-
button behavior.

Hosts First Window Second Window

UNIX UNIX Highlight text. 1. Position cursor at posi-


tion to paste.
2. Press middle mouse but-
ton.
UNIX Windows 1. Highlight text. 1. Position cursor at posi-
tion to paste.
2. Click on in upper left
corner. 2. Select Edit Paste
3. Select Edit Copy X -or-
Selection to Clip-
board. press Ctrl + V
Windows UNIX 1. Highlight text. 1. Click on in upper left
corner.
2. Select Edit Copy
2. Select Edit Paste to X
-or- Selection from Clip-
Highlight the text and board.
press Ctrl + C. 3. Position cursor at posi-
tion to paste.
4. Press middle mouse but-
ton.
Windows Windows 1. Highlight text. 1. Position cursor at posi-
tion to paste.
2. Select Edit Copy
2. Select Edit Paste
-or-
-or-
Press Ctrl + C.
Press Ctrl + V
UNIX Fundamentals Workshop 27
______________________________________________________________________________

A Quick Tour of UNIX


The next few pages will quickly walk you through some basic commands in UNIX. This chapter is
not intended to provide you with in depth information. It is intended to be a quick ―get your feet
wet‖ kind of chapter that gets you moving around on a UNIX system.

Logging in and Logging out:

On a conceptual level, when you login to a UNIX machine, your ―identity‖ consists of three things: a
userid, a password, and an associated group. Anything you do will be associated with your userid,
commonly referred to as UID. If you create a file, it will be owned by you. If you send mail to a
friend, you will be logged as the sender. If you run a SAS/SHARE server, that process will be
owned by you.

For the purposes of this class, we will be using HP 10.20. An example (internal to SAS) login fol-
lows:

login012> rlogin mkt.fyi.sas.com -l sssims Enter


Password: ******** Enter
login020>

Your UNIX system is now running a shell on your behalf which is waiting to run commands or utili-
ties. This shell process works between you (the user) and the operating system. We‘ll talk more
about shells later, but for now it is just important that you realize you are already interacting with a
process.

When you are ready to exit the UNIX system, execute one of the following commands:

login020> logout Enter

or

login020> exit Enter

One of those should return you to a login prompt and leave the system ready for another user.

If you are using Exceed, your xterm window will close when you logout.
28 UNIX Fundamentals Workshop
______________________________________________________________________________

Terminal Settings

Everything you enter on a UNIX command line is dependent on your terminal‘s properties. Have you
ever logged into a UNIX machine and had your [backspace] or [delete] keys not work as you would
expect them to? If so, the stty command can come to your rescue.

Display all (-a) current stty settings for your terminal (shell):

login012> stty -a Enter


speed 9600 baud; line = 0;
rows = 37; columns = 80
min = 4; time = 0;
intr = DEL; quit = ^\; erase = ^H; kill = @
eof = ^D; eol = ^@; eol2 <undef>; swtch <undef>
stop = ^S; start = ^Q; susp = ^Z; dsusp <undef>
.
.
.

In the above output, the ―kill‖ command is set to the ―@‖ key. This is a common setting, though not
a desirable one. Effectively, each time I type the ―@‖ sign within a command – such as in an email
address or an oracle database alias – only the characters that appear AFTER the ―@‖ will be sent to
the shell . There are ways of escaping it, of course, which we will find out about later. For now, let‘s
change it to Control-K:

login020> stty kill \^K Enter


login020> stty –a <enter>
speed 9600 baud; line = 0;
rows = 37; columns = 80
min = 4; time = 0;
intr = DEL; quit = ^\; erase = ^H; kill = ^K
eof = ^D; eol = ^@; eol2 <undef>; swtch <undef>
stop = ^S; start = ^Q; susp = ^Z; dsusp <undef>
.
.
.
UNIX Fundamentals Workshop 29
______________________________________________________________________________

Processes:

Now, login to your UNIX system again. Once you get logged into the system, execute the following
command:

login012> ps Enter

This ps command, when given without any arguments, will list all processes currently running on the
system that are owned by your UID:

login012> ps Enter
PID TTY TIME CMD
28164 pts/2 0:00 ksh

Every process running on UNIX has an associated Process Identification number associated with it,
commonly referred to as the PID. The PID of the only process I am currently running is 28164. The
command (CMD) running under that PID is ksh, which is the Korn Shell process I am interacting
with.
30 UNIX Fundamentals Workshop
______________________________________________________________________________

Processes (cont’d):

To get an idea of how many processes are running on the UNIX machine by all users, execute the fol-
lowing command:

login012> ps -ef | more Enter

UID PID PPID C STIME TTY TIME CMD


root 0 0 0 Dec 24 ? 0:07 sched
root 1 0 0 Dec 24 ? 43:38 /etc/init -
root 2 0 0 Dec 24 ? 0:01 pageout
root 3 0 1 Dec 24 ? 10787:59 fsflush
root 912 1 0 Dec 24 ? 0:00 /usr/lib/saf/sac -t 300
root 909 1 0 Dec 24 ? 0:00 /bin/sh ./bin/mysqld_
oracle 25899 1 0 Jan 17 ? 3:30 ora_ckpt_ora10g
root 634 633 0 Dec 24 ? 0:00 /usr/sbin/ccv -f
root 758 1 0 Dec 24 ? 0:01 /usr/dt/bin/dtlogin
root 129 1 0 Dec 24 ? 0:01 /usr/lib/picl/picld
.
.
.
.

Following is a short description of each column you see listed:

UID: The userid that owns the process


PID: The process ID that the UNIX system has assigned the process
PPID: The process ID of the parent process from which the PID was started
C: Processor Utilization – not something we need to worry about
STIME: The start time of the process. If more than 24 hours has elapsed, the date will be listed
TTY: The controlling terminal for the process
TIME: The cumulative execution time for the process
CMD: The command that is running under this PID
UNIX Fundamentals Workshop 31
______________________________________________________________________________

User and System Date Information:

Use the who command to list all users that are currently logged into the system:

login012> who Enter

dbitest pts/48 Mar 3 10:37 (garage.unx.sas.com)


noe pts/21 Mar 3 12:08 (D8710.na.sas.com)
sasts pts/46 Feb 28 13:48 (login001.unx.sas.com)
sherman pts/33 Feb 22 16:45 (kerouac.unx.sas.com)
osrmgr pts/27 Mar 3 10:38 (login009.unx.sas.com)
dam pts/24 Mar 3 08:10 (doors.unx.sas.com)
dbitest pts/34 Mar 3 10:40 (login011.unx.sas.com)
osrmgr pts/25 Mar 3 11:21 (login017.unx.sas.com)
dbitest pts/20 Mar 3 11:26 (login003.unx.sas.com)
deculp pts/22 Mar 3 12:21 (login017.unx.sas.com)
sssims pts/38 Mar 3 13:30 (login004.unx.sas.com)
osrmgr pts/41 Mar 3 13:37 (login012)
sasghk pts/7 Feb 25 10:22 (bat.unx.sas.com)
sssims pts/2 Mar 3 14:33 (login020.unx.sas.com)
disque pts/42 Mar 3 13:47 (login022.unx.sas.com)

Depending on the flavor of UNIX you are using, you can enter the whoami or who am i com-
mand to tell you the current userid (UID) you are using (This can be especially helpful if you have
access to privileged accounts and need to make sure you are running as the proper userid before start-
ing a server process).

login012> whoami Enter


sssims
32 UNIX Fundamentals Workshop
______________________________________________________________________________
All UNIX systems have an internal clock that you can access via the date command:

login012> date Enter


Tue Mar 8 09:38:06 EST 2005

Print your current working directory with the pwd command:

login012> pwd Enter


/users/sssims

Print the name of the current machine on which you are logged in (useful when the machine name is
not listed as part of your command prompt):

login012> hostname Enter


login012
UNIX Fundamentals Workshop 33
______________________________________________________________________________

Files:

There are many ways you can create a file in UNIX. Let‘s create a simple file using the echo com-
mand. The cd without any arguments will make sure you are in your userid‘s home directory when
you begin this exercise:

login012> cd Enter
login012> echo ―this is my first file‖ > first_file Enter

The echo command is typically used to ―echo‖, or display, something to the screen. We have used
the ―>‖ symbol to redirect the output of the echo command to a file (don‘t worry about the redirec-
tion symbol right now…we‘ll get to that later). For now, it is just important that you realize you
have created a file.

Display a list of all filenames in current directory using ls (list):

login012> ls Enter
first_file

Create a backup copy of your file with the cp (copy) command, then use ls to list the contents of the
current directory:

login012> cp first_file first_file.bak Enter

login012> ls Enter
first_file
first_file.bak
34 UNIX Fundamentals Workshop
______________________________________________________________________________

Now, what if you decide you want to change the name of your backup filenames from *.bak to *.orig.
You can easily accomplish this with the mv (move) command:

login012> mv first_file.bak first_file.orig Enter

login012> ls Enter
first_file
first_file.orig

You can remove your backup file with the rm command:

login012> rm first_file.orig Enter

login012> ls Enter
first_file

(rm behaves a little differently when removing a directory. We will get into that a little later).
UNIX Fundamentals Workshop 35
______________________________________________________________________________

Directories:

Create a directory with the mkdir command:

login012> mkdir tempdir Enter

By now, you have probably noticed that UNIX systems don‘t really tell you much when things work.
For example, when you issue the above mkdir command, nothing is displayed on your terminal to
offer reassurance that it actually worked properly and the directory was indeed created. You know it
was successful simply because your prompt returns and no error was generated. UNIX will always
tell you when something is wrong, but rarely when something is right. Remember, UNIX was
created by programmers for programmers, so there is not a lot of superfluous information provided.
Chalk it up to just being the way it is for now. This apparent lack of information will come in handy
later when we cover filtering and redirection. For now, you can use the ls –F command to check that
the command worked and your directory was created:

login012> ls –F Enter
first_file
tempdir/
.
.

The –F option on the ls command will add a trailing slash ―/‖ to any entry that is a directory. As
you can see in the above output, first_file is a regular file and tempdir is a directory.

Move first_file into your newly created tempdir directory:

login012> mv first_file tempdir Enter

Change into your tempdir directory with the cd command and list the contents with ls:

login012> cd tempdir Enter

login012> ls Enter
first_file
36 UNIX Fundamentals Workshop
______________________________________________________________________________

Scripts:

Let‘s create a very simple script in your tempdir directory using the echo command:

login012> echo who > test.sh Enter

This has created a file named test.sh with the contents being the who command.

Run your test.sh file with the following command. You should see output similar to the follow-
ing:

login012> sh test.sh Enter


pendergr pts/16 Mar 8 09:34 (login024.unx.sas.com)
edconn pts/1 Mar 4 11:51 (d8552.us.sas.com)
noe pts/21 Mar 3 12:08 (D8710.na.sas.com)
rgh pts/22 Mar 3 16:44 (pseudo.pc.sas.com)
sherman pts/33 Feb 22 16:45 (kerouac.unx.sas.com)
osrmgr pts/27 Mar 3 10:38 (login009.unx.sas.com)
UNIX Fundamentals Workshop 37
______________________________________________________________________________

Cleanup:

Now, let‘s cleanup the files and directories we have created. First, you will need to remove the files
in your tempdir directory. While in that directory, execute the following commands:

login012> rm first_file Enter

login012> rm test.sh Enter

Now, use the cd command to change to the parent directory (the ―..‖ moves you up one level in the
directory structure):

login012> cd .. Enter

Remove the tempdir directory with the rmdir command:

login012> rmdir tempdir Enter

You may wonder why we didn‘t just remove the directory first, since certainly that would have re-
moved the contents of the directory as well. Well, rmdir is a funny command in that it requires a
directory to be empty before it can be removed. Of course, as with all things UNIX, there is a way
around this; you can use the rm command with the –rf options. We‘ll cover that in more depth lat-
er.

You might also like