Академический Документы
Профессиональный Документы
Культура Документы
CONTENTS
I
Commands
1. date 8
2. who
10
3. cal
12
4. ls
14
5. ed
16
6. cat
18
7. touch
20
8. wc
22
9. more
24
10. echo
26
11. pr
28
12. bc
30
13. mkdir
32
14. rmdir
34
15. head
36
16. tail
38
17. ps
40
18. kill
42
3
19. cp
44
20. vi
46
21. pwd
48
22. sh
50
23. grep
52
24. cmp
54
25. diff
56
4
CONTENTS
Programs
INTRODUCTION OF UNIX
What is UNIX?
UNIX is an operating system which was first developed in the 1960s, and has
been under constant development ever since. By operating system, we
mean the suite of programs which make the computer work. It is a stable,
multi-user, multi-tasking system for servers, desktops and laptops. UNIX
systems also have a graphical user interface (GUI) similar to Microsoft
Windows which provides an easy to use environment. However, knowledge
of UNIX is required for operations which aren't covered by a graphical
program, or for when there is no windows interface available, for example, in
a telnet session.
Types of UNIX
There are many different versions of UNIX, although they share common
similarities. The most popular varieties of UNIX are Sun Solaris, GNU/Linux,
and MacOS X. We use Solaris on our servers and workstations, and Fedora
Linux on the servers and desktop PCs.
The UNIX operating system is made up of three parts; the kernel, the shell
and the programs.
The kernel of UNIX is the hub of the operating system. it allocates time and
memory to programs and handles the filestore and communications in
response to system calls.
The shell acts as an interface between the user and the kernel. When a user
logs in, the login program checks the username and password, and then
starts another program called the shell. The shell is a command line
interpreter (CLI). It interprets the commands the user types in and arranges
for them to be carried out.
Types of Shell
1. sh
The Bourne shell, or sh, was the default Unix shell of Unix Version 7,
and replaced theThompson shell, whose executable file had the
same name, sh. It remains a popular default shell for Unix accounts.
2. ash
The Almquist shell (also known as A Shell or ash) was originally
Kenneth Almquist’s clone of the SVR4-variant of the Bourne shell; it
is a fast, small, POSIX-compatible Unix shell designed to replace the
Bourne shell in later BSD distributions.
3. dash
Debian Almquist shell (dash) is a POSIX-compliant Unix shell, much
smaller than bash. It requires less disk space but is also less feature
rich. dash is a direct descendant of the NetBSD version of the
Almquist Shell.
4. bash
Bash is a Unix shell written for the GNU Project. The name of the
actual executable is bash. Its name is an acronym for Bourne-again
shell, a pun on the name of the Bourne shell. Bash is the default
shell on most Linux systems as well as on Mac OS X and it can be
run on most Unix-like operating systems.
5. fish
fish is a Unix shell. Its name is an acronym for friendly interactive
shell. fish focuses on interactive use, discoverability, and user
friendliness.
6. ksh
7
The Korn shell (ksh) is a Unix shell is backwards compatible with the
Bourne shell and includes many features of the C shell as well. The
main advantage of ksh over the traditional Unix shell is in its use as
a programming language.
7. csh
The C shell (csh) is a Unix shell is predecessor of the Bourne shell. Its
syntax is modeled after the C programming language.
8. tcsh
tcsh is a Unix shell based on and compatible with the C shell (csh). It
is essentially the C shell with (programmable) filename completion,
command-line editing, and a few other features.
9. es
The es shell is a command line interpreter that uses a scripting
language similar to the rc shell. It is intended to provide a fully
functional programming language as a Unix shell.
10. rc
rc is the command line interpreter for Version 10 Unix, Plan 9, and
Inferno operating systems. It resembles the Bourne shell, but its
syntax is somewhat simpler.
11. scsh
Scsh is a POSIX API layered on top of the Scheme programming
language (currently only a Scheme 48 implementation exists, but
others are planned) in a manner to make the most of scheme’s
capability for scripting. It is limited to 32-bit platforms.
12. sash
Stand-alone shell (sash) is a Unix shell designed for use in
recovering from certain types of system failures.
13. zsh
The Z shell (zsh) is a Unix shell that can be used as an interactive
login shell and as a powerful command interpreter for shell scripting.
Zsh can be thought of as an extended bourne shell with a large
number of improvements, including some of the most useful
features of bash, ksh, and tcsh.
-----------------
8
Command 1
‘date’ COMMAND
NAME : date - print or set the system date and time
DESCRIPTION
Display the current time in the given FORMAT, or set the system date.
FORMAT controls the output. The only valid option for the second form specifies Coordinated
Universal Time. Interpreted sequences are:
%C century; like %Y, except omit last two digits (e.g., 21)
Command 2
‘who’ COMMAND
NAME : who - show who is logged on
DESCRIPTION
Command 3
13
‘cal’ COMMAND
NAME : cal - displays a calendar
DESCRIPTION
Cal displays a simple calendar. If arguments are not specified, the current month is displayed. The
options are as follows:
-s : Display Sunday as the first day of the week. (This is the default.)
Command 4
‘ls’ COMMAND
NAME : ls - list directory contents
DESCRIPTION
OUTPUT: ed COMMAND
Command 5
17
‘ed’ COMMAND
NAME : ed, red - text editor
DESCRIPTION
‘ed’ is a line-oriented text editor. It is used to create, display, modify and otherwise manipulate text
files.
'red’ is a restricted ed. it can only edit files in the current directory and cannot execute shell
commands.
If invoked with a file argument, then a copy of file is read into the editorâs buffer. Changes are
made to this copy and not directly to file itself. Upon quitting ed, any changes not explicitly saved
with a âwâ command are lost.
OPTIONS
-G : Forces backwards compatibility.
-s : Suppresses diagnostics. This should be used if edâs standard input is from a script.
-p string : Specifies a command prompt. This may be toggled on and off with the âPâ
command.
18
Command 6
‘cat’ COMMAND
NAME : cat - concatenate files and print on the standard output
DESCRIPTION
-e : equivalent to -vE
-t : equivalent to -vT
-v, --show-nonprinting use ^ and M- notation, except for LFD and TAB
20
Command 7
21
‘touch’ COMMAND
DESCRIPTION
Update the access and modification times of each FILE to the current time. Mandatory arguments to
long options are mandatory for short options too.
OUTPUT: wc COMMAND
Command 8
23
‘wc’ COMMAND
DESCRIPTION
Print newline, word, and byte counts for each FILE, and a total line if more than one FILE is
specified.
Command 9
25
‘more’ COMMAND
DESCRIPTION
OPTIONS
-num : This option specifies an integer which is the screen size (in lines).
-l : more usually treats ^L (form feed) as a special character, and will pause after
any line that contains a form feed. The -l option will prevent this
behavior.
-p : Do not scroll. Instead, clear the whole screen and then display the text.
-c : Do not scroll. Instead, paint each screen from the top, clearing the remainder
of each line as it is displayed.
-u : Suppress underlining.
26
Command 10
27
‘echo’ COMMAND
DESCRIPTION
\\ : backslash
\a : alert (BEL)
\b : backspace
\f : form feed
\n : new line
\r : carriage return
\t : horizontal tab
\v : vertical tab
OUTPUT: pr COMMAND
28
Command 11
29
‘pr’ COMMAND
DESCRIPTION
-a, --across : print columns across rather than down, used together with -COLUMN
-c, --show-control-chars : use hat notation (^G) and octal backslash notation
-F, -f, --form-feed : use form feeds instead of newlines to separate pages.
-m, --merge : print all files in parallel, one in each column, truncate lines, but
join lines of full length with -J
OUTPUT: bc COMMAND
Command 12
‘bc’ COMMAND
31
DESCRIPTION
bc is a language that supports arbitrary precision numbers with interactive execution of statements.
There are some similarities in the syntax to the C programming language. A standard math library is
available by command line option. If requested, the math library is defined before processing any
files.
bc starts by processing code from all the files listed on the command line in the order listed. After
all files have been processed, bc reads from the standard input. All code is executed as it is read.
OPTIONS:
-h, --help : Print the usage and exit.
-v, --version : Print the version number and copyright and quit.
Command 13
‘mkdir’ COMMAND
33
DESCRIPTION
Command 14
‘rmdir’ COMMAND
35
DESCRIPTION
Command 15
‘head’ COMMAND
37
DESCRIPTION
Print the first 10 lines of each FILE to standard output. With more than one FILE, precede each with
a header giving the file name. With no FILE, or when FILE is -, read standard input.
Mandatory arguments to long options are mandatory for short options too.
-c, --bytes=[-]N : print the first N bytes of each file; with the leading â-â, print all but the
last N bytes of each file.
-n, --lines=[-]N : print the first N lines instead of the first 10; with the leading â-â, print
all but the last N lines of each file.
Command 16
‘tail’ COMMAND
39
DESCRIPTION
Print the last 10 lines of each FILE to standard output. With more than one FILE, precede each with
a header giving the file name.
With no FILE, or when FILE is -, read standard input.
Mandatory arguments to long options are mandatory for short options too.
--retry : keep trying to open a file even if it is inaccessible when tail starts or if
it becomes inaccessible later; useful when follow- ing by name.
OUTPUT: ps COMMAND
PID : Process Id
TTY : Terminal Type
Command 17
‘ps’ COMMAND
41
SYNOPSIS : ps [options]
DESCRIPTION
ps displays information about a selection of the active processes. If you want a repetitive update of
the selection and the displayed information, use top(1) instead.
Options of different types may be freely mixed, but conflicts can appear. There are some
synonymous options, which are functionally identical, due to the many standards and ps
implementations that this ps is compatible with.
EXAMPLES
To see every process on the system using standard syntax:
ps -e
ps -ef
ps -eF
ps -ely
EFFECT : Since we are supplied the process id of the bash process, as soon as we press enter the
bash process is killed and we are logged out.
Command 18
43
‘kill’ COMMAND
DESCRIPTION
The command kill sends the specified signal to the specified process or process group. If no signal
is specified, the TERM signal is sent. The TERM signal will kill processes which do not catch this
signal. For other processes, it may be necessary to use the KILL (9) signal, since this signal cannot
be caught.
OPTIONS
pid... Specify the list of processes that kill should signal. Each pid can be one of five things:
-s signal : Specify the signal to send. The signal may be given as a signal name or no.
-p : Specify that kill should only print the process id (pid) of the named
processes, and not send any signals.
44
OUTPUT: cp COMMAND
Command 19
‘cp’ COMMAND
45
DESCRIPTION
-f, --force : if existing destination file can’t be opened,remove it & try again
OUTPUT: vi COMMAND
Command 20
‘vi’ COMMAND
47
DESCRIPTION
Vim is a text editor that is upwards compatible to Vi. It can be used to edit all kinds of plain text.
It is especially useful for editing programs. There are a lot of enhancements above Vi: multi level
undo, multi windows and buffers, syntax highlighting, command line editing, filename
completion, on-line help, visual selection, etc.
While running Vim a lot of help can be obtained from the on-line help system, with the ":help"
command.
Most often Vim is started to edit a single file with the command vim file
More generally Vim is started with:
vim [options] [filelist]
STEPS in using vi :-
Command 21
‘pwd’ COMMAND
DESCRIPTION
OUTPUT: sh COMMAND
Command 22
‘sh’ COMMAND
51
DESCRIPTION
Bash is an sh-compatible command language interpreter that executes commands read from the
standard input or from a file. Bash also incorporates useful features from the Korn and C shells.
Bash is intended to be a conformant implementation of the IEEE POSIX Shell and Tools
specification (IEEE Working Group 1003.2). Bash can be configured to be POSIX-conformant by
default.
OPTIONS
In addition to the single-character shell options documented in the description of the set builtin
command, bash interprets the following options when it is invoked:
Command 23
‘grep’ COMMAND
53
DESCRIPTION
grep searches the named input FILEs (or standard input if no files are named, or the file name - is
given) for lines containing a match to the given PATTERN. By default, grep prints the matching
lines.
In addition, two variant programs egrep and fgrep are available. Egrep is the same as grep -E.
Fgrep is the same as grep -F.
OPTIONS
-a, --text : Process a binary file as if it were text; this is equivalent to the --binary-
files=text option.
-b, --byte-offset : Print the byte offset within the input file before each line of output.
-e PATTERN, --regexp=PATTERN
Use PATTERN as the pattern; useful to protect patterns beginning with -.
54
Command 24
‘cmp’ COMMAND
55
DESCRIPTION
The cmp utility compares two files of any type and writes the results to the standard output. By
default, cmp is silent if the files are the same; if they differ, the byte and line number at which the
first difference occurred is reported. Bytes and lines are numbered beginning with one.
The following options are available:
-l Print the byte number (decimal) and the differing byte values (octal) for each difference.
The optional arguments skip1 and skip2 are the byte offsets from the beginning of file1 and file2,
respectively, where the comparison will begin. The offset is decimal by default, but may be
expressed as an hexadecimal or octal value by preceding it with a leading ââ0xââ or ââ0ââ.
1 The files are different; this includes the case where one file is identical to the first part of the
other. In the latter case,
56
Command 25
‘diff’ COMMAND
57
DESCRIPTION
In the simplest case, diff compares the contents of the two files from-file and to-file. A file name
of - stands for text read from the standard input. As a special case, diff - - compares a copy of
standard input to itself.
If from-file is a directory and to-file is not, diff compares the file in from-file whose file name is
that of to-file, and vice versa. The non-directory file must not be -.
If both from-file and to-file are directories, diff compares corresponding files in both directories, in
alphabetical order; this comparison is not recursive unless the -r or --recursive option is given
-a : Treat all files as text and compare them line-by-line, even if they do not seem
to be text.
--brief : Report only whether the files differ, not the details of the differences.
OUTPUT – firstprogram
58
OUTPUT - demols
PROGRAM – 1
59
[sohit@localhost~]vi firstprogram
PROGRAM – 2
Write a UNIX program to show the files or directories in the current directory on the screen.
[sohit@localhost~]vi demols
ls
OUTPUT – demoinput
60
OUTPUT - demowho
PROGRAM – 3
61
Write a UNIX program to get a number as input from the user and print the same on the screen.
[sohit@localhost~]vi demoinput
PROGRAM – 4
Write a UNIX program to show all the users that have logged on.
[sohit@localhost~]vi demowho
who
OUTPUT – sum
62
OUTPUT - multiply
PROGRAM – 5
63
[sohit@localhost~]vi sum
c = ‘expr $a + $b’
PROGRAM – 6
[sohit@localhost~]vi multiply
c = ‘expr $a \* $b’
PROGRAM – 7
65
[sohit@localhost~]vi lab
a=0
sum=0
while [$n –gt 0]
do
a = ‘expr $n % 10’ OUTPUT – simpleinterest
b = ‘expr $n / 10’
sum = ‘expr $sum +$a’
done
echo “Sum of the digits of this Number is $sum”
PROGRAM – 8
[sohit@localhost~]vi lab1
x=0
while [$a –ne 0]
do
b = ‘expr $a % 10’
x = ‘expr $x + $b’ OUTPUT – simpleinterest
x = ‘expr $x \* 10’
a = ‘expr $a / 10’
done
x = ‘expr $x / 10’
echo “$x”
OUTPUT - odd
PROGRAM – 9
67
[sohit@localhost~]vi lab2
c = ‘expr $p \* $r \* $t/100’
PROGRAM – 10
[sohit@localhost~]vi odd
b = ‘expr $a%2’
if[$b –eq 0]
then
echo “Even number”
else
echo “Odd number”
fi
OUTPUT – while
68
OUTPUT – switch
PROGRAM – 11
69
[sohit@localhost~]vi while
PROGRAM – 12
[sohit@localhost~]vi switch
OUTPUT – circle
70
OUTPUT – leap
PROGRAM – 13
71
Write a UNIX program to calculate the area and circumference of a given circle.
[sohit@localhost~]vi circle
PROGRAM – 14
[sohit@localhost~]vi leap
OUTPUT – fact
72
OUTPUT – fibo
PROGRAM – 15
73
[sohit@localhost~]vi fact
PROGRAM – 16
[sohit@localhost~]vi fibo
while [ $i -lt $n ]
do
i=` expr $i + 1`
done
OUTPUT – smallest
74
PROGRAM – 17
75
[sohit@localhost~]vi smallest
if [ $a -gt $b ]
then
if [ $b -gt $c ]
then echo "c is smallest"
else
echo "b is smallest"
fi
else
if [ $a -gt $c ]
then echo "c is smallest"
else
echo "a is smallest"
fi
fi
OUTPUT – largest
76
OUTPUT – pattern
PROGRAM – 18
77
[sohit@localhost~]vi largest
if [ $a -gt $b -a $a -gt $c ]
then
echo "a is largest"
elif [ $b -gt $a -a $b -gt $c ]
then
echo "b is largest"
else
echo "c is largest"
fi
PROGRAM – 19
[sohit@localhost~]vi pattern