OSV Practical GTU Sem 4
OSV Practical GTU Sem 4
OSV Practical GTU Sem 4
Enrollment No : 190410116100
Division : SY IT 3
Batch : A
2
Enrollment No : 190410116100 SY IT 3 A
CERTIFICATE
2
Enrollment No : 190410116100 SY IT 3 A
INDEX
No. Subject Page no.
1. Study of basic commands of LINUX / UNIX. 4
2. Study of advanced commands and filters of LINUX / 4
UNIX. ( 1 to 50 commands {basic & advance} )
3. (a) Write a shell script to generate marksheet of a 78
student. Take 3 subjects, calculate and display total
marks, percentage and class obtained by the
students.
(b) Write a shell script to find maximum of two numbers. 79
(c) Write a shell script to find maximum of three 80
numbers.
4. (a) Write a shell script to find factorial of given number 82
n.
(b) Write a shell script to display multiplication table of 83
given number.
(c) Write a shell script to find given number is odd or 84
even.
5. Write a shell script which will accept a number b and 85
display first n prime number as output.
6. Write a shell script which will generate first n 87
Fibonacci numbers like : 1, 1, 2, 3, 5,…
7. Write a menu driven shell script which will print the 88
following menu and execute the given task :
(a) Display calendar of current month. 88
(b) Display today’s date and time. 88
(c) Display usernames those are currently logged in the 88
system.
(d) Display your name at given x, y position. 88
(e) Display your terminal number. 88
8. Write shell script to check entered string is 90
palindrome or not.
9. Write a shell script to read n numbers as command 92
line arguments and sort them in descending order.
10. Write a shell script to display all executable files, 94
directories and zero sized files from current directory.
2
Enrollment No : 190410116100 SY IT 3 A
Commands :
1)cal :
Display a calendar.
SYNTAX :
DESCRIPTION :
2
Enrollment No : 190410116100 SY IT 3 A
OPTIONS DESCRIPTION
-1 --one Display single month output. (This is the
default.)
-3 --three Display three months spanning the date
-n --months Display number of months, starting from the
[=NUMBER] month containing the date.
-S --span Display months spanning the date.
EXAMPLE :
2
Enrollment No : 190410116100 SY IT 3 A
2) pwd :
Print name of current / working directory
SYNTAX :
pwd [option]….
DESCRIPTION :
OPTIONS DESCRIPTION
-L --logical use PWD from environment, even if it contains
symlinks
-P --physical avoid all symlinks
EXAMPLE :
3) ls :
2
Enrollment No : 190410116100 SY IT 3 A
SYNTAX :
ls [option]... [file]...
DESCRIPTION :
OPTIONS DESCRIPTION
-a --all do not ignore entries starting with .
-A -almost-all do not list implied . and ..
--author with -l, print the author of each file
-b --escape print C-style escapes for nongraphic
characters
--block-size [=SIZE] scale sizes by SIZE before printing them;
e.g., '--block-size=M' prints sizes in units of
1,048,576 bytes; see SIZE format below
-B --ignore-backups do not list implied entries ending with ~
-c with -lt: sort by, and show, ctime (time of
last modification of file status information);
with -l: show ctime and sort by name;
otherwise: sort by ctime, newest first
-C list entries by columns
--color [=WHEN] colorize the output; WHEN can be 'always'
(default if omitted), 'auto', or 'never'; more
info below
-d --directory list directories themselves, not their
contents
-D --dired generate output designed for Emacs' dired
mode
-f do not sort, enable -aU, disable -ls --color
-F --classify append indicator (one of */=>@|) to entries
--file-type likewise, except do not append '*'
2
Enrollment No : 190410116100 SY IT 3 A
2
Enrollment No : 190410116100 SY IT 3 A
2
Enrollment No : 190410116100 SY IT 3 A
EXAMPLE :
4)clear :
Clear the terminal screen
SYNTAX :
clear [-Ttype] [-V] [-x]
DESCRIPTION :
clear clears your screen if this is possible, including its scrollback
buffer (if the extended “E3” capability is defined). clear looks in the
environment for the terminal type given by the environment variable
TERM, and then in the terminfo database to determine how to clear
the screen.
2
Enrollment No : 190410116100 SY IT 3 A
clear writes to the standard output. You can redirect the standard
output to a file (which prevents clear from actually clearing the
screen), and later cat the file to the screen, clearing it at that point.
OPTIONS DESCRIPTION
-T [=TYPE] indicates the type of terminal. Normally this option is
unnecessary, because the default is taken from the
environment variable TERM. If -T is specified, then the shell
variables LINES and COLUMNS will also be ignored.
-V reports the version of ncurses which was used in this
program, and exits. The options are as follows:
EXAMPLE :
2
Enrollment No : 190410116100 SY IT 3 A
5) exit :
Exit the shell
SYNTAX :
exit [n]
DESCRIPTION :
Exits the shell with a status of N. If N is omitted, the exit status is that
of the last command executed.
EXAMPLE :
6) cd :
Change the shell working directory.
SYNTAX :
cd [-L | [ -P [-e]] [-@]] [dir]
DESCRIPTION :
Change the current directory to DIR. The default DIR is the value of
the HOME shell variable.
The variable CDPATH defines the search path for the directory
containing DIR. Alternative directory names in CDPATH are
separated by a colon (:). A null directory name is the same as the
current directory. If DIR begins with a slash (/), then CDPATH is not
used.
2
Enrollment No : 190410116100 SY IT 3 A
If the directory is not found, and the shell option `cdable_vars' is set
the word is assumed to be a variable name. If that variable has a
value, its value is used for DIR.
OPTIONS DESCRIPTION
-L force symbolic links to be followed: resolve symbolic
links in DIR after processing instances of ‘..’
-P use the physical directory structure without following
symbolic links: resolve symbolic links in DIR before
processing instances of ‘..’
-e if the -P option is supplied, and the current working
directory cannot be determined successfully, exit
with a non-zero status
-@ on systems that support it, present a file with
extended attributes as a directory containing the file
attributes
EXAMPLE :
7) man :
2
Enrollment No : 190410116100 SY IT 3 A
SYNTAX :
man [-C file] [-d] [-D] [--warnings[=warnings]] [-R encoding] [-L
locale] [m system[,...]] [-M path] [-S list] [-e extension] [-i|-I] [--regex|--
wildcard] [--names-only] [-a] [-u] [--no-subpages] [-P pager] [-r
prompt] [-7] [-E encoding] [--no-hyphenation] [--no-justification] [-p
string] [-t] [-T[device]] [-H[browser]] [-X[dpi]] [-Z] [[section]
page[.section] ...] ...
man -k [apropos options] regexp ...
man -K [-w|-W] [-S list] [-i|-I] [--regex] [section] term ...
man -f [whatis options] page ...
man -l [-C file] [-d] [-D] [--warnings[=warnings]] [-R encoding] [-L
locale] [-P pager] [-r prompt] [-7] [-E encoding] [-p string] [-t] [-
T[device]] [-H[browser]] [-X[dpi]] [-Z] file ...
man -w|-W [-C file] [-d] [-D] page ...
man -c [-C file] [-d] [-D] page ...
man [-?V]
DESCRIPTION :
man is the system's manual pager. Each page argument given to
man is normally the name of a program, utility or function. The
manual page associated with each of these arguments is then
found and displayed. A section, if provided, will direct man to look
only in that section of the manual. The default action is to search in all
of the available sections following a pre-defined order ("1 1p 8 2 3 3p
4 5 6 7 9 0p n" by default, unless overridden by the SECTION
directive in / etc / man_db.conf), and to show only the first page
found, even if page exists in several sections.
The table below shows the section numbers of the manual followed
by the types of pages they contain.
2
Enrollment No : 190410116100 SY IT 3 A
OPTIONS DESCRIPTION
-C --config-file [=FILE] use this user configuration file
-d --debug emit debugging messages
-D --default reset all options to their default values
--warnings enable warnings from groff
[=WARNING]
-f --whatis equivalent to whatis
-k --apropos equivalent to apropos
-K --global-apropos search for text in all pages
-l --local-file interpret PAGE argument(s) as local
filename(s)
-w --where, --path, print physical location of man page(s)
--location
-W --where-cat, print physical location of cat file(s)
--location-cat
-c --catman used by catman to reformat out of date cat
2
Enrollment No : 190410116100 SY IT 3 A
pages
-R --recode [=ENCODING] output source page encoded in ENCODING
-L --locale [=LOCALE] define the locale for this particular man
search
-m --systems [=SYSTEM] use manual pages from other systems
-M --manpath [=PATH] set search path for manual pages to PATH
-S, -s --section [=LIST] use colon separated section list
-e --extension limit search to extension type EXTENSION
[=EXTENSION]
-i --ignore-case look for pages case-insensitively (default)
-I --match-case look for pages case-sensitively
--regex show all pages matching regex
--wildcard show all pages matching wildcard
--names-only make --regex and --wildcard match page
names only, not descriptions
-a --all find all matching manual pages
-u --update force a cache consistency check
--no-subpages don't try subpages, e.g. 'man foo bar' =>
'man foo-bar'
-P --pager [=PAGER] use program PAGER to display output
-r --prompt [=STRING] provide the `less' pager with a prompt
-7 --ascii display ASCII translation of certain latin1
chars
-E --encoding use selected output encoding
[=ENCODING]
-p --preprocessor STRING indicates which preprocessors to
[=STRING] run:
e - [n]eqn, p - pic, t - tbl, g - grap, r - refer, v
- vgrind
-t --troff use groff to format pages
-T --troff-device use groff with selected device
[=DEVICE]
-H --html [=BROWSER] use lynx or BROWSER to display HTML
output
-X --gxditview use groff and display through gxditview
[=RESOLUTION] (X11) : -X = -TX75, -X100 = -TX100,
-X100-12 = -TX100-12
2
Enrollment No : 190410116100 SY IT 3 A
EXAMPLE :
8)whoami :
SYNTAX :
whoami [OPTION]….
DESCRIPTION :
Print the user name associated with the current effective user ID.
Same as id -un.
EXAMPLE :
9) echo :
Display a line of text
2
Enrollment No : 190410116100 SY IT 3 A
SYNTAX :
DESCRIPTION :
OPTION DESCRIPTION
-n do not output the trailing newline
-e enable interpretation of backslash escapes
-E disable interpretation of backslash escapes (default)
EXAMPLE :
10) who :
Show who is logged in
2
Enrollment No : 190410116100 SY IT 3 A
SYNTAX :
who [OPTION]… [FILE | ARG1 ARG2]
DESCRIPTION :
Print information about users who are currently logged in.
OPTIONS DESCRIPTION
-a --all same as -b -d --login -p -r -t -T -u
-b --boot time of last system boot
-d --dead print dead processes
-H --heading print line of column headings
-l --login print system login processes
--lookup attempt to canonicalize hostnames via DNS
EXAMPLE :
2
Enrollment No : 190410116100 SY IT 3 A
11) mkdir :
Make directories
SYNTAX :
DESCRIPTION :
OPTIONS DESCRIPTION
-m --mode [=MODE] set file mode (as in chmod), not a=rwx -
umask
-p --parents no error if existing, make parent directories
as needed
-v --verbose print a message for each created directory
2
Enrollment No : 190410116100 SY IT 3 A
EXAMPLE :
12) rmdir :
Remove empty directories
SYNTAX :
rmdir [OPTION]… DIRECTORY…
DESCRIPTION :
OPTIONS DESCRIPTION
--ignore-fail-on-non- ignore each failure that is solely because a
directory is non-empty
empty
-p --parents remove DIRECTORY and its ancestors; e.g.,
'rmdir -p a/b/c' is similar to 'rmdir a/b/c a/b a'
-v --verbose output a diagnostic for every directory
processed
EXAMPLE :
2
Enrollment No : 190410116100 SY IT 3 A
13) uname :
Print system information
SYNTAX :
uname [OPTION]…
DESCRIPTION :
Print certain system information. With no OPTION, same as -s.
OPTIONS DESCRIPTION
-a --all print all information, in the following order,
except omit -p and -i if unknown:
-s --kernel-name print the kernel name
-n --nodename print the network node hostname
-r --kernel-release print the kernel release
-v --version-release print the kernel version
-m --machine print the machine hardware name
-p --processer print the processor type (non-portable)
-i --hardware-platform print the hardware platform (non-portable)
-o --operating-system print the operating system
EXAMPLE :
2
Enrollment No : 190410116100 SY IT 3 A
14) tty :
Print the file name of the terminal connected to standard input
SYNTAX :
tty [OPTION]…
DESCRIPTION :
OPTION DESCRIPTION
-s --silent, --quiet print nothing, only return an exit status
EXAMPLE :
15) stty :
2
Enrollment No : 190410116100 SY IT 3 A
SYNTAX :
stty [-F DEVICE | --file=DEVICE] [SETTING]...
stty [-F DEVICE | --file=DEVICE] [-a | --all]
stty [-F DEVICE | --file=DEVICE] [-g | --save]
DESCRIPTION :
OPTIONS DESCRIPTION
-a --all print all current settings in human-readable form
-F --file [=DEVICE] open and use the specified DEVICE instead of stdin
EXAMPLE :
16) cat :
Concatenate files and print on the standard output
2
Enrollment No : 190410116100 SY IT 3 A
SYNTAX :
cat [OPTION]… [FILE]…
DESCRIPTION :
Concatenate FILE(s) to standard output.
With no FILE, or when FILE is -, read standard input.
OPTIONS DESCRIPTION
-A --show-all equivalent to -vET
-b --number- number nonempty output lines, overrides -n
nonblank
-e equivalent to -vE
-E --show-ends display $ at end of each line
-n --number number all output lines
-s --squeeze-blank suppress repeated empty output lines
-t equivalent to -vT
-T --show-tabs display TAB characters as ^I
-v --show-nonprinting use ^ and M- notation, except for LFD and TAB
EXAMPLE :
17) cp :
2
Enrollment No : 190410116100 SY IT 3 A
SYNTAX :
DESCRIPTION :
OPTIONS DESCRIPTION
-a --archive same as -dR --preserve=all
--attributes-only don't copy the file data, just the attributes
--backup [=CONTROL] make a backup of each existing
destination file
-b like --backup but does not accept an
argument
--copy-contents copy contents of special files when
recursive
-d same as --no-dereference
--preserve=links
-f --force if an existing destination file cannot be
opened, remove it and try again (this
option is ignored when the -n option is
also used)
-i --interactive prompt before overwrite (overrides a
previous -n option)
-H follow command-line symbolic links in
SOURCE
-l --link hard link files instead of copying
-L --deference always follow symbolic links in SOURCE
-n --no-clobber do not overwrite an existing file (overrides
a previous -i option)
-P --no-deference never follow symbolic links in SOURCE
2
Enrollment No : 190410116100 SY IT 3 A
2
Enrollment No : 190410116100 SY IT 3 A
EXAMPLE :
18) rm :
Remove files or directories
SYNTAX :
rm [OPTION]… [FILE]…
DESCRIPTION :
OPTIONS DESCRIPTION
-f --force ignore nonexistent files and arguments, never
prompt
2
Enrollment No : 190410116100 SY IT 3 A
EXAMPLE :
19) mv :
Move (rename) files
SYNTAX :
2
Enrollment No : 190410116100 SY IT 3 A
DESCRIPTION :
Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.
Mandatory arguments to long options are mandatory for short options
too.
OPTIONS DESCRIPTION
--backup [=CONTROL] make a backup of each existing
destination file
-b like --backup but does not accept an
argument
-f --force do not prompt before overwriting
-i --interactive prompt before overwrite
-n --no-clobber do not overwrite an existing file
EXAMPLE :
2
Enrollment No : 190410116100 SY IT 3 A
20) nl :
Number lines of files
SYNTAX :
nl [OPTION]… [FILE]…
DESCRIPTION :
Write each FILE to standard output, with line numbers added.
With no FILE, or when FILE is -, read standard input.
Mandatory arguments to long options are mandatory for short options
too.
OPTIONS DESCRIPTION
-b --body-numbering use STYLE for numbering body lines
[=STYLE]
-d --section-delimiter use CC for logical page delimiters
[=CC]
-f --footer-numbering use STYLE for numbering footer lines
[=STYLE]
-h --header-numbering use STYLE for numbering header lines
[=STYLE]
-i --line-increment line number increment at each line
[=NUMBER]
-l --join-blank-lines group of NUMBER empty lines counted as
[=NUMBER] one
-n --number-format insert line numbers according to FORMAT
[=FORMAT]
2
Enrollment No : 190410116100 SY IT 3 A
EXAMPLE :
21) cut :
Remove sections from each line of files
SYNTAX :
cut OPTION… [FILE]…
DESCRIPTION :
Print selected parts of lines from each FILE to standard output.
With no FILE, or when FILE is -, read standard input.
Mandatory arguments to long options are mandatory for short options
too.
OPTIONS DESCRIPTION
-b --bytes [=LIST] select only these bytes
-c --characters [=LIST] select only these characters
2
Enrollment No : 190410116100 SY IT 3 A
EXAMPLE :
22) paste :
Merge lines of files.
SYNTAX :
2
Enrollment No : 190410116100 SY IT 3 A
DESCRIPTION :
EXAMPLE :
23) more :
File perusal filter for crt viewing
SYNTAX :
file [=OPTIONS] FILE….
2
Enrollment No : 190410116100 SY IT 3 A
DESCRIPTION :
more is a filter for paging through text one screenful at a time. This
version is especially primitive. Users should realize that less(1)
provides more(1) emulation plus extensive enhancements.
OPTIONS DESCRIPTION
-d Prompt with "[Press space to continue, 'q' to quit.]",
and display "[Press 'h' for instructions.]" instead of
ringing the bell when an illegal key is pressed.
-l Do not pause after any line containing a ^L (form
feed).
-f Count logical lines, rather than screen lines (i.e., long
lines are not folded).
-p Do not scroll. Instead, clear the whole screen and
then display the text. Notice that this option is
switched on automatically if the executable is named
page.
-c Do not scroll. Instead, paint each screen from the top,
clearing the remainder of each line as it is displayed.
-s Squeeze multiple blank lines into one.
-u Suppress underlining.
-number The screen size to use, in number of lines.
+number Start displaying each file at line number.
+/string The string to be searched in each file before starting to
display it.
EXAMPLE :
2
Enrollment No : 190410116100 SY IT 3 A
24) cmp :
Compare two files byte by byte.
SYNTAX :
cmp [OPTION]... FILE1 [FILE2 [SKIP1 [SKIP2]]]
DESCRIPTION :
Compare two files byte by byte.
The optional SKIP1 and SKIP2 specify the number of bytes to skip at
the beginning of each file (zero by default).
Mandatory arguments to long options are mandatory for short options
too.
OPTIONS DESCRIPTION
-b --print-byte print differing bytes
-i --ignore-initial [=SKIP] skip first SKIP bytes of both inputs
-i --ignore-initial skip first SKIP1 bytes of FILE1 and first
[=SKIP1:SKIP2] SKIP2 bytes of FILE2
-l --verbose output byte numbers and differing byte
values
2
Enrollment No : 190410116100 SY IT 3 A
EXAMPLE :
25) comm :
Compare two sorted files line by line
SYNTAX :
comm [OPTION]... FILE1 FILE2
DESCRIPTION :
Compare sorted files FILE1 and FILE2 line by line.
When FILE1 or FILE2 (not both) is -, read standard input.
With no options, produce three-column output. Column one contains
lines unique to FILE1, column two contains lines unique to FILE2, and
column three contains lines common to both files.
OPTIONS DESCRIPTION
-1 suppress column 1 (lines unique to FILE1)
-2 suppress column 2 (lines unique to FILE2)
-3 suppress column 3 (lines that appear in
both files)
--check-order check that the input is correctly sorted, even
if all input lines are pairable
2
Enrollment No : 190410116100 SY IT 3 A
EXAMPLE :
26) diff :
Compare files line by line
SYNTAX :
diff [OPTION]... FILES
DESCRIPTION :
Compare FILES line by line.
Mandatory arguments to long options are mandatory for short options
too.
OPTIONS DESCRIPTION
--normal output a normal diff (the default)
-q --brief report only when files differ
-s --report-identical-file report when two files are the same
-c, -C --context [=NUM] output NUM (default 3) lines of copied
context
-u, -U --unified [=NUM] output NUM (default 3) lines of unified
context
2
Enrollment No : 190410116100 SY IT 3 A
2
Enrollment No : 190410116100 SY IT 3 A
EXAMPLE :
2
Enrollment No : 190410116100 SY IT 3 A
27) chmod :
Change file mode bits.
SYNTAX :
chmod [OPTION]... MODE[MODE]... FILE...
chmod [OPTION]... OCTAL-MODE FILE...
chmod [OPTION]... --reference=RFILE FILE...
DESCRIPTION :
This manual page documents the GNU version of chmod. chmod
changes the file mode bits of each given file according to mode,
which can be either a symbolic representation of changes to make, or
an octal number representing the bit pattern for the new mode bits.
The format of a symbolic mode is [ugoa...][[-+=][perms...]...], where
perms is either zero or more letters from the set rwxXst, or a single
letter from the set ugo. Multiple symbolic modes can be given,
separated by commas.
A combination of the letters ugoa controls which users' access to the
file will be changed: the user who owns it (u), other users in the file's
group (g), other users not in the file's group (o), or all users (a). If
none of these are given, the effect is as if (a) were given, but bits that
are set in the umask are not affected.
The letters rwxXst select file mode bits for the affected users: read
(r), write (w), execute (or search for directories) (x), execute/search
only if the file is a directory or already has execute permission for
some user (X), set user or group ID on execution (s), restricted
deletion flag or sticky bit (t). Instead of one or more of these letters,
you can specify exactly one of the letters ugo: the permissions
granted to the user who owns the file (u), the permissions granted to
other users who are members of the file's group (g), and the
permissions granted to users that are in neither of the two preceding
categories (o).
2
Enrollment No : 190410116100 SY IT 3 A
OPTIONS DESCRIPTION
-c --changes like verbose but report only when a
change is made
-f --silent, --quiet suppress most error messages
-v --verbose output a diagnostic for every file
processed
--no-preserve-root do not treat '/' specially (the default)
--preserve-root fail to operate recursively on '/'
--reference [=REFILE] use RFILE's mode instead of MODE
values
-R --recursive change files and directories recursively
EXAMPLE :
2
Enrollment No : 190410116100 SY IT 3 A
28) chown :
Change file owner and group.
SYNTAX :
chown [OPTION]... [OWNER][:[GROUP]] FILE...
chown [OPTION]... --reference=RFILE FILE...
DESCRIPTION :
2
Enrollment No : 190410116100 SY IT 3 A
OPTIONS DESCRIPTION
-c --changes like verbose but report only when a change is
made
-f --silent, --quiet suppress most error messages
-v --verbose output a diagnostic for every file processed
--deference affect the referent of each symbolic link (this is
the default), rather than the symbolic link itself
-h --no-deference affect symbolic links instead of any referenced
file (useful only on systems that can change
the ownership of a symlink)
--from change the owner and/or group of each file
[=CURRENT_OWNER : only if its current owner and/or group match
those specified here. Either may be omitted, in
CURRENT_GROUP]
which case a match is not required for the
omitted attribute
--no-preserve-root do not treat '/' specially (the default)
--preserve-root fail to operate recursively on '/'
--reference [=RFILE] use RFILE's owner and group rather than
specifying OWNER : GROUP values
-R --recursive operate on files and directories recursively
-H if a command line argument is a symbolic link
to a directory, traverse it
-L traverse every symbolic link to a directory
encountered
-P do not traverse any symbolic links (default)
29) chgrp :
Change group ownership.
SYNTAX :
DESCRIPTION :
2
Enrollment No : 190410116100 SY IT 3 A
OPTIONS DESCRIPTION
-c --changes like verbose but report only when a change is
made
-f --silent, --quiet suppress most error messages
-v --verbose output a diagnostic for every file processed
--deference affect the referent of each symbolic link (this is
the default), rather than the symbolic link itself
-h --no-deference affect symbolic links instead of any referenced
file (useful only on systems that can change
the ownership of a symlink)
--no-preserve-root do not treat '/' specially (the default)
--preserve-root fail to operate recursively on '/'
--reference [=RFILE] use RFILE's group rather than specifying a
GROUP values
-R --recursive operate on files and directories recursively
-H if a command line argument is a symbolic link
to a directory, traverse it
-L traverse every symbolic link to a directory
encountered
-P do not traverse any symbolic links (default)
30) date :
Print or set the system date and time
SYNTAX :
date [OPTION]... [+FORMAT]
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
DESCRIPTION :
Display the current time in the given FORMAT or set the system date.
Mandatory arguments to long options are mandatory for short options
too.
OPTIONS DESCRIPTION
2
Enrollment No : 190410116100 SY IT 3 A
EXAMPLE :
31) passwd :
Compute password hashes
SYNTAX :
2
Enrollment No : 190410116100 SY IT 3 A
openssl passwd [-help] [-crypt] [-1] [-apr1] [-aixmd5] [-5] [-6] [-salt
string] [-in file] [-stdin] [-noverify] [-quiet] [-table] [-rand file...] [-
writerand file] {password}
DESCRIPTION :
The passwd command computes the hash of a password typed at
run-time or the hash of each password in a list. The password list is
taken from the named file for option -in file, from stdin for option -
stdin, or from the command line, or from the terminal otherwise. The
Unix standard algorithm crypt and the MD5-based BSD password
algorithm 1, its Apache variant apr1, and its AIX variant are available.
OPTIONS DESCRIPTION
-help Print out a usage message.
-crypt Use the crypt algorithm (default).
-1 Use the MD5 based BSD password algorithm 1.
-apr1 Use the apr1 algorithm (Apache variant of the BSD
algorithm).
-aixmd5 Use the AIX MD5 algorithm (AIX variant of the BSD
algorithm).
-5, -6 Use the SHA256 / SHA512 based algorithms defined by
Ulrich Drepper.
-salt [=STRING] Use the specified salt. When reading a password from the
terminal, this implies -noverify.
-in [=FILE] Read passwords from file.
-stdin Read passwords from stdin.
-noverify Don't verify when reading a password from the terminal.
-quiet Don't output warnings when passwords given at the
command line are truncated.
-table In the output list, prepend the cleartext password and a TAB
character to each password hash.
-rand file… A file or files containing random data used to seed the
random number generator. Multiple files can be specified
separated by an OS-dependent character. The separator is ;
for MS-Windows, for OpenVMS, and : for all others.
[-writerand file] Writes random data to the specified file upon exit. This can
be used with a subsequent -rand flag.
EXAMPLE :
2
Enrollment No : 190410116100 SY IT 3 A
32) file :
Determine file type
SYNTAX :
file [-bcdEhiklLNnprsSvzZ0] [--apple] [--exclude-quiet] [--
extension] [--mime-encoding] [--mime-type] [-e testname] [-F
separator] [-f namefile] [-m magicfiles] [-P name=value] file ...
file -C [-m magicfiles]
file [--help]
DESCRIPTION :
This manual page documents version 5.39 of the file command.
file tests each argument in an attempt to classify it. There are three
sets of tests, performed in this order: filesystem tests, magic tests,
and language tests. The first test that succeeds causes the file type to
be printed.
The type printed will usually contain one of the words text (the file
contains only printing characters and a few common control
characters and is probably safe to read on an ASCII terminal),
executable (the file contains the result of compiling a program in a
form understandable to some UNIX kernel or another), or data
meaning anything else (data is usually “binary” or non-printable).
Exceptions are well-known file formats (core files, tar archives) that
are known to contain binary data. When modifying magic files or the
program itself, make sure to preserve these keywords. Users depend
on knowing that all the readable files in a directory have the word
“text” printed. Don't do as Berkeley did and change “shell commands
text” to “shell script”.
2
Enrollment No : 190410116100 SY IT 3 A
The filesystem tests are based on examining the return from a stat(2)
system call. The program checks to see if the file is empty, or if it's
some sort of special file. Any known file types appropriate to the
system you are running on (sockets, symbolic links, or named pipes
(FIFOs) on those systems that implement them) are intuited if they
are defined in the system header file <sys/stat.h>.
The magic tests are used to check for files with data in particular fixed
formats. The canonical example of this is a binary executable
(compiled program) a.out file, whose format is defined in <elf.h>,
<a.out.h> and possibly <exec.h> in the standard include directory.
These files have a “magic number” stored in a particular place near
the beginning of the file that tells the UNIX operating system that the
file is a binary executable, and which of several types thereof. The
concept of a “magic” has been applied by extension to data files. Any
file with some invariant identifier at a small fixed offset into the file can
usually be described in this way. The information identifying these
files is read from the compiled magic file /usr/share/misc/magic.mgc,
or the files in the directory /usr/share/misc/magic if the compiled file
does not exist. In addition, if $HOME/.magic.mgc or $HOME/.magic
exists, it will be used in preference to the system magic files.
If a file does not match any of the entries in the magic file, it is
examined to see if it seems to be a text file. ASCII, ISO-8859-x, non-
ISO 8-bit extended-ASCII character sets (such as those used on
Macintosh and IBM PC systems), UTF-8-encoded Unicode, UTF-16-
encoded Unicode, and EBCDIC character sets can be distinguished
by the different ranges and sequences of bytes that constitute
printable text in each set. If a file passes any of these tests, its
character set is reported. ASCII, ISO-8859-x, UTF-8, and extended-
ASCII files are identified as “text” because they will be mostly
readable on nearly any terminal; UTF-16 and EBCDIC are only
“character data” because, while they contain text, it is text that will
require translation before it can be read. In addition, file will attempt
to determine other characteristics of text-type files. If the lines of a
file are terminated by CR, CRLF, or NEL, instead of the Unix-
standard LF, this will be reported. Files that contain embedded
escape sequences or overstriking will also be identified.
Once file has determined the character set used in a text-type file, it
will attempt to determine in what language the file is written. The
language tests look for particular strings (cf ,<names.h>) that can
appear anywhere in the first few blocks of a file. For example, the
keyword .br indicates that the file is most likely a troff(1) input file, just
as the keyword struct indicates a C program. These tests are less
reliable than the previous two groups, so they are performed last.
2
Enrollment No : 190410116100 SY IT 3 A
The language test routines also test for some miscellany (such as
tar(1) archives, JSON files).
Any file that cannot be identified as having been written in any of the
character sets listed above is simply said to be “data”.
OPTIONS DESCRIPTION
--apple Causes the file command to output the file
type and creator code as used by older
MacOS versions. The code consists of eight
letters, the first describing the file type, the
latter the creator. This option works properly
only for file formats that have the apple-style
output defined.
-b --brief Do not prepend filenames to output lines
(brief mode).
-C --compile Write a magic.mgc output file that contains a
pre-parsed version of the magic file or
directory.
-c --checking-printout Cause a checking printout of the parsed
form of the magic file. This is usually used
in conjunction with the -m flag to debug a
new magic file before installing it.
-d Prints internal debugging information to
stderr.
-E On filesystem errors (file not found etc),
instead of handling the error as regular
output as POSIX mandates and keep going,
issue an error message and exit.
-e --exclude [=TESTNAME] Exclude the test named in testname from the
list of tests made to determine the file type.
Valid test names are:
apptype EMX application type (only on EMX).
ascii Various types of text files (this test will try to
guess the text encoding, irrespective of the
setting of the ‘encoding’ option).
encoding Different text encodings for soft magic tests.
2
Enrollment No : 190410116100 SY IT 3 A
2
Enrollment No : 190410116100 SY IT 3 A
2
Enrollment No : 190410116100 SY IT 3 A
EXAMPLE :
33) finger :
Displays information about a user on a specified system running the
Finger service. Output varies based on the remote system.
2
Enrollment No : 190410116100 SY IT 3 A
SYNTAX :
FINGER [-l] [user]@host [...]
DESCRIPTION :
OPTIONS DESCRIPTION
-l Displays information in long list format.
User Specifies the user you want information about. Omit the
user parameter to display information about all users on
the specified host.
@host Specifies the server on the remote system whose users
you want information about.
34) sleep :
Delay for a specified amount of time
SYNTAX :
sleep NUMBER[SUFFIX]...
sleep OPTION
DESCRIPTION :
Pause for NUMBER seconds. SUFFIX may be 's' for seconds (the
default), 'm' for minutes, 'h' for hours or 'd' for days. Unlike most
implementations that require NUMBER be an integer, here NUMBER
may be an arbitrary floating point number. Given two or more
arguments, pause for the amount of time specified by the sum of their
values.
EXAMPLE :
2
Enrollment No : 190410116100 SY IT 3 A
35) ps :
Report process status.
SYNTAX :
ps [-aefls] [-u UID] [-p PID]
DESCRIPTION :
OPTIONS DESCRIPTION
-a --all show processes of all users
-e --everyone show processes of all users
-f --full show process uids, ppids
-l --long show process uids, ppids, pgids, winpids
-p --process show information for specified PID
-s --summary show process summary
-u --user list processes owned by UID
-w --windows show windows as well as cygwin processes
EXAMPLE :
36) kill :
Send a signal to a job.
SYNTAX :
kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
2
Enrollment No : 190410116100 SY IT 3 A
DESCRIPTION :
Send the processes identified by PID or JOBSPEC the signal named
by SIGSPEC or SIGNUM. If neither SIGSPEC nor SIGNUM is
present, then SIGTERM is assumed.
OPTIONS DESCRIPTION
-s sig SIG is a signal name
-n sig SIG is a signal number
-l list the signal names ; if arguments follow ‘-l’ they are
assumed to be signal numbers for which names should be
listed
-L synonym for -l
Kill is a shell built in for two reasons: it allows job IDs to be used
instead of process IDs and allows processes to be killed if the limit on
processes that you can create is reached.
37) head :
Output the first part of the files
SYNTAX :
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.
OPTIONS DESCRIPTION
-c --bytes [=[-]NUM] print the first NUM bytes of each file; with the
leading '-', print all but the last NUM bytes of each
file
2
Enrollment No : 190410116100 SY IT 3 A
-n --lines [=[-]NUM] print the first NUM lines instead of the first 10;
with the leading '-', print all but the last NUM lines
of each file
-q --quiet, --silent never print headers giving file names
-v --verbose always print headers giving file names
-z --zero-terminated line delimiter is NUL, not newline
EXAMPLE :
38) tail :
Output the last part of the files
SYNTAX :
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.
2
Enrollment No : 190410116100 SY IT 3 A
OPTIONS DESCRIPTION
-c --bytes [=[+]NUM] output the last NUM bytes; or use -c
+NUM to output starting with byte NUM of
each file
-f --follow [={NAME| output appended data as the file grows;
DESCRIPTOR}] an absent option argument means
'descriptor'
-F same as --follow=name --retry
-n --lines [=[+]NUM] output the last NUM lines, instead of the
last 10; or use -n +NUM to output starting
with line NUM
--max-unchanged-stats with --follow=name, reopen a FILE which
[=N] has not changed size after N (default 5)
iterations to see if it has been unlinked or
renamed (this is the usual case of rotated
log files); with inotify, this option is rarely
useful
--pid [=PID] with -f, terminate after process ID, PID
dies
-q --quiet, --silent never output headers giving file names
--retry keep trying to open a file if it is
inaccessible
-s --sleep-interval [=N] with -f, sleep for approximately N seconds
(default 1.0) between iterations; with
inotify and --pid=P, check process P at
least once every N seconds
-v --verbose always output headers giving file names
-z --zero-terminated line delimiter is NUL, not newline
EXAMPLE :
2
Enrollment No : 190410116100 SY IT 3 A
39) sort :
Sort lines of text files.
Syntax :
sort [OPTION]... [FILE]...
sort [OPTION]... --files0-from=F
DESCRIPTION :
Write sorted concatenation of all FILE(s) to standard output.
With no FILE, or when FILE is -, read standard input.
Mandatory arguments to long options are mandatory for short options
too. Ordering options:
OPTIONS DESCRIPTION
-b --ignore-leading-blanks ignore leading blanks
-d --dictionary-order consider only blanks and alphanumeric
characters
-f --ignore-case fold lower case to upper case characters
2
Enrollment No : 190410116100 SY IT 3 A
2
Enrollment No : 190410116100 SY IT 3 A
EXAMPLE :
40) find :
Search for files in a directory hierarchy
SYNTAX :
find [-H] [-L] [-P] [-D debugopts] [-Olevel] [starting-point...]
[expression]
DESCRIPTION :
2
Enrollment No : 190410116100 SY IT 3 A
This manual page documents the GNU version of find. GNU find
searches the directory tree rooted at each given starting point by
evaluating the given expression from left to right, according to the
rules of precedence (see section OPERATORS), until the outcome is
known (the left hand side is false for and operations, true for or), at
which point find moves on to the next file name. If no starting point is
specified, `.' is assumed.
If you are using find in an environment where security is important
(for example if you are using it to search directories that are writable
by other users), you should read the "Security Considerations"
chapter of the find utils documentation, which is called Finding Files
and comes with find utils. That document also includes a lot more
detail and discussion than this manual page, so you may find it a
more useful source of information.
OPTIONS :
The -H, -L and -P options control the treatment of symbolic links.
Command-line arguments following these are taken to be names of
files or directories to be examined, up to the first argument that
begins with `-', or the argument `(' or `!'. That argument and any
following arguments are taken to be the expression describing what is
to be searched for. If no paths are given, the current directory is used.
If no expression is given, the expression -print is used (but you
should probably consider using -print0 instead, anyway).
This manual page talks about ‘options’ within the expression list.
These options control the behaviour of find but are specified
immediately after the last path name. The five `real' options -H, -L, -
P, -D and -O must appear before the first path name, if at all. A
double dash -- can also be used to signal that any remaining
arguments are not options (though ensuring that all start points begin
with either `./' or `/' is generally safer if you use wildcards in the list of
start points).
-P :-> Never follow symbolic links. This is the default behaviour.
When find examines or prints information a file, and the file is a
symbolic link, the information used shall be taken from the properties
of the symbolic link itself.
-L :-> Follow symbolic links. When find examines or prints
information about files, the information used shall be taken from the
properties of the file to which the link points, not from the link itself
(unless it is a broken symbolic link or find is unable to examine the
file to which the link points). Use of this option implies -noleaf. If you
later use the -P option, -noleaf will still be in effect. If -L is in effect
2
Enrollment No : 190410116100 SY IT 3 A
2
Enrollment No : 190410116100 SY IT 3 A
EXAMPLE :
41) uniq :
Report or omit repeated lines
SYNTAX :
uniq [OPTION]... [INPUT [OUTPUT]]
DESCRIPTION :
Filter adjacent matching lines from INPUT (or standard input), writing
to OUTPUT (or standard output).
With no options, matching lines are merged to the first occurrence.
Mandatory arguments to long options are mandatory for short options
too.
OPTIONS DESCRIPTION
-c --count prefix lines by the number of occurrences
-d --repeated only print duplicate lines, one for each group
-D print all duplicate lines
--all-repeated like -D, but allow separating groups with an empty line;
[=METHOD] METHOD={none(default),prepend,separate}
-f --skip-fields [=N] avoid comparing the first N fields
--group [=METHOD] show all items, separating groups with an empty line;
METHOD={separate(default),prepend,append,both}
-i --ignore-case ignore differences in case when comparing
2
Enrollment No : 190410116100 SY IT 3 A
EXAMPLE :
42) tr :
Translate or delete characters.
SYNTAX :
tr [OPTION]... SET1 [SET2]
DESCRIPTION :
Translate, squeeze, and/or delete characters from standard input,
writing to standard output.
OPTIONS DESCRIPTION
-c, -C --complement use the complement of SET1
-d --delete delete characters in SET1, do not
translate
-s --squeeze-repeats replace each sequence of a repeated
character that is listed in the last specified
SET, with a single occurrence of that
2
Enrollment No : 190410116100 SY IT 3 A
character
-t --truncate-set1 first truncate SET1 to length of SET2
EXAMPLE :
43) history :
Display or manipulate the history list.
SYNTAX :
history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg
[arg...]
DESCRIPTION :
Display the history list with line numbers, prefixing each modified
entry with a `*'. An argument of N lists only the last N entries.
OPTIONS DESCRIPTION
-c clear the history list by deleting all of the entries
-d offset delete the history entry at position OFFSET.
-a append history lines from this session to the history file
-n read all history lines not already read from the history file and append
them to the history list
-r read the history file and append the contents to the history list
-w write the current history to the history file
2
Enrollment No : 190410116100 SY IT 3 A
EXAMPLE :
44) write :
Send a message to another user.
SYNTAX :
write user [ttyname]
DESCRIPTION :
write allows you to communicate with other users, by copying lines
from your terminal to theirs.
When you run the write command, the user you are writing to gets a
message of the form: Message from yourname@yourhost on yourtty
at hh:mm ...
Any further lines you enter will be copied to the specified
user&apos;s terminal. If the other user wants to reply, they must
run write as well.
When you are done, type an end-of-file or interrupt character. The
other user will see the message EOF indicating that the conversation
is over.
You can prevent people (other than the superuser) from writing to you
with the mesg(1) command. Some commands, for example nroff(1)
2
Enrollment No : 190410116100 SY IT 3 A
and pr(1), may automatically disallow writing, so that the output they
produce isn&apos;t overwritten.
If the user you want to write to is logged in on more than one terminal,
you can specify which terminal to write to by giving the terminal name
as the second operand to the write command. Alternatively, you can
let write select one of the terminals - it will pick the one with the
shortest idle time. This is so that if the user is logged in at work and
also dialed up from home, the message will go to the right place.
EXAMPLE :
45) grep :
grep, egrep, fgrep - print lines matching a pattern.
SYNTAX :
grep [OPTIONS] PATTERN [FILE...]
grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]
DESCRIPTION :
2
Enrollment No : 190410116100 SY IT 3 A
grep searches the named input FILEs for lines containing a match to
the given PATTERN. If no files are specified, or if the file “-” is given,
grep searches standard input. By default, grep prints the matching
lines.
In addition, the variant programs egrep and fgrep are the same as
grep -E and grep -F, respectively. These variants are deprecated,
but are provided for backward compatibility.
OPTIONS DESCRIPTION
-E --extended-regexp Interpret PATTERN as an extended
regular expression (ERE, see below).
-F --fixed-strings Interpret PATTERN as a list of fixed
strings (instead of regular expressions),
separated by newlines, any of which is to
be matched.
-G --basic-regexp Interpret PATTERN as a basic regular
expression (BRE, see below). This is the
default.
-P --perl-regexp Interpret the pattern as a Perl-compatible
regular expression (PCRE). This is highly
experimental and grep -P may warn of
unimplemented features.
-e --regexp [=PATTERN] Use PATTERN as the pattern. If this
[=PATTERN] option is used multiple times or is
combined with the -f (--file) option, search
for all patterns given. This option can be
used to protect a pattern beginning with
“-”.
-f [=FILE] --file [=FILE] Obtain patterns from FILE, one per line. If
this option is used multiple times or is
combined with the -e (--regexp) option,
search for all patterns given. The empty
file contains zero patterns, and therefore
matches nothing.
-i --ignore-case Ignore case distinctions in both the
PATTERN and the input files.
-v --invert-match Invert the sense of matching, to select
non-matching lines.
2
Enrollment No : 190410116100 SY IT 3 A
2
Enrollment No : 190410116100 SY IT 3 A
2
Enrollment No : 190410116100 SY IT 3 A
EXAMPLE :
2
Enrollment No : 190410116100 SY IT 3 A
46) wc :
Print newline, word, and byte counts for each file.
SYNTAX :
wc [OPTION]... [FILE]...
wc [OPTION]... --files0-from=F
DESCRIPTION :
Print newline, word, and byte counts for each FILE, and a total line if
more than one FILE is specified. A word is a non-zero-length
sequence of characters delimited by white space.
With no FILE, or when FILE is -, read standard input.
The options below may be used to select which counts are printed,
always in the following order: newline, word, character, byte,
maximum line length.
OPTIONS DESCRIPTION
-c --bytes print the byte counts
-m --chars print the character counts
-l --lines print the newline counts
--files0-from [=F] read input from the files specified by NUL-terminated
names in file F; If F is - then read names from standard
input
-L --max-line-length print the maximum display width
-w --words print the word counts
EXAMPLE :
2
Enrollment No : 190410116100 SY IT 3 A
SYNTAX :
command_1 | command_2 | command_3 | … command_N …
DESCRIPTION :
In short, the output of each process directly as input to the next one
like a pipeline.
The symbol ‘|’ denotes a pipe.
Pipes help you mash-up two or more commands at the same time
and run them consecutively.
EXAMPLE :
2
Enrollment No : 190410116100 SY IT 3 A
48) bc :
An arbitrary precision calculator language
SYNTAX :
bc [ -hlwsqv ] [long-options] [ file ... ]
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. (If a file contains a command to halt the
processor, bc will never read from the standard input.)
This version of bc contains several extensions beyond traditional bc
implementations and the POSIX draft standard. Command line
options can cause these extensions to print a warning or to be
rejected. This document describes the language accepted by this
processor. Extensions will be identified as such.
49) wall :
Write a message to all users
SYNTAX :
wall [-n] [-t timeout] [-g group] [message | file]
DESCRIPTION :
wall displays a message, or the contents of a file, or otherwise its
standard input, on the terminals of all currently logged in users. The
command will wrap lines that are longer than 79 characters. Short
2
Enrollment No : 190410116100 SY IT 3 A
50) ln :
Make lines between files.
SYNTAX :
ln [OPTION]... [-T] TARGET LINK_NAME (1st form)
ln [OPTION]... TARGET (2nd form)
ln [OPTION]... TARGET... DIRECTORY (3rd form)
ln [OPTION]... -t DIRECTORY TARGET... (4th form)
DESCRIPTION :
In the 1st form, create a link to TARGET with the name LINK_NAME.
In the 2nd form, create a link to TARGET in the current directory. In
the 3rd and 4th forms, create links to each TARGET in DIRECTORY.
Create hard links by default, symbolic links with --symbolic. By
default, each destination (name of new link) should not already exist.
When creating hard links, each TARGET must exist. Symbolic links
can hold arbitrary text; if later resolved, a relative link is interpreted in
relation to its parent directory.
Mandatory arguments to long options are mandatory for short options
too.
OPTIONS DESCRIPTION
--backup [=CONTROL] make a backup of each existing
destination file
-b like --backup but does not accept an
argument
-d, -F --directory allow the superuser to attempt to hard link
directories (note: will probably fail due to
system restrictions, even for the
superuser)
2
Enrollment No : 190410116100 SY IT 3 A
EXAMPLE :
2
Enrollment No : 190410116100 SY IT 3 A
Practical - 3
a) Write a shell script to generate marksheet of a student. Take 3
subjects, calculate and display total marks, percentage and Class
obtained by the student.
Input :
per=`expr $total / 3`
echo "Percentage : $per %"
if [ $per -gt 70 ]
then
echo "Distinction Class"
fi
Output :
Input :
2
Enrollment No : 190410116100 SY IT 3 A
read n1
Output :
Input :
echo "Enter Number 1 :"
2
Enrollment No : 190410116100 SY IT 3 A
read n1
else
echo "All are equal"
fi
Output :
2
Enrollment No : 190410116100 SY IT 3 A
Practical - 4
a) Write a shell script to find factorial of given number n.
Input :
echo "Enter Number : "
read n
fact=1
while [ $n -gt 1 ]
do
fact=`expr $fact \* $n`
n=`expr $n - 1`
done
Output :
2
Enrollment No : 190410116100 SY IT 3 A
Input :
echo "Enter Number : "
read n
i=1
while [ $i -le 10 ]
do
echo "$n x $i = `expr $n \* $i`"
i=`expr $i + 1`
done
Output :
2
Enrollment No : 190410116100 SY IT 3 A
Input :
echo "Enter Number : "
read n
if [ `expr $n % 2` -eq 0 ]
then
echo "Number is Even"
else
echo "Number is Odd"
fi
Output :
2
Enrollment No : 190410116100 SY IT 3 A
Practical - 5
Write a shell script which will accept a number b and display first n
prime numbers as output.
Input :
echo "Enter Range : "
read r
j=2
while [ $j -le $r ]
do
n=$j
2
Enrollment No : 190410116100 SY IT 3 A
i=2
while [ $i -le $n ]
do
if [ `expr $n % $i` -eq 0 ]
then
break
fi
i=`expr $i + 1`
done
if [ $i -eq $n ]
then
echo $n
fi
j=`expr $j + 1`
done
Output :
2
Enrollment No : 190410116100 SY IT 3 A
Practical - 6
Write a shell script which will generate first n fibonacci numbers like:
1, 1, 2, 3, 5, 13,…
Input :
echo "Enter Range : "
read n
n1=1
n2=1
2
Enrollment No : 190410116100 SY IT 3 A
do
echo $n2
temp=$n1
n1=`expr $n1 + $n2`
n2=$temp
done
Output :
Practical - 7
Write a menu driven shell script which will print the following menu
and execute the given task.
a) Display calendar of current month
b) Display today’s date and time
c) Display usernames those are currently logged in the system
d) Display your name at given x, y position
e) Display your terminal number
Input :
echo "Main - Menu"
echo "1. Display calendar of current month"
echo "2. Display today's date and time"
2
Enrollment No : 190410116100 SY IT 3 A
echo "3. Display usernames of those are currently logged in the system"
echo "4. Display your name at given x, y position"
echo "5. Display your terminal number"
echo "6. Exit"
case $choice in
1)cal;;
2)date;;
3)whoami;;
4)printf "%10s%10s\n" Soham Patel;;
5)tty;;
6)exit 0;;
*)echo "Enter valid choice";;
esac
Output :
2
Enrollment No : 190410116100 SY IT 3 A
Practical - 8
Write a shell script to check entered string is palindrome or not.
Input :
Output :
2
Enrollment No : 190410116100 SY IT 3 A
Practical - 9
Write a shell script to read n numbers as command arguments and sort
them in descending order.
Input :
i=0
for n in $@
do
arr[$i]=$n
i=`expr $i + 1`
done
2
Enrollment No : 190410116100 SY IT 3 A
l=`expr $# - 1`
for ((j=0;j<$#;++j))
do
for ((a=0;a<l;++a))
do
aa=`expr $a + 1`
if [ ${arr[$a]} -lt ${arr[$aa]} ]
then
temp=${arr[$a]}
arr[$a]=${arr[$aa]}
arr[$aa]=$temp
fi
done
done
echo " "
Output :
2
Enrollment No : 190410116100 SY IT 3 A
Practical - 10
Write a shell script to display all executable files, directories and zero
sized files from current directory.
Input :
2
Enrollment No : 190410116100 SY IT 3 A
if [ -f $file -a -x $file ]
then
echo "$file"
fi
#ls -l $file
done
for file in *
do
if [ ! -s $file ]
then
echo "$file"
fi
#ls -l $file
done
2
Enrollment No : 190410116100 SY IT 3 A
Output :