OSV Practical GTU Sem 4

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 96

Enrollment No : 190410116100 SY IT 3 A

SARDAR VALLABHBHAI PATEL


INSTITUTE OF TECHNOLOGY ,
VASAD

Operating System &


Virtualization
SY BE SEMESTER - IV

Name : Soham Patel

Enrollment No : 190410116100

Branch : Information Technology

Division : SY IT 3

Batch : A

Academic Year : 2020 - 21

2
Enrollment No : 190410116100 SY IT 3 A

SARDAR VALLBHBHAI PATEL INSTITUTE


OF TECHNOLOGY, VASAD

CERTIFICATE

This is certify that Mr./Ms. Soham C. Patel Enrollment


No 190410116100 of program S.Y. B.E. Semester
IV Branch Information Technology has satisfactorily
completed his/her Term Work in Code No : 3141601 in
course of OPERATING SYSTEM &
VIRTUALIZATION for the term 2020-2021.

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 :

 cal [options] [[[day] month] year]


 cal [options] [timestamp / monthname]

 DESCRIPTION :

 cal displays a simple calendar. If no arguments are specified, the


current month is displayed.
 The month may be specified as a number (1-12), as a month name or
as an abbreviated month name according to the current locales.
 Two different calendar systems are used, Gregorian and Julian.
These are nearly identical systems with Gregorian making a small
adjustment to the frequency of leap years; this facilitates improved
synchronization with solar events like the equinoxes. The Gregorian
calendar reform was introduced in 1582, but its adoption continued up
to 1923. By default cal uses the adoption date of 3 Sept 1752. From
that date forward the Gregorian calendar is displayed; previous dates
use the Julian calendar system. 11 days were removed at the time of
adoption to bring the calendar in sync with solar events. So Sept
1752 has a mix of Julian and Gregorian dates by which the 2nd is
followed by the 14th (the 3rd through the 13th are absent).
 Optionally, either the proleptic Gregorian calendar or the Julian
calendar may be used exclusively. See --reform below.

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.

-s --Sunday Display Sunday as the first day of the week.

-m --Monday Display Monday as the first day of the week.


--iso Display the proleptic Gregorian calendar
exclusively. See --reform below.
-j --julian Use day-of-year numbering for all calendars.
These are also called ordinal days. Ordinal
days range from 1 to 366. This option does not
switch from the Gregorian to the Julian
calendar system, that is controlled by the --
reform option.
-y --year Display a calendar for the whole year.
-Y --twelve Display a calendar for the next twelve months.
-w --week [=NUMBER] Display week numbers in the calendar (US or
ISO-8601).
--color [=WHEN] Colorize the output. The optional argument
when can be auto, never or always. If the
when argument is omitted, it defaults to auto.
The colors can be disabled; for the current
built-in default see the --help output. See also
the COLORS section.
-V --version Display version information and exit.
-h --help Display help text and exit.

 EXAMPLE :

2
Enrollment No : 190410116100 SY IT 3 A

2) pwd :
 Print name of current / working directory

 SYNTAX :

 pwd [option]….

 DESCRIPTION :

 Print the full filename of the current working directory.

OPTIONS DESCRIPTION
-L --logical use PWD from environment, even if it contains
symlinks
-P --physical avoid all symlinks

--help display this help and exit

--version output version information and exit

 If no option is specified, -P is assumed.

 EXAMPLE :

3) ls :
2
Enrollment No : 190410116100 SY IT 3 A

 List directory contents

 SYNTAX :

 ls [option]... [file]...

 DESCRIPTION :

 List information about the FILEs (the current directory by default).


Sort entries alphabetically if none of -cftuvSUX nor --sort is
specified.
 Mandatory arguments to long options are mandatory for short options
too.

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

--format [=WORD] across -x, commas -m, horizontal -x, long -


l, single-column -1, verbose -l, vertical -C
--full-time like -l --time-style=full-iso
-g like -l, but do not list owner
--group-directories- group directories before files;
first
can be augmented with a --sort option, but
any use of --sort=none (-U) disables
grouping

-G --no-group in a long listing, don't print group names


-h --human-readable with -l and/or -s, print human readable sizes
(e.g., 1K 234M 2G)
--si likewise, but use powers of 1000 not 1024
-H --dereference- follow symbolic links listed on the command
command-line line
--dereference- follow each command line symbolic link
command-line-
that points to a directory
symlink-to-dir
--hide [=PATTERN] do not list implied entries matching shell
PATTERN (overridden by -a or -A)
--indicator-style append indicator with style WORD to entry
[=WORD] names: none (default), slash (-p), file-type
(--file-type), classify (-F)
-i --inode print the index number of each file
-I --ignore [=PATTERN] do not list implied entries matching shell
PATTERN
-k --kibibytes default to 1024-byte blocks for disk usage
-l use a long listing format
-L --deference when showing file information for a
symbolic link, show information for the file
the link references rather than for the link
itself
-m fill width with a comma separated list of
entries
-n --numeric-uid-gid like -l, but list numeric user and group IDs
-N --literal print entry names without quoting
-o like -l, but do not list group information
-p --indicater-style append / indicator to directories
[=SLASH]
-q --hide-control-chars print ? instead of nongraphic characters

2
Enrollment No : 190410116100 SY IT 3 A

--show-control-chars show nongraphic characters as-is (the


default, unless program is 'ls' and output is
a terminal)
-Q --quote-name enclose entry names in double quotes
--quoting-style use quoting style WORD for entry names:
[=WORD] literal, locale, shell, shell-always, shell-
escape, shell-escape-always, c, escape
-r --reverse reverse order while sorting
-R --recursive list subdirectories recursively
-s --size print the allocated size of each file, in blocks
-S sort by file size, largest first
--sort [=WORD] sort by WORD instead of name: none (-U),
size (-S), time (-t), version (-v), extension (-
X)
--time [=WORD] with -l, show time as WORD instead of
default modification time: atime or access or
use (-u); ctime or status (-c); also use
specified time as sort key if --sort=time
(newest first)
--time-style [=STYLE] with -l, show times using style STYLE:
full-iso, long-iso, iso, locale, or +FORMAT;
FORMAT is interpreted like in 'date'; if
FORMAT is
FORMAT1<newline>FORMAT2, then
FORMAT1 applies to
non-recent files and FORMAT2 to recent
files; if STYLE is prefixed with 'posix-',
STYLE takes effect only outside the POSIX
locale
-t sort by modification time, newest first
-T --tabsize [=COLS] assume tab stops at each COLS instead of
8
-u with -lt: sort by, and show, access time;
with -l: show access time and sort by name;
otherwise: sort by access time, newest first
-U do not sort; list entries in directory order
-v natural sort of (version) numbers within text
-w --width [=COLS] set output width to COLS. 0 means no limit
-x list entries by lines instead of by columns
-X sort alphabetically by entry extension
-Z --context print any security context of each file

2
Enrollment No : 190410116100 SY IT 3 A

-1 list one file per line. Avoid '\n' with -q or -b


--append-exe append .exe if cygwin magic was needed
--help display this help and exit
--version output version information and exit

 The SIZE argument is an integer and optional unit (example: 10K is


10*1024). Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,...
(powers of 1000).
 Using color to distinguish file types is disabled both by default and
with --color = never. With --color = auto, ls emits color codes only
when standard output is connected to a terminal. The LS_COLORS
environment variable can change the settings. Use the dircolors
command to set it.

 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:

-x do not attempt to clear the terminal's scrollback buffer using


the extended “E3” capability.

 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

 An interface to the on-line reference manuals

 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.

1 Executable programs or shell commands


2 System calls (functions provided by the kernel)
3 Library calls (functions within program libraries)
4 Special files (usually found in /dev)

2
Enrollment No : 190410116100 SY IT 3 A

5 File formats and conventions eg /etc/passwd


6 Games
7 Miscellaneous (including macro packages and conventions), e.g.
man(7), groff(7)
8 System administration commands (usually only for root)
9 Kernel routines [Non standard]
 A manual page consists of several sections.
 Conventional section names include NAME, SYNOPSIS,
CONFIGURATION, DESCRIPTION, OPTIONS, EXIT STATUS,
RETURN VALUE, ERRORS, ENVIRONMENT, FILES, VERSIONS,
CONFORMING TO, NOTES, BUGS, EXAMPLE, AUTHORS, and
SEE ALSO.
 The following conventions apply to the SYNTEX section and can be
used as a guide in other sections.

o bold text type exactly as shown.


o italic text replace with appropriate argument.
o [-abc] any or all arguments within [ ] are optional.
o -a|-b options delimited by | cannot be used together.
o argument ... argument is repeatable.
o [expression] ... entire expression within [ ] is repeatable.

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

-Z --ditroff use groff and force it to produce ditroff


-? --help give this help list

2
Enrollment No : 190410116100 SY IT 3 A

--usage give a short usage message

 EXAMPLE :

8)whoami :

 Print effective userid

 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 :

 echo [SHORT-OPTION]… [STRING]…


 echo LONG-OPTION

 DESCRIPTION :

 Echo the STRING(s) to standard output.

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

-m only hostname and user associated with


stdin
-p --process print active processes spawned by init
-q --count all login names and number of users logged
on
-r --runlevel print current runlevel
-s --short print only name, line, and time (default)
-t --time print last system clock change
-T, -w --mesg add user's message status as +, - or ?
-u --users list users logged in
--message same as -T
--writable same as -T

 EXAMPLE :

2
Enrollment No : 190410116100 SY IT 3 A

11) mkdir :
 Make directories

 SYNTAX :

 mkdir [OPTION]… DIRECTORY…

 DESCRIPTION :

 Create the DIRECTORY(ies), if they do not already exist.


 Mandatory arguments to long options are mandatory for short options
too.

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

-z set SELinux security context of each created


directory to the default type

2
Enrollment No : 190410116100 SY IT 3 A

--context [=CTX] like -Z, or if CTX is specified then set the


SELinux or SMACK security context to CTX

 EXAMPLE :

12) rmdir :
 Remove empty directories

 SYNTAX :
 rmdir [OPTION]… DIRECTORY…

 DESCRIPTION :

 Remove the DIRECTORY(ies), if they are empty.

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

 Change and print terminal line settings

 SYNTAX :
 stty [-F DEVICE | --file=DEVICE] [SETTING]...
 stty [-F DEVICE | --file=DEVICE] [-a | --all]
 stty [-F DEVICE | --file=DEVICE] [-g | --save]

 DESCRIPTION :

 Print or change terminal characteristics.


 Mandatory arguments to long options are mandatory for short
options too.

OPTIONS DESCRIPTION
-a --all print all current settings in human-readable form

-g --save print all current settings in a stty-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

 Copy files and directories.

 SYNTAX :

 cp [OPTION]... [-T] SOURCE DEST


 cp [OPTION]... SOURCE... DIRECTORY
 cp [OPTION]... -t DIRECTORY SOURCE...

 DESCRIPTION :

 Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.


 Mandatory arguments to long options are mandatory for short options
too.

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

-p same as –preserve = mode, ownership,


timestamps
--preserve preserve the specified attributes (default :
[=ATTR_LIST] mode, ownership, timestamps), if possible
additional attributes: context, links, xattr,
all
--no-preserve don't preserve the specified attributes
[=ATTR_LIST]
--parents use full source file name under
DIRECTORY
-R, -r --recursive copy directories recursively
--reflink [=WHEN] control clone/CoW copies. See below

--remove- remove each existing destination file


destination before attempting to open it (contrast with
--force)
--sparse [=WHEN] control creation of sparse files. See below
--strip-trailing- remove any trailing slashes from each
slashes SOURCE argument
-s --symbolic-link make symbolic links instead of copying
-S --suffix [=SUFFIX] override the usual backup suffix
-t --target-directory copy all SOURCE arguments into
[=DIRECTORY] DIRECTORY
-T --no-target-directory treat DEST as a normal file
-u --update copy only when the SOURCE file is newer
than the destination file or when the
destination file is missing
-v --verbose explain what is being done
-x --one-file-system stay on this file system

-Z set SELinux security context of destination


file to default type

--context [=CTX] like -Z, or if CTX is specified then set the


SELinux or SMACK security context to
CTX

2
Enrollment No : 190410116100 SY IT 3 A

 EXAMPLE :

18) rm :
 Remove files or directories

 SYNTAX :

 rm [OPTION]… [FILE]…

 DESCRIPTION :

 This manual page documents the GNU version of rm. rm removes


each specified file. By default, it does not remove directories.
 If the -I or --interactive=once option is given, and there are more than
three files or the -r, -R, or --recursive are given, then rm prompts the
user for whether to proceed with the entire operation. If the response
is not affirmative, the entire command is aborted.
 Otherwise, if a file is unwritable, standard input is a terminal, and the
-f or --force option is not given, or the -i or --interactive=always option
is given, rm prompts the user for whether to remove the file. If the
response is not affirmative, the file is skipped.

OPTIONS DESCRIPTION
-f --force ignore nonexistent files and arguments, never
prompt

2
Enrollment No : 190410116100 SY IT 3 A

-i prompt before every removal


-I prompt once before removing more than three
files, or when removing recursively; less
intrusive than -i, while still giving protection
against most mistakes
--interactive prompt according to WHEN: never, once (-I), or
always (-i); without WHEN, prompt always
--one-file-system when removing a hierarchy recursively, skip any
directory that is on a file system different from
that of the corresponding command line
argument

--no-preserve-root do not treat '/' specially


--preserve-root do not remove '/' (default)
-r, -R --recursive remove directories and their contents
recursively
-d --dir remove empty directories
-v --verbose explain what is being done

 EXAMPLE :

19) mv :
 Move (rename) files

 SYNTAX :

 mv [OPTION]... [-T] SOURCE DEST


 mv [OPTION]... SOURCE... DIRECTORY
 mv [OPTION]... -t DIRECTORY SOURCE...

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

If you specify more than one of -i, -f, -n,


only the final one takes effect.
--strip-trailing-slashes remove any trailing slashes from each
SOURCE argument
-s --suffix [=SUFFIX] override the usual backup suffix
-t --target-directory move all SOURCE arguments into
[=DIRECTORY] DIRECTORY
-T --no-target-directory treat DEST as a normal file
-u --update move only when the SOURCE file is
newer than the destination file or when the
destination file is missing
-v --verbose explain what is being done
-z --context set SELinux security context of destination
file to default type

 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

-p --no-renumber do not reset line numbers for each section

-s --number-separator add STRING after (possible) line number


[=STRING]
-v --starting-line-number first line number for each section
[=NUMBER]
-w --number-width use NUMBER columns for line numbers
[=NUMBER]

 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

-d --delimiter [=DELIM] use DELIM instead of TAB for field delimiter


-f --fields [=LIST] select only these fields; also print any line that
contains no delimiter character, unless the -s
option is specified
--complement complement the set of selected bytes,
characters or fields
-s --only-delimited do not print lines not containing delimiters

--output-delimiter use STRING as the output delimiter the


[=STRING] default is to use the input delimiter
-z --zero-terminated line delimiter is NUL, not newline

 EXAMPLE :

22) paste :
 Merge lines of files.

 SYNTAX :

 paste [OPTION]… [FILE]…

2
Enrollment No : 190410116100 SY IT 3 A

 DESCRIPTION :

 Write lines consisting of the sequentially corresponding lines from


each FILE, separated by TABs, 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
-d --delimiters [=LIST] reuse characters from LIST instead of TABs
-s --serial paste one file at a time instead of in parallel
-z --zero-terminated line delimiter is NUL, not newline

 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

-n --bytes [=LIMIT] compare at most LIMIT bytes


-s --quiet, --silent suppress all normal output

 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

--nocheck-order do not check that the input is correctly


sorted
--output-delimiter [=STR] separate columns with STR
--total output a summary
-z --zero-terminated line delimiter is NUL, not newline

 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

-e --ed output an ed script


-n --rcs output an RCS format diff
-y --side-by-side output in two columns
-W --width [=NUM] output at most NUM (default 130) print
columns
--left-column output only the left column of common
lines
--supress-common-lines do not output common lines

-p --show-c-function show which C function each change is in


-F --show-function-line show the most recent line matching RE
[=RE]
--label [=LABEL] use LABEL instead of file name and
timestamp (can be repeated)
-t --expand-tabs expand tabs to spaces in output
-T --initial-tab make tabs line up by prepending a tab
--tabsize [=NUM] tab stops every NUM (default 8) print
columns
--supress-blank-empty suppress space or tab before empty
output lines
-l --paginate pass output through 'pr' to paginate it
-r --recursive recursively compare any subdirectories
found
--no-deference recursively compare any subdirectories
found
-N --new-file treat absent files as empty
--unidirectional-new-file treat absent first files as empty
--ignore-file-name-case ignore case when comparing file names
--no-ignore-file-name- consider case when comparing file
case names

-x --exclude [=PAT] exclude files that match PAT


-X --exclude-from [=FILE] exclude files that match any pattern in
FILE
-S --starting-file [=FILE] start with FILE when comparing
directories
`--from-file [=FILE1] compare FILE1 to all operands; FILE1
can be a directory
--to-file [=FILE2] compare all operands to FILE2; FILE2
can be a directory
-i --ignore-case ignore case differences in file contents

2
Enrollment No : 190410116100 SY IT 3 A

-E --ignore-tab-expansion ignore changes due to tab expansion


-Z --ignore-trailing-space ignore white space at line end
-b --ignore-space-change ignore changes in the amount of white
space
-w --ignore-all-space ignore all white space
-B --ignore-blank-lines ignore changes where lines are all blank
-I --ignore-matching-lines ignore changes where all lines match RE
[=RE]
-a --text treat all files as text
--strip-trailing-cr strip trailing carriage return on input
-D --ifdef [=NAME] output merged file with '#ifdef NAME' diffs

--GTYPE-group-format format GTYPE input groups with GFMT


[=GFMT]
--line-format [=LFMT] format all input lines with LFMT
-d --minimal try hard to find a smaller set of changes
--horizon-lines [=NUM] keep NUM lines of the common prefix
and suffix
--speed-large-files assume large files and many scattered
small changes
--color [=WHEN] colorize the output; WHEN can be 'never',
'always', or 'auto' (the default)
--palette [=PALETTE] specify the colors to use when --color is
active PALETTE is a colon-separated list
terminfo capabilities

 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

 A numeric mode is from one to four octal digits (0-7), derived by


adding up the bits with values 4, 2, and 1. Omitted digits are
assumed to be leading zeros. The first digit selects the set user ID
(4) and set group ID (2) and restricted deletion or sticky (1) attributes.
The second digit selects permissions for the user who owns the file:
read (4), write (2), and execute (1); the third selects permissions for
other users in the file's group, with the same values; and the fourth for
other users not in the file's group, with the same values.
 chmod never changes the permissions of symbolic links; the chmod
system call cannot change their permissions. This is not a problem
since the permissions of symbolic links are never used. However, for
each symbolic link listed on the command line, chmod changes the
permissions of the pointed-to file. In contrast, chmod ignores
symbolic links encountered during recursive directory traversals.

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 :

 This manual page documents the GNU version of chown. chown


changes the user and/or group ownership of each given file. If only an
owner (a username or numeric user ID) is given, that user is made
the owner of each given file, and the files' group is not changed. If the
owner is followed by a colon and a group name (or numeric group
ID), with no spaces between them, the group ownership of the files is
changed as well. If a colon but no group name follows the username,
that user is made the owner of the files and the group of the files is
changed to that user's login group. If the colon and group are given,
but the owner is omitted, only the group of the files is changed; in this
case, chown performs the same function as chgrp. If only a colon is
given, or if the entire operand is empty, neither the owner nor the
group is changed.

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 :

 chgrp [OPTION]... GROUP FILE...


 chgrp [OPTION]... --reference=RFILE FILE...

 DESCRIPTION :

 Change the group of each FILE to GROUP. With --reference, change


the group of each FILE to that of RFILE.

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

-d --date [=STRING] display time described by STRING, not


'now'
--debug annotate the parsed date, and warn about
questionable usage to stderr
-f --file [=DATEFILE] like --date; once for each line of
DATEFILE
-I[FMT] --iso-8601 [=FMT] output date/time in ISO 8601 format.
FMT='date' for date only (the default),
'hours', 'minutes', 'seconds', or 'ns' for
date and time to the indicated precision.
Example: 2006-08-14T02:34:56-06:00
-R --rfc-2822 output date and time in RFC 2822 format.
Example: Mon, 14 Aug 2006 02:34:56 -
0600
--rfc-3339 [=FMT] output date/time in RFC 3339 format.
FMT='date', 'seconds', or 'ns' for date and
time to the indicated precision. Example:
2006-08-14 02:34:56-06:00
-r --reference [=FILE] display the last modification time of FILE
-s --set [=STRING] set time described by STRING
-u --utc, --universal print or set Coordinated Universal Time
(UTC)

 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.

tokens Ignored for backwards compatibility.


cdf Prints details of Compound Document Files.

compress Checks for, and looks inside, compressed


files.
csv Checks Comma Separated Value files.
elf Prints ELF file details, provided soft magic
tests are enabled and the elf magic is found.
json Examines JSON (RFC-7159) files by parsing
them for compliance.

2
Enrollment No : 190410116100 SY IT 3 A

soft Consults magic files.


tar Examines tar files by verifying the checksum
of the 512 byte tar header. Excluding this
test can provide more detailed content
description by using the soft magic method.
text A synonym for ‘ascii’.
--exclude-quiet Like --exclude but ignore tests that file does
not know about. This is intended for
compatilibity with older versions of file.
--extension Print a slash-separated list of valid
extensions for the file type found.
-F --separator [=SEPARATOR] Use the specified string as the separator
between the filename and the file result
returned. Defaults to ‘:’.
-f --file-form [=NAMEFILE] Read the names of the files to be examined
from namefile (one per line) before the
argument list. Either namefile or at least one
filename argument must be present; to test
the standard input, use ‘-’ as a filename
argument. Please note that namefile is
unwrapped and the enclosed filenames are
processed when this option is encountered
and before any further options processing is
done. This allows one to process multiple
lists of files with different command line
arguments on the same file invocation. Thus
if you want to set the delimiter, you need to
do it before you specify the list of files, like:
“-F @ -f namefile”, instead of: “-f namefile -F
@”.
-h --no-dereference option causes symlinks not to be followed
(on systems that support symbolic links).
This is the default if the environment variable
POSIXLY_CORRECT is not defined.

-i --mime Causes the file command to output mime


type strings rather than the more traditional
human readable ones. Thus it may say
‘text/plain; charset=us-ascii’ rather than
“ASCII text”.
--mime-type, Like -i, but print only the specified
--mime-encoding element(s).

2
Enrollment No : 190410116100 SY IT 3 A

-k --keep-going Don't stop at the first match, keep going.


Subsequent matches will be have the string
‘\012- ’ prepended. (If you want a newline,
see the -r option.) The magic pattern with
the highest strength (see the -l option)
comes first.
-l --list Shows a list of patterns and their strength
sorted descending by magic(5) strength
which is used for the matching (see also the
-k option).
-L --dereference option causes symlinks to be followed, as
the like-named option in ls(1) (on systems
that support symbolic links). This is the
default if the environment variable
POSIXLY_CORRECT is defined.

-m --magic-file [=MAGICFILES] Specify an alternate list of files and


directories containing magic. This can be a
single item, or a colon-separated list. If a
compiled magic file is found alongside a file
or directory, it will be used instead.

-N --no-pad Don't pad filenames so that they align in the


output.
-n --no-buffer Force stdout to be flushed after checking
each file. This is only useful if checking a list
of files. It is intended to be used by
programs that want filetype output from a
pipe.
-p --preserve-date On systems that support utime(3) or
utimes(2), attempt to preserve the access
time of files analyzed, to pretend that file
never read them.
-P --parameter Set various parameter limits.
[=NAME-VALUE]
Name Default Explanation
bytes 1048576 max number of bytes to read from file
elf-notes 256 max ELF notes processed
elf-phnum 2048 max ELF program sections processed
elf-shnum 32768 max ELF sections processed
indir 50 recursion limit for indirect magic
name 50 use count limit for name/use magic
regex 8192 length limit for regex searches
-r --raw Don't translate unprintable characters to \
ooo. Normally file translates unprintable
characters to their octal representation.

2
Enrollment No : 190410116100 SY IT 3 A

-s --special-files Normally, file only attempts to read and


determine the type of argument files which
stat(2) reports are ordinary files. This
prevents problems, because reading special
files may have peculiar consequences.
Specifying the -s option causes file to also
read argument files which are block or
character special files. This is useful for
determining the filesystem types of the data
in raw disk partitions, which are block
special files. This option also causes file to
disregard the file size as reported by stat(2)
since on some systems it reports a zero size
for raw disk partitions.
-S --no-sandbox On systems where libseccomp
(https://github.com/seccomp/libseccomp) is
available, the -S flag disables sandboxing
which is enabled by default. This option is
needed for file to execute external
decompressing programs, i.e. when the -z
flag is specified and the built-in
decompressors are not available. On
systems where sandboxing is not available,
this option has no effect.

-z --uncompress Try to look inside compressed files.


-Z --uncompress-noreport Try to look inside compressed files, but
report information about the contents only
not the compression.

 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 :

 head [OPTION]... [FILE]...

 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 :

 tail [OPTION]... [FILE]...

 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

 Mandatory arguments to long options are mandatory for short options


too.

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

-g --general-numeric-sort compare according to general numerical


value
-i --ignore-nonprinting consider only printable characters
-M --month-sort compare (unknown) < 'JAN' < ... < 'DEC'
-h --human-numeric-sort compare human readable numbers (e.g.,
2K 1G)
-n --numeric-sort compare according to string numerical
value
-R --random-sort shuffle, but group identical keys. See
shuf(1)
--random-source [=FILE] get random bytes from FILE
-r --reverse reverse the result of comparisons
--sort [=WORD] sort according to WORD: general-numeric
-g, human-numeric -h, month -M, numeric
-n, random -R, version -V
-V --version-sort natural sort of (version) numbers within
text
--batch-size [=NMERGE] merge at most NMERGE inputs at once;
for more use temp files
-c --check, --check check for sorted input; do not sort
[=DIAGNOSE-FIRST]
-C --check [=QUIET], like -c, but do not report first bad line
--check [=SILENT]
--compress-program compress temporaries with PROG;
[=PROG] decompress them with PROG -d
--debug annotate the part of the line used to sort,
and warn about questionable usage to
stderr
--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
-k --key [=KEYDEF] sort via a key; KEYDEF gives location and
type
-m --merge merge already sorted files; do not sort
-o --output [=FILE] write result to FILE instead of standard
output
-s --stable stabilize sort by disabling last-resort
comparison
-S --buffer-size [=SIZE] use SIZE for main memory buffer
-t --field-separator [=SEP] use SEP instead of non-blank to blank
transition

2
Enrollment No : 190410116100 SY IT 3 A

-T --temporary-directory use DIR for temporaries, not $TMPDIR or


[=DIR] /tmp; multiple options specify multiple
directories
--parallel [=N] change the number of sorts run
concurrently to N
-u --unique with -c, check for strict ordering; without -
c, output only the first of an equal run
-z --zero-terminated line delimiter is NUL, not newline

 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

and find discovers a symbolic link to a subdirectory during its search,


the subdirectory pointed to by the symbolic link will be searched.
 When the -L option is in effect, the -type predicate will always match
against the type of the file that a symbolic link points to rather than
the link itself (unless the symbolic link is broken). Actions that can
cause symbolic links to become broken while find is executing (for
example -delete) can give rise to confusing behaviour. Using -L
causes the -lname and -ilname predicates always to return false.
 -H :-> Do not follow symbolic links, except while processing the
command line arguments. When find examines or prints information
about files, the information used shall be taken from the properties of
the symbolic link itself. The only exception to this behaviour is when a
file specified on the command line is a symbolic link, and the link can
be resolved. For that situation, the information used is taken from
whatever the link points to (that is, the link is followed). The
information about the link itself is used as a fallback if the file pointed
to by the symbolic link cannot be examined. If -H is in effect and one
of the paths specified on the command line is a symbolic link to a
directory, the contents of that directory will be examined (though of
course -maxdepth 0 would prevent this).
 If more than one of -H, -L and -P is specified, each overrides the
others; the last one appearing on the command line takes effect.
Since it is the default, the -P option should be considered to be in
effect unless either -H or -L is specified.
 GNU find frequently stats files during the processing of the command
line itself, before any searching has begun. These options also affect
how those arguments are processed. Specifically, there are a
number of tests that compare files listed on the command line against
a file we are currently considering. In each case, the file specified on
the command line will have been examined and some of its properties
will have been saved. If the named file is in fact a symbolic link, and
the -P option is in effect (or if neither -H nor -L were specified), the
information used for the comparison will be taken from the properties
of the symbolic link. Otherwise, it will be taken from the properties of
the file the link points to. If find cannot follow the link (for example
because it has insufficient privileges or the link points to a non-
existent file) the properties of the link itself will be used.
 When the -H or -L options are in effect, any symbolic links listed
as the argument of -newer will be dereferenced, and the timestamp
will be taken from the file to which the symbolic link points. The same
consideration applies to -newerXY, -anewer and -cnewer.

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

-s --skip-chars [=N] avoid comparing the first N characters


-u --unique only print unique lines
-z --zero-terminated line delimiter is NUL, not newline
-w --check-chars [=N] compare no more than N characters in lines

 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

-p perform history expansion on each ARG and display the result


without storing it in the history list
-s append the ARGs to the history list as a single entry

 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&amp;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&amp;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

-w --word-regexp Select only those lines containing matches


that form whole words. The test is that the
matching substring must either be at the
beginning of the line, or preceded by a
non-word constituent character. Similarly,
it must be either at the end of the line or
followed by a non-word constituent
character. Word-constituent characters
are letters, digits, and the underscore. This
option has no effect if -x is also specified.
-x --line-regexp Select only those matches that exactly
match the whole line. For a regular
expression pattern, this is like
parenthesizing the pattern and then
surrounding it with ^ and $.

-y Obsolete synonym for -i.


-c --count Suppress normal output; instead print a
count of matching lines for each input file.
With the -v, --invert-match option (see
below), count non-matching lines.
--color [=WHEN], Surround the matched (non-empty)
--colour [=WHEN] strings, matching lines, context lines, file
names, line numbers, byte offsets, and
separators (for fields and groups of context
lines) with escape sequences to display
them in color on the terminal. The colors
are defined by the environment variable
GREP_COLORS. The deprecated
environment variable GREP_COLOR is
still supported, but its setting does not
have priority. WHEN is never, always, or
auto.
-L --files-without-match Suppress normal output; instead print the
name of each input file from which no
output would normally have been printed.
The scanning will stop on the first match.
-l --files-with-matches Suppress normal output; instead print the
name of each input file from which output
would normally have been printed. The
scanning will stop on the first match.
-m [=NUM] --max-count [=NUM] Stop reading a file after NUM matching
lines. If the input is standard input from a
regular file, and NUM matching lines are
output, grep ensures that the standard
input is positioned to just after the last
matching line before exiting, regardless of
the presence of trailing context lines. This

2
Enrollment No : 190410116100 SY IT 3 A

enables a calling process to resume a


search. When grep stops after NUM
matching lines, it outputs any trailing
context lines. When the -c or --count
option is also used, grep does not output a
count greater than NUM. When the -v or
--invert-match option is also used, grep
stops after outputting NUM non-matching
lines.
-o --only-matching Print only the matched (non-empty) parts
of a matching line, with each such part on
a separate output line.
-q --quiet, --silent Quiet; do not write anything to standard
output. Exit immediately with zero status if
any match is found, even if an error was
detected. Also see the -s or --no-
messages option.
-s --no-messages Suppress error messages about
nonexistent or unreadable files.
-b --byte-offset Print the 0-based byte offset within the
input file before each line of output. If -o
(--only-matching) is specified, print the
offset of the matching part itself.
-H --with-filename Print the file name for each match. This is
the default when there is more than one
file to search.
-h --no-filename Suppress the prefixing of file names on
output. This is the default when there is
only one file (or only standard input) to
search.
--label [=LABEL] Display input actually coming from
standard input as input coming from file
LABEL. This is especially useful when
implementing tools like zgrep, e.g., gzip -
cd foo.gz | grep --label=foo -H
something. See also the -H option.
-n --line-number Prefix each line of output with the 1-based
line number within its input file.

2
Enrollment No : 190410116100 SY IT 3 A

-T --initial-tab Make sure that the first character of actual


line content lies on a tab stop, so that the
alignment of tabs looks normal. This is
useful with options that prefix their output
to the actual content: -H, -n, and -b. In
order to improve the probability that lines
from a single file will all start at the same
column, this also causes the line number
and byte offset (if present) to be printed in
a minimum size field width.

-u --unix-byte-offsets Report Unix-style byte offsets. This switch


causes grep to report byte offsets as if the
file were a Unix-style text file, i.e., with CR
characters stripped off. This will produce
results identical to running grep on a Unix
machine. This option has no effect unless
-b option is also used; it has no effect on
platforms other than MS-DOS and MS-
Windows.
-z --null Output a zero byte (the ASCII NUL
character) instead of the character that
normally follows a file name. For example,
grep -lZ outputs a zero byte after each file
name instead of the usual newline. This
option makes the output unambiguous,
even in the presence of file names
containing unusual characters like
newlines. This option can be used with
commands like find -print0, perl -0, sort -
z, and xargs -0 to process arbitrary file
names, even those that contain newline
characters.

 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

47) | (pipeline command) :


 The pipe is a command in Linux that lets you use two or more
commands such that output of one command serves as input to the
text.

 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

lines are whitespace padded to have 79 characters. The command


will always put a carriage return and new line at the end of each line.
 Only the superuser can write on the terminals of users who have
chosen to deny messages or are using a program which
automatically denies messages.
 Reading from a file is refused when the invoker is not superuser and
the program is set-user-ID or set-group-ID.

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

-f --force remove existing destination files


-i --interactive prompt whether to remove destinations
-l --logical dereference TARGETs that are symbolic
links
-n --no-dereference treat LINK_NAME as a normal file if it is a
symbolic link to a directory
-P --physical make hard links directly to symbolic links
-r --relative create symbolic links relative to link
location
-s --symbolic make symbolic links instead of hard links
-S --suffix [=SUFFIX] override the usual backup suffix
-t --target-directory specify the DIRECTORY in which to
[=DIRECTORY] create the links
-T --no-target-directory treat LINK_NAME as a normal file always
-v --verbose print name of each linked file

 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 :

echo "Enter Subject - 1 Marks :"


read s1

echo "Enter Subject - 2 Marks :"


read s2

echo "Enter Subject - 3 Marks :"


read s3

total=`expr $s1 + $s2 + $s3`


echo "Total Marks : $total"

per=`expr $total / 3`
echo "Percentage : $per %"

if [ $per -gt 70 ]
then
echo "Distinction Class"

elif [ $per -ge 61 -a $per -le 70 ]


then
echo "First Class"
2
Enrollment No : 190410116100 SY IT 3 A

elif [ $per -ge 51 -a $per -le 60 ]


then
echo "Second Class"

elif [ $per -ge 41 -a $per -le 50 ]


then
echo "Third Class"
else
echo "Fail"

fi

 Output :

b) Write a shell script to find maximum of two number.

 Input :

echo "Enter Number 1 : "

2
Enrollment No : 190410116100 SY IT 3 A

read n1

echo "Enter Number 2 : "


read n2

if [ $n1 -gt $n2 ]


then
echo "$n1 is greater than $n2"
elif [ $n1 -lt $n2 ]
then
echo "$n1 is lesser than $n2"
else
echo "Both numbers are equal"
fi

 Output :

c) Write a shell script to find maximum of three number.

 Input :
echo "Enter Number 1 :"
2
Enrollment No : 190410116100 SY IT 3 A

read n1

echo "Enter Number 2 :"


read n2

echo "Enter Number 3 :"


read n3
if [ $n1 -gt $n2 -a $n1 -gt $n3 ]
then
echo "$n1 is max"

elif [ $n2 -gt $n1 -a $n2 -gt $n3 ]


then
echo "$n2 is max"

elif [ $n3 -gt $n1 -a $n3 -gt $n2 ]


then
echo "$n3 is max"

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

echo "Factorial = $fact"

 Output :

2
Enrollment No : 190410116100 SY IT 3 A

b) Write a shell script to display multiplication table of given number.

 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

c) Write a shell script to find given number is odd or even.

 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

echo "Fibonacci Series :"

for(( i=0; $i < $n; i++ ))

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"

echo "Enter Choice : "


read choice

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 :

echo "Enter String : "


read s

ln=`echo "$s" | wc -c`


ln=`expr $ln - 1`
l=1
2
Enrollment No : 190410116100 SY IT 3 A

while [ $l -le $ln ]


do
rr=`echo $s | cut -c $ln`
ll=`echo $s | cut -c $l`
if [ $rr != $ll ]
then
echo "It is not Palindrome"
exit
fi
ln=`expr $ln - 1`
l=`expr $l + 1`
done
echo "It is Palindrome"

 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 " "

echo "Elements in sorted form "


for ((j=0;j<$#;++j))
do
echo "${arr[$j]}"
done

 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 :

echo "Executable files: "


for file in *
do

2
Enrollment No : 190410116100 SY IT 3 A

if [ -f $file -a -x $file ]
then
echo "$file"
fi
#ls -l $file
done

echo " "


echo "Executable Directories: "
for file in *
do
if [ -d $file -a -w $file ]
then
echo $file
fi
#ls -l $file
done
echo " "
echo "Zero size files: "

for file in *
do
if [ ! -s $file ]
then
echo "$file"
fi
#ls -l $file
done

2
Enrollment No : 190410116100 SY IT 3 A

 Output :

You might also like