SlideShare a Scribd company logo
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 1
Utility Commands:-
1. date: - Date sets a system's date and time.
Syntax: - $ date [OPTION]… [+format]… [ENTER]
Format:
Option Description
%d Day of Month (e.g.01)
%m Month (01..12)
%y Last two digits of year(00..99)
%H Hour(00..23)
%M Minute (00..59)
%S Second (00..60)
%T Time; same as %H/%M/%S.
%D Date; same as %m/%d/%y
%h The abbreviated month name (e.g. Jan)
Example:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 2
2. cal :- Shows the calendar.
Syntax:- $ cal [OPTION] …[ENTER]
Example:
3. type: - It locates the file in the directory.
Syntax: - $ type [FILENAME]… [ENTER]
Example:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 3
4. echo: - Display a line of Text.
Syntax: - $ echo [arg...]… [ENTER]
Example:
5. man: - For showing the manual page of any command.
Syntax: - $ man [name..]… [ENTER]
Example:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 4
6. whatis: -Display one line manual page description.
Syntax:- $ whatis [name]… [ENTER]
Example:
7. printf: - Format and print data.
Syntax: - printf(const char *format, ...);
Formats: Controls the output as in c printf.
Option Description
%s String
%d Decimal
%o Octal
%x Hexadecimal
%f Floating point
n New line
t Horizontal tab
v Vertical tab
Example:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 5
8. pwd: - pwd (Present Working Directory) prints the name of current/working
directory.
Syntax:- $ pwd… [ENTER]
Example:
Directory Command
9. mkdir: - (Make Directory) It is used to create a new directory.
Syntax: - $ mkdir [OPTION]…Directory… [ENTER]
Options:
Option Description
-m (mode) set file mode (as in chmod)
-p (parent) no error if existing, make parent directories as needed
-v (verbose) print a message for each created directory
Example:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 6
10. cd: - To change directory - change the current working directory to a specific Folder.
Syntax:- $ cd [filename] or [path]… [ENTER]
$ cd [OPTION]…Directory … [ENTER]
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 7
Example:
11. rmdir: - remove empty directories
Syntax: - $ rmdir [OPTION]... DIRECTORY… [ENTER]
Options:
Option Description
-p (parent) remove DIRECTORY and its ancestors; e.g., 'rmdir -p a/b/c' is
similar to 'rmdir a/b/c a/b a'
-v (verbose) print a message for each directory processed
Example:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 8
12. ls: - List directory Contents.
Syntax: - $ ls [OPTION]…[FILE]…[ENTER]
Option:
Option Description
-a Do not ignore entries starting with.
-l use a long listing format
-t sort by modification time
-lat Same as -l-a-t
-i print the index number of each file
-R list subdirectories recursively
-s print the allocated size of each file, in blocks
-S sort by file size
-d list directory entries instead of contents, and do not dereference symbolic links
-m fill width with a comma separated list of entries
Example:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 9
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 10
File Command
13. cat: - concatenate files and print on the standard output.
Syntax: - $ cat [OPTION]… [FILE]… [ENTER]
Option:
Option Description
-n number all output lines
-b number nonempty output lines, overrides –n
-T display TAB characters as ^I
-E display $ at end of each line
Example:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 11
14. cp: -copy files and directories
Syntax: - $ cp [OPTION]... SOURCE... DIRECTORY… [ENTER]
Option:
Option Description
-i prompt before overwrite
-R copy directories recursively
-l hard link files instead of copying
-v Explain what is being done.
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 12
Example:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 13
15. rm: - (Remove) remove files or directories.
Syntax: - $ rm [OPTION]... [FILE]... [ENTER]
Option:
Option Description
-i Prompt before every removal.
-R Remove directories and their contents recursively.
-v Explain what is being done.
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 14
Example:
16. mv: - move (rename) files.
Syntax: - $ mv [OPTION]... SOURCE... DIRECTORY… [ENTER]
Option:
Option Description
-i prompt before overwrite
-n do not overwrite an existing file
-f do not prompt before overwriting
-v explain what is being done
Example:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 15
17. touch: -change file timestamps.
Syntax:- $ touch [OPTION]... FILE... [ENTER]
Example:
18. file: - Determine file type.
Syntax: -$ wc [OPTION]... [FILE]... [ENTER]
Example:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 16
19. wc: - print newline, word, and byte counts for each file .
Syntax:- $ wc [OPTION]... [FILE]... [ENTER]
Option:
-c print the byte counts
-m print the character counts
-l print the newline counts
-L print the maximum display width
-w print the word counts
Example:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 17
20. chmod: - change file mode bits.
Syntax: -$ chmod [OPTION]... MODE [, MODE]... FILE... [ENTER]
Where each MODE is of the form [ugoa...][[-+=][rwx...]...]
U User
G Group
O Others
A All
R Read
W Write
X Execute
+ Causes the selected file mode bits to be added to the existing file mode
- Causes the selected file mode bits to be removed to the existing file mode
= Causes the selected file mode bits to be added to the existing file mode.
Example:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 18
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 19
Input-Output Redirection
21. Output Redirection: - Denoted by > .
> (Truncate)
>> (Append)
Syntax: - $ command > Filename… [ENTER]
$ command >> Filename… [ENTER]
Example:
22. Input Redirection: - Denoted by < .
Syntax: - $ command < filename… [ENTER]
Here, File is considered as Standard input.
Example:
23. Error Redirection: - Output channel for error messages is standard error.
Default destination is user’s screen.
Syntax: - $ command > filename… [ENTER]
Example:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 20
Read Statement
24. read: - Used to taking one or more input from user or read from a file descriptor.
Syntax: - $ read varname… [ENTER]
To unset the variable:
$ unset varname… [ENTER]
Example:
Expression Statement
25. expr: - evaluate expressions.
Syntax: - $ expr EXPRESSION… [ENTER]
$ expr OPTION… [ENTER]
EXPRESSION may be:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 21
Expression Description
ARG1 | ARG2 ARG1 if it is neither null nor 0, otherwise ARG2
ARG1 & ARG2 ARG1 if neither argument is null or 0, otherwise 0
ARG1 < ARG2 ARG1 is less than ARG2
ARG1 <= ARG2 ARG1 is less than or equal to ARG2
ARG1 = ARG2 ARG1 is equal to ARG2
ARG1 != ARG2 ARG1 is unequal to ARG2
ARG1 >= ARG2 ARG1 is greater than or equal to ARG2
ARG1 > ARG2 ARG1 is greater than ARG2
ARG1 + ARG2 Arithmetic sum of ARG1 and ARG2
ARG1 - ARG2 Arithmetic difference of ARG1 and ARG2
ARG1 * ARG2 Arithmetic product of ARG1 and ARG2
ARG1 / ARG2 Arithmetic quotient of ARG1 divided by ARG2
ARG1 % ARG2 Arithmetic remainder of ARG1 divided by ARG2
length STRING Length of STRING.
Example:
26. test: - check file types and compare values.
Syntax: -$ test EXPRESSION... [ENTER]
EXPRESSION may be:
Expression Description
INTEGER1 -eq INTEGER2 INTEGER1 is equal to INTEGER2
INTEGER1 -gt INTEGER2 INTEGER1 is greater than INTEGER2
INTEGER1 -le INTEGER2 INTEGER1 is less than or equal to INTEGER2
INTEGER1 -lt INTEGER2 INTEGER1 is less than INTEGER2
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 22
INTEGER1 -ne INTEGER2 INTEGER1 is not equal to INTEGER2
STRING1 = STRING2 the strings are equal
STRING1 != STRING2 the strings are not equal
-n STRING the length of STRING is nonzero
-z STRING the length of STRING is zero
STRING1 = STRING2 the strings are equal
STRING1 != STRING2 the strings are not equal
Example:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 23
Environment Variable
27. PATH: - Display list directories.
Syntax: - $ echo $PATH… [ENTER]
28. HOME: - Users home directory to store files.
Syntax: - $ echo $HOME… [ENTER]
29. PS1: - Display shell prompt in the bourne shell and variant.
Syntax:- $ echo $PS … [ENTER]
30. TEMP: - Path to where process can store files.
Syntax: - $ echo $TEMP… [ENTER]
31. JAVA_HOME: - JDK path.
Syntax: - $ echo $JAVA_HOME… [ENTER]
32. ORACLE_HOME: - Oracle data base installation path.
Syntax: - $ echo $ORACLE_HOME… [ENTER]
33. TZ: - Setting time zone.
Syntax: - $ echo $TZ… [ENTER]
34. USER: - Current logged in user name.
Syntax: - $echo $USER… [ENTER]
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 24
35. SHELL: - The current shell.
Syntax: - $ echo $SHELL… [ENTER]
36. OSTYPE: - Type of operating system.
Syntax: - $ echo $OSTYPE… [ENTER]
37. PWD: - Path to present working directory.
Syntax: - $ echo $PWD… [ENTER]
38. HISTFILE: - The name of file in which command history is saved.
Syntax: - $ echo $HISTFILE… [ENTER]
39. export: - To change the environment variable value.
Syntax: - $ export PS1 = VALUE … [ENTER]
Example:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 25
40. Command Line Arguments: - The command-line arguments $1, $2, $3, ...$9
are positional parameters, with $0 pointing to the actual command, program, shell
script, or function and $1, $2, $3, ...$9 as the arguments to the command.
Example:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 26
Output:
Filter Commands:-
41. Grep: - Print lines matching a pattern.
Syntax:- $ grep [OPTIONS] PATTERN [FILE...]… [ENTER]
Options:
Options Description
--color Display matches in color.
-i Matches either upper or lowercase.
-n Prints the matched line and its line number.
-v Prints all lines that do not match pattern.
-l Prints only the names of files with matching lines.
-L Prints the name of files without match.
-c Prints only the count of matching lines.
-o Display only matched portion not whole matched line.
-b Print the 0-based byte offset within the input file before each line of output.
-f Obtain patterns from FILE, one per line.
Example:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 27
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 28
42. Sed: - Stream editor for filtering and transforming the text.
Syntax: - sed [OPTION]... {Script} [Input-file]... [ENTER]
Option:
Options Description
P Prints the line.
D Deletes the line.
s/pattern1/pattern2/ Substitutes the first occurrence of pattern1 with pattern2
$ Matches the end of lines
-e add the script to the commands to be executed
-n suppress automatic printing of pattern space
G Give one line space between each line.
G;G Two new lines between each line.
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 29
'2,5!d' This deletes everything except starting from 2nd till 5th line
'4,10p' Lines starting from 4th till 10th are printed
Example:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 30
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 31
43. head: - output the first part of files.
Syntax: - head [OPTION]... [FILE]... [ENTER]
Option:
Options Description
-n, --lines=[-]NUM Print the first NUM lines.
-c, --bytes=[-]NUM Print the first NUM bytes of each file.
Example:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 32
44. tail: - output the last part of files.
Syntax: - tail [OPTION]... [FILE]... [ENTER]
Option:
Option Description
-n, --lines=[-]NUM Print the last NUM lines of each file.
-c, --bytes=[-]NUM Print the first NUM bytes of each file.
Example:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 33
45. Pipe: - connect two commands together so that the output from one program
becomes the input of the next program. To make a pipe put a vertical bar ( | ) on the
command line between two commands.
Syntax: - $ command | command … [ENTER]
Example:
46. tee:- Read from standard input and writes to standard output or files.
Syntax: - $ tee [OPTION]… [FILE]… [ENTER]
Option:
Option Description
-a Append to the given files, do not overwrite.
-i Ignore interrupt Signals.
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 34
Example:
47. Command Substitutions: - Used to assign the output of a command to a variable.
Syntax: $ varName=`command`… [ENTER]
Example:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 35
48. Command History: - To display a list of previously entered commands.
Syntax: - $ history… [ENTER]
 To finding the location of history file in your system.
$ echo $HISTFILE
 To show the default history size.
$ echo $HISTSIZE… [ENTER]
 To display only the most recent command.
$ history [n]… [ENTER]
Example:
49. Clobbering:-
 Will prevent > from clobbering by making it issue an error message instead.
Syntax: - $ set –o noclobber… [ENTER]
 Use >| operator to force the file to be overwritten
$ command >| FILENAME… [ENTER]
 To turnoff noclobber
$ set +o noclobber… [ENTER]
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 36
Example:
50. noglob:- It disables wild card characters *,?,[,],~ in user shell.
Syntax: -
 To stop wild card characters permanently:
$ set -o noglob… [ENTER]
 To unset the noglob:
$ set +o noglob… [ENTER]
51. pushd and popd: -
Syntax: -
 For pushd:
$ pushd [DIRECTORY PATH]… [ENTER]
 For popd:
$ popd… [ENTER]
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 37
Example:
52. Process Priority:-
 Checking the priority of running process.
$ top.. [ENTER]
Or
$ ps –eo [FIELDS/COLUMNS]
FIELDS/COLUMNS:
PID Process Id.
USER User Name.
PR Priority
NI Nice value.
VIRT Virtual memory Size.
RES Resident Memory size(KiB)
SHR Shared memory size.
S Process status.
%CPU CPU usage.
%MEM Memory usage.
TIME+ CPU Time. Hundredths
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 38
Command Command name or command line.
Example:
To set the priority on new process:
$ nice –n [NICE VALUE][COMMAND]… [ENTER]
To setting priority on existing process:
$ renice [nice value] –p [process id]… [ENTER]
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 39
SHELL SCRIPTING
1. Write a shell script for addition, subtraction, multiplication, division, modulo
division?
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 40
2. Write a Linux shell script to check the given year is leap year?
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 41
3. Write a Linux shell script to check given number is prime or not?
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 42
4. Write a Linux shell script for Fibonacci series?
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 43
5. Write a Linux shell script to calculate factorial of given number?
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 44
6. Write a Linux shell script for Armstrong number?
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 45
7. Write a Linux shell script to check largest no of three numbers?
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 46
8. Write a shell script to see date, time, username, current directory?
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 47
9. Write a Linux shell script to swapping variable?
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 48
10. Write a Linux shell script to check given no odd or even?
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 49
11. Write shell script to find multiplication table using for loop?
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 50
12. Write a Linux shell script to print employee payroll (basic, DA, HRA, PF, Gross
salary, Net Salary)?
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 51
13. Write a Linux shell script to perform all arithmetic operation using command
line argument?
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 52
14. Write a shell script to accept character and check for following?
 If user enter character (A-Z) then show upper case letter.
 If user enter character (a-z) then show lower case letter.
 If user enters digital no (0-9) then show digital number.
 *, $, #, @ show its special character.
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 53
15. Write a Linux shell script show various system configurations?
 Currently log user and His/her login name.
 Your current shell.
 Your current directory.
 Your operating system type.
 Show mouse setting.
 Show keyboard
 Show network setting.
 Show Path
 currently logged number of users
Program:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 54
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 55
16. Write a shell script to check given name is a file or a directory or special file or
not?
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 56
17. Write a shell script to determine whether given file exist or not, existing file
name supplied by command line argument also check for sufficient no of
command line argument?
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 57
18. Write shell script to copy the content is one file to another file?
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 58
19. Write a shell script to print addition of given of all digits?
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 59
20. Write a shell script to search element present in list or not. (Binary & Linear
Search).
Program: Binary Search
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 60
Output:
Linear Search
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 61
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 62
21. Write a shell script for bubble & selection sort.
Program: Bubble sort
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 63
Selection Sort:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 64
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 65
22. Write a Linux shell script to sort the given no in ascending or descending orders?
Program:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 66
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 67
23. Write a Linux shell script to implement read, write and execute permission?
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 68
24. Write a Linux shell script to print the following pattern?
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 69
25. Write a Linux script to print the following pattern using for loop?
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 70
26. Write a Linux shell script to implement break & continue statement?
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 71
27. Write a Linux shell script to calculate area of circle & rectangle?
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 72
28. Write a Linux shell script to count no of file in directory?
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 73
29. Write a shell script to generate all combination of 1, 2 and 3.
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 74
30. Write a shell script to check given string or number is palindrome or not?
Program: Number
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 75
String:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 76
31. Write a Linux shell script to implement create () system calls?
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 77
32. Write a Linux shell script to implement Open () system calls?
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 78
33. Write a Linux shell script to implement Open (), read (), write () system calls?
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 79
34. Write a shell script which receives two file names as argument. It checks
whether two file contents are same or not. If they are same then second file is
deleted.
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 80
35. Write a shell script for decimal to binary conversion?
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 81
36. Execute any 5 file handling commands with required options on the terminal.
1) Displaying the file: - Displays the file on standard output.
Syntax: - $ cat filename… [ENTER]
Example:
Concatenates the first two files and places the result on the third, overwriting the current
contents of file3.
Syntax: - $ cat file1 file2 > file3.. [ENTER]
Example:
2) Copying File: - copy files and directories
Syntax: - $ cp [OPTION]... SOURCE... DIRECTORY… [ENTER]
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 82
Example:
3) Moving a File: - Move file command (which essentially renames a file) is mv .
Syntax: - $ mv [OPTION]... SOURCE... DIRECTORY… [ENTER]
Example:
4) Deleting a File: - Remove files.
Syntax: - $ rm [OPTION]... [FILE]... [ENTER]
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 83
Example:
5) Searching: - searches the files for a pattern specified by a limited regular
expression.
Syntax: - $ grep [OPTIONS] PATTERN [FILE...]… [ENTER]
Example:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 84
37. Create an awk program to calculate to check even or odd number.
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 85
38. Create an awk program to calculate gross salary from employee database file.
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 86
39. Create an awk program to provide an increment of 10%on the salary on the employee
database file containing 'salary' field.
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 87
40. Create sed script file to make following replacement on student database file:
 Name- John as Joney
 Rollno- 101 as 110
 Percentage- 97 as 78
 Address- Raipur as Durg
Program:
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 88
41. Create a sed script file to perform following operation on student database:
 Insertion.
 Append
 Deletion
Program:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 89
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 90
42. Write a linux shell script to implement system call that will check for disk
appearance of child and exit return its p_id , modify its various used and keep
child process.
Program:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 91
Output:
Unix/Linux MCA-IV
N i k i t a K e s h a r w a n i Page 92
43. Write a linux shell script to implement system call signal () pass one argument
that will contain signal () and if it is valid then display signal flag otherwise error
will be generated.
Program:
Output:

More Related Content

What's hot (19)

PPTX
Basic unix commands
swtjerin4u
 
PDF
Unit 7 standard i o
root_fibo
 
PPT
Bash Programming
Kiplangat Chelule
 
PPT
Shell Scripts
Dr.Ravi
 
RTF
Unix lab manual
Chaitanya Kn
 
PDF
Unix 1st sem lab programs a - VTU Karnataka
iCreateWorld
 
PDF
21bUc8YeDzZpE
aniruddh Tyagi
 
PDF
CLI, the other SAPI phpnw11
Combell NV
 
PDF
Basic unix commands
Nomura Japanese Investment Bank
 
TXT
Mkscript sh
Ben Pope
 
PPTX
Pipes and filters
bhatvijetha
 
DOCX
32 shell-programming
kayalkarnan
 
PDF
Basic linux commands
Harikrishnan Ramakrishnan
 
PPT
Gnome terminal basics
Kamrul Hasan
 
TXT
Unix3
Krishna Prasad
 
PPT
Talk Unix Shell Script
Dr.Ravi
 
PDF
Unix command line concepts
Artem Nagornyi
 
KEY
Tres Gemas De Ruby
Leonardo Soto
 
Basic unix commands
swtjerin4u
 
Unit 7 standard i o
root_fibo
 
Bash Programming
Kiplangat Chelule
 
Shell Scripts
Dr.Ravi
 
Unix lab manual
Chaitanya Kn
 
Unix 1st sem lab programs a - VTU Karnataka
iCreateWorld
 
21bUc8YeDzZpE
aniruddh Tyagi
 
CLI, the other SAPI phpnw11
Combell NV
 
Basic unix commands
Nomura Japanese Investment Bank
 
Mkscript sh
Ben Pope
 
Pipes and filters
bhatvijetha
 
32 shell-programming
kayalkarnan
 
Basic linux commands
Harikrishnan Ramakrishnan
 
Gnome terminal basics
Kamrul Hasan
 
Talk Unix Shell Script
Dr.Ravi
 
Unix command line concepts
Artem Nagornyi
 
Tres Gemas De Ruby
Leonardo Soto
 

Similar to Linux/Unix Commands (20)

PDF
Linux file commands and shell scripts
PrashantTechment
 
PPTX
AARAV NAYAN OPERATING SYSTEM LABORATORY PCA
AaravNayan
 
PPTX
various shell commands in unix operating system.pptx
ssuserc26f8f
 
PPTX
2. UNIX OS System Architecture easy.pptx
Priyadarshini648418
 
ODP
Linux
merlin deepika
 
ODP
Linux
merlin deepika
 
PPT
Linux
HAINIRMALRAJ
 
PPT
Linux day 1
sumairdotcom
 
PPT
PowerPoint_merge.ppt on unix programming
Priyadarshini648418
 
PPT
Basic Linux day 1
Saikumar Daram
 
PPT
Shell_Scripting.ppt
KiranMantri
 
PDF
Unleash your inner console cowboy
Kenneth Geisshirt
 
PPSX
Unix environment [autosaved]
Er Mittinpreet Singh
 
PPT
Linux ppt
Sanmuga Nathan
 
PPTX
linux chapter 5.pptx lesson About introduction to linux
zakiaxmed534
 
PPT
Linux operating system by Quontra Solutions
QUONTRASOLUTIONS
 
PDF
Unleash your inner console cowboy
Kenneth Geisshirt
 
Linux file commands and shell scripts
PrashantTechment
 
AARAV NAYAN OPERATING SYSTEM LABORATORY PCA
AaravNayan
 
various shell commands in unix operating system.pptx
ssuserc26f8f
 
2. UNIX OS System Architecture easy.pptx
Priyadarshini648418
 
Linux day 1
sumairdotcom
 
PowerPoint_merge.ppt on unix programming
Priyadarshini648418
 
Basic Linux day 1
Saikumar Daram
 
Shell_Scripting.ppt
KiranMantri
 
Unleash your inner console cowboy
Kenneth Geisshirt
 
Unix environment [autosaved]
Er Mittinpreet Singh
 
Linux ppt
Sanmuga Nathan
 
linux chapter 5.pptx lesson About introduction to linux
zakiaxmed534
 
Linux operating system by Quontra Solutions
QUONTRASOLUTIONS
 
Unleash your inner console cowboy
Kenneth Geisshirt
 
Ad

Recently uploaded (20)

PDF
Understanding The True Cost of DynamoDB Webinar
ScyllaDB
 
PDF
Pipeline Industry IoT - Real Time Data Monitoring
Safe Software
 
PDF
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
PPTX
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
PPSX
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
PDF
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
PDF
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
PDF
Why aren't you using FME Flow's CPU Time?
Safe Software
 
PDF
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
PDF
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
PPTX
Practical Applications of AI in Local Government
OnBoard
 
PDF
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
PPTX
Reimaginando la Ciberdefensa: De Copilots a Redes de Agentes
Cristian Garcia G.
 
PDF
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
PDF
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
PDF
How to Comply With Saudi Arabia’s National Cybersecurity Regulations.pdf
Bluechip Advanced Technologies
 
PDF
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
DOCX
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
PDF
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
Understanding The True Cost of DynamoDB Webinar
ScyllaDB
 
Pipeline Industry IoT - Real Time Data Monitoring
Safe Software
 
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
Why aren't you using FME Flow's CPU Time?
Safe Software
 
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
Practical Applications of AI in Local Government
OnBoard
 
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
Reimaginando la Ciberdefensa: De Copilots a Redes de Agentes
Cristian Garcia G.
 
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
How to Comply With Saudi Arabia’s National Cybersecurity Regulations.pdf
Bluechip Advanced Technologies
 
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
Ad

Linux/Unix Commands

  • 1. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 1 Utility Commands:- 1. date: - Date sets a system's date and time. Syntax: - $ date [OPTION]… [+format]… [ENTER] Format: Option Description %d Day of Month (e.g.01) %m Month (01..12) %y Last two digits of year(00..99) %H Hour(00..23) %M Minute (00..59) %S Second (00..60) %T Time; same as %H/%M/%S. %D Date; same as %m/%d/%y %h The abbreviated month name (e.g. Jan) Example:
  • 2. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 2 2. cal :- Shows the calendar. Syntax:- $ cal [OPTION] …[ENTER] Example: 3. type: - It locates the file in the directory. Syntax: - $ type [FILENAME]… [ENTER] Example:
  • 3. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 3 4. echo: - Display a line of Text. Syntax: - $ echo [arg...]… [ENTER] Example: 5. man: - For showing the manual page of any command. Syntax: - $ man [name..]… [ENTER] Example:
  • 4. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 4 6. whatis: -Display one line manual page description. Syntax:- $ whatis [name]… [ENTER] Example: 7. printf: - Format and print data. Syntax: - printf(const char *format, ...); Formats: Controls the output as in c printf. Option Description %s String %d Decimal %o Octal %x Hexadecimal %f Floating point n New line t Horizontal tab v Vertical tab Example:
  • 5. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 5 8. pwd: - pwd (Present Working Directory) prints the name of current/working directory. Syntax:- $ pwd… [ENTER] Example: Directory Command 9. mkdir: - (Make Directory) It is used to create a new directory. Syntax: - $ mkdir [OPTION]…Directory… [ENTER] Options: Option Description -m (mode) set file mode (as in chmod) -p (parent) no error if existing, make parent directories as needed -v (verbose) print a message for each created directory Example:
  • 6. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 6 10. cd: - To change directory - change the current working directory to a specific Folder. Syntax:- $ cd [filename] or [path]… [ENTER] $ cd [OPTION]…Directory … [ENTER]
  • 7. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 7 Example: 11. rmdir: - remove empty directories Syntax: - $ rmdir [OPTION]... DIRECTORY… [ENTER] Options: Option Description -p (parent) remove DIRECTORY and its ancestors; e.g., 'rmdir -p a/b/c' is similar to 'rmdir a/b/c a/b a' -v (verbose) print a message for each directory processed Example:
  • 8. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 8 12. ls: - List directory Contents. Syntax: - $ ls [OPTION]…[FILE]…[ENTER] Option: Option Description -a Do not ignore entries starting with. -l use a long listing format -t sort by modification time -lat Same as -l-a-t -i print the index number of each file -R list subdirectories recursively -s print the allocated size of each file, in blocks -S sort by file size -d list directory entries instead of contents, and do not dereference symbolic links -m fill width with a comma separated list of entries Example:
  • 9. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 9
  • 10. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 10 File Command 13. cat: - concatenate files and print on the standard output. Syntax: - $ cat [OPTION]… [FILE]… [ENTER] Option: Option Description -n number all output lines -b number nonempty output lines, overrides –n -T display TAB characters as ^I -E display $ at end of each line Example:
  • 11. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 11 14. cp: -copy files and directories Syntax: - $ cp [OPTION]... SOURCE... DIRECTORY… [ENTER] Option: Option Description -i prompt before overwrite -R copy directories recursively -l hard link files instead of copying -v Explain what is being done.
  • 12. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 12 Example:
  • 13. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 13 15. rm: - (Remove) remove files or directories. Syntax: - $ rm [OPTION]... [FILE]... [ENTER] Option: Option Description -i Prompt before every removal. -R Remove directories and their contents recursively. -v Explain what is being done.
  • 14. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 14 Example: 16. mv: - move (rename) files. Syntax: - $ mv [OPTION]... SOURCE... DIRECTORY… [ENTER] Option: Option Description -i prompt before overwrite -n do not overwrite an existing file -f do not prompt before overwriting -v explain what is being done Example:
  • 15. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 15 17. touch: -change file timestamps. Syntax:- $ touch [OPTION]... FILE... [ENTER] Example: 18. file: - Determine file type. Syntax: -$ wc [OPTION]... [FILE]... [ENTER] Example:
  • 16. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 16 19. wc: - print newline, word, and byte counts for each file . Syntax:- $ wc [OPTION]... [FILE]... [ENTER] Option: -c print the byte counts -m print the character counts -l print the newline counts -L print the maximum display width -w print the word counts Example:
  • 17. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 17 20. chmod: - change file mode bits. Syntax: -$ chmod [OPTION]... MODE [, MODE]... FILE... [ENTER] Where each MODE is of the form [ugoa...][[-+=][rwx...]...] U User G Group O Others A All R Read W Write X Execute + Causes the selected file mode bits to be added to the existing file mode - Causes the selected file mode bits to be removed to the existing file mode = Causes the selected file mode bits to be added to the existing file mode. Example:
  • 18. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 18
  • 19. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 19 Input-Output Redirection 21. Output Redirection: - Denoted by > . > (Truncate) >> (Append) Syntax: - $ command > Filename… [ENTER] $ command >> Filename… [ENTER] Example: 22. Input Redirection: - Denoted by < . Syntax: - $ command < filename… [ENTER] Here, File is considered as Standard input. Example: 23. Error Redirection: - Output channel for error messages is standard error. Default destination is user’s screen. Syntax: - $ command > filename… [ENTER] Example:
  • 20. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 20 Read Statement 24. read: - Used to taking one or more input from user or read from a file descriptor. Syntax: - $ read varname… [ENTER] To unset the variable: $ unset varname… [ENTER] Example: Expression Statement 25. expr: - evaluate expressions. Syntax: - $ expr EXPRESSION… [ENTER] $ expr OPTION… [ENTER] EXPRESSION may be:
  • 21. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 21 Expression Description ARG1 | ARG2 ARG1 if it is neither null nor 0, otherwise ARG2 ARG1 & ARG2 ARG1 if neither argument is null or 0, otherwise 0 ARG1 < ARG2 ARG1 is less than ARG2 ARG1 <= ARG2 ARG1 is less than or equal to ARG2 ARG1 = ARG2 ARG1 is equal to ARG2 ARG1 != ARG2 ARG1 is unequal to ARG2 ARG1 >= ARG2 ARG1 is greater than or equal to ARG2 ARG1 > ARG2 ARG1 is greater than ARG2 ARG1 + ARG2 Arithmetic sum of ARG1 and ARG2 ARG1 - ARG2 Arithmetic difference of ARG1 and ARG2 ARG1 * ARG2 Arithmetic product of ARG1 and ARG2 ARG1 / ARG2 Arithmetic quotient of ARG1 divided by ARG2 ARG1 % ARG2 Arithmetic remainder of ARG1 divided by ARG2 length STRING Length of STRING. Example: 26. test: - check file types and compare values. Syntax: -$ test EXPRESSION... [ENTER] EXPRESSION may be: Expression Description INTEGER1 -eq INTEGER2 INTEGER1 is equal to INTEGER2 INTEGER1 -gt INTEGER2 INTEGER1 is greater than INTEGER2 INTEGER1 -le INTEGER2 INTEGER1 is less than or equal to INTEGER2 INTEGER1 -lt INTEGER2 INTEGER1 is less than INTEGER2
  • 22. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 22 INTEGER1 -ne INTEGER2 INTEGER1 is not equal to INTEGER2 STRING1 = STRING2 the strings are equal STRING1 != STRING2 the strings are not equal -n STRING the length of STRING is nonzero -z STRING the length of STRING is zero STRING1 = STRING2 the strings are equal STRING1 != STRING2 the strings are not equal Example:
  • 23. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 23 Environment Variable 27. PATH: - Display list directories. Syntax: - $ echo $PATH… [ENTER] 28. HOME: - Users home directory to store files. Syntax: - $ echo $HOME… [ENTER] 29. PS1: - Display shell prompt in the bourne shell and variant. Syntax:- $ echo $PS … [ENTER] 30. TEMP: - Path to where process can store files. Syntax: - $ echo $TEMP… [ENTER] 31. JAVA_HOME: - JDK path. Syntax: - $ echo $JAVA_HOME… [ENTER] 32. ORACLE_HOME: - Oracle data base installation path. Syntax: - $ echo $ORACLE_HOME… [ENTER] 33. TZ: - Setting time zone. Syntax: - $ echo $TZ… [ENTER] 34. USER: - Current logged in user name. Syntax: - $echo $USER… [ENTER]
  • 24. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 24 35. SHELL: - The current shell. Syntax: - $ echo $SHELL… [ENTER] 36. OSTYPE: - Type of operating system. Syntax: - $ echo $OSTYPE… [ENTER] 37. PWD: - Path to present working directory. Syntax: - $ echo $PWD… [ENTER] 38. HISTFILE: - The name of file in which command history is saved. Syntax: - $ echo $HISTFILE… [ENTER] 39. export: - To change the environment variable value. Syntax: - $ export PS1 = VALUE … [ENTER] Example:
  • 25. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 25 40. Command Line Arguments: - The command-line arguments $1, $2, $3, ...$9 are positional parameters, with $0 pointing to the actual command, program, shell script, or function and $1, $2, $3, ...$9 as the arguments to the command. Example:
  • 26. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 26 Output: Filter Commands:- 41. Grep: - Print lines matching a pattern. Syntax:- $ grep [OPTIONS] PATTERN [FILE...]… [ENTER] Options: Options Description --color Display matches in color. -i Matches either upper or lowercase. -n Prints the matched line and its line number. -v Prints all lines that do not match pattern. -l Prints only the names of files with matching lines. -L Prints the name of files without match. -c Prints only the count of matching lines. -o Display only matched portion not whole matched line. -b Print the 0-based byte offset within the input file before each line of output. -f Obtain patterns from FILE, one per line. Example:
  • 27. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 27
  • 28. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 28 42. Sed: - Stream editor for filtering and transforming the text. Syntax: - sed [OPTION]... {Script} [Input-file]... [ENTER] Option: Options Description P Prints the line. D Deletes the line. s/pattern1/pattern2/ Substitutes the first occurrence of pattern1 with pattern2 $ Matches the end of lines -e add the script to the commands to be executed -n suppress automatic printing of pattern space G Give one line space between each line. G;G Two new lines between each line.
  • 29. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 29 '2,5!d' This deletes everything except starting from 2nd till 5th line '4,10p' Lines starting from 4th till 10th are printed Example:
  • 30. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 30
  • 31. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 31 43. head: - output the first part of files. Syntax: - head [OPTION]... [FILE]... [ENTER] Option: Options Description -n, --lines=[-]NUM Print the first NUM lines. -c, --bytes=[-]NUM Print the first NUM bytes of each file. Example:
  • 32. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 32 44. tail: - output the last part of files. Syntax: - tail [OPTION]... [FILE]... [ENTER] Option: Option Description -n, --lines=[-]NUM Print the last NUM lines of each file. -c, --bytes=[-]NUM Print the first NUM bytes of each file. Example:
  • 33. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 33 45. Pipe: - connect two commands together so that the output from one program becomes the input of the next program. To make a pipe put a vertical bar ( | ) on the command line between two commands. Syntax: - $ command | command … [ENTER] Example: 46. tee:- Read from standard input and writes to standard output or files. Syntax: - $ tee [OPTION]… [FILE]… [ENTER] Option: Option Description -a Append to the given files, do not overwrite. -i Ignore interrupt Signals.
  • 34. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 34 Example: 47. Command Substitutions: - Used to assign the output of a command to a variable. Syntax: $ varName=`command`… [ENTER] Example:
  • 35. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 35 48. Command History: - To display a list of previously entered commands. Syntax: - $ history… [ENTER]  To finding the location of history file in your system. $ echo $HISTFILE  To show the default history size. $ echo $HISTSIZE… [ENTER]  To display only the most recent command. $ history [n]… [ENTER] Example: 49. Clobbering:-  Will prevent > from clobbering by making it issue an error message instead. Syntax: - $ set –o noclobber… [ENTER]  Use >| operator to force the file to be overwritten $ command >| FILENAME… [ENTER]  To turnoff noclobber $ set +o noclobber… [ENTER]
  • 36. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 36 Example: 50. noglob:- It disables wild card characters *,?,[,],~ in user shell. Syntax: -  To stop wild card characters permanently: $ set -o noglob… [ENTER]  To unset the noglob: $ set +o noglob… [ENTER] 51. pushd and popd: - Syntax: -  For pushd: $ pushd [DIRECTORY PATH]… [ENTER]  For popd: $ popd… [ENTER]
  • 37. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 37 Example: 52. Process Priority:-  Checking the priority of running process. $ top.. [ENTER] Or $ ps –eo [FIELDS/COLUMNS] FIELDS/COLUMNS: PID Process Id. USER User Name. PR Priority NI Nice value. VIRT Virtual memory Size. RES Resident Memory size(KiB) SHR Shared memory size. S Process status. %CPU CPU usage. %MEM Memory usage. TIME+ CPU Time. Hundredths
  • 38. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 38 Command Command name or command line. Example: To set the priority on new process: $ nice –n [NICE VALUE][COMMAND]… [ENTER] To setting priority on existing process: $ renice [nice value] –p [process id]… [ENTER]
  • 39. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 39 SHELL SCRIPTING 1. Write a shell script for addition, subtraction, multiplication, division, modulo division? Program: Output:
  • 40. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 40 2. Write a Linux shell script to check the given year is leap year? Program: Output:
  • 41. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 41 3. Write a Linux shell script to check given number is prime or not? Program: Output:
  • 42. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 42 4. Write a Linux shell script for Fibonacci series? Program: Output:
  • 43. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 43 5. Write a Linux shell script to calculate factorial of given number? Program: Output:
  • 44. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 44 6. Write a Linux shell script for Armstrong number? Program: Output:
  • 45. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 45 7. Write a Linux shell script to check largest no of three numbers? Program: Output:
  • 46. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 46 8. Write a shell script to see date, time, username, current directory? Program: Output:
  • 47. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 47 9. Write a Linux shell script to swapping variable? Program: Output:
  • 48. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 48 10. Write a Linux shell script to check given no odd or even? Program: Output:
  • 49. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 49 11. Write shell script to find multiplication table using for loop? Program: Output:
  • 50. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 50 12. Write a Linux shell script to print employee payroll (basic, DA, HRA, PF, Gross salary, Net Salary)? Program: Output:
  • 51. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 51 13. Write a Linux shell script to perform all arithmetic operation using command line argument? Program: Output:
  • 52. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 52 14. Write a shell script to accept character and check for following?  If user enter character (A-Z) then show upper case letter.  If user enter character (a-z) then show lower case letter.  If user enters digital no (0-9) then show digital number.  *, $, #, @ show its special character. Program: Output:
  • 53. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 53 15. Write a Linux shell script show various system configurations?  Currently log user and His/her login name.  Your current shell.  Your current directory.  Your operating system type.  Show mouse setting.  Show keyboard  Show network setting.  Show Path  currently logged number of users Program:
  • 54. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 54 Output:
  • 55. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 55 16. Write a shell script to check given name is a file or a directory or special file or not? Program: Output:
  • 56. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 56 17. Write a shell script to determine whether given file exist or not, existing file name supplied by command line argument also check for sufficient no of command line argument? Program: Output:
  • 57. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 57 18. Write shell script to copy the content is one file to another file? Program: Output:
  • 58. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 58 19. Write a shell script to print addition of given of all digits? Program: Output:
  • 59. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 59 20. Write a shell script to search element present in list or not. (Binary & Linear Search). Program: Binary Search
  • 60. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 60 Output: Linear Search
  • 61. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 61 Output:
  • 62. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 62 21. Write a shell script for bubble & selection sort. Program: Bubble sort Output:
  • 63. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 63 Selection Sort:
  • 64. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 64 Output:
  • 65. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 65 22. Write a Linux shell script to sort the given no in ascending or descending orders? Program:
  • 66. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 66 Output:
  • 67. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 67 23. Write a Linux shell script to implement read, write and execute permission? Program: Output:
  • 68. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 68 24. Write a Linux shell script to print the following pattern? 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 Program: Output:
  • 69. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 69 25. Write a Linux script to print the following pattern using for loop? * * * * * * * * * * * * * * * * * * * * * * * * * Program: Output:
  • 70. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 70 26. Write a Linux shell script to implement break & continue statement? Program: Output:
  • 71. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 71 27. Write a Linux shell script to calculate area of circle & rectangle? Program: Output:
  • 72. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 72 28. Write a Linux shell script to count no of file in directory? Program: Output:
  • 73. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 73 29. Write a shell script to generate all combination of 1, 2 and 3. Program: Output:
  • 74. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 74 30. Write a shell script to check given string or number is palindrome or not? Program: Number Output:
  • 75. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 75 String: Output:
  • 76. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 76 31. Write a Linux shell script to implement create () system calls? Program: Output:
  • 77. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 77 32. Write a Linux shell script to implement Open () system calls? Program: Output:
  • 78. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 78 33. Write a Linux shell script to implement Open (), read (), write () system calls? Program: Output:
  • 79. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 79 34. Write a shell script which receives two file names as argument. It checks whether two file contents are same or not. If they are same then second file is deleted. Program: Output:
  • 80. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 80 35. Write a shell script for decimal to binary conversion? Program: Output:
  • 81. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 81 36. Execute any 5 file handling commands with required options on the terminal. 1) Displaying the file: - Displays the file on standard output. Syntax: - $ cat filename… [ENTER] Example: Concatenates the first two files and places the result on the third, overwriting the current contents of file3. Syntax: - $ cat file1 file2 > file3.. [ENTER] Example: 2) Copying File: - copy files and directories Syntax: - $ cp [OPTION]... SOURCE... DIRECTORY… [ENTER]
  • 82. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 82 Example: 3) Moving a File: - Move file command (which essentially renames a file) is mv . Syntax: - $ mv [OPTION]... SOURCE... DIRECTORY… [ENTER] Example: 4) Deleting a File: - Remove files. Syntax: - $ rm [OPTION]... [FILE]... [ENTER]
  • 83. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 83 Example: 5) Searching: - searches the files for a pattern specified by a limited regular expression. Syntax: - $ grep [OPTIONS] PATTERN [FILE...]… [ENTER] Example:
  • 84. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 84 37. Create an awk program to calculate to check even or odd number. Program: Output:
  • 85. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 85 38. Create an awk program to calculate gross salary from employee database file. Program: Output:
  • 86. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 86 39. Create an awk program to provide an increment of 10%on the salary on the employee database file containing 'salary' field. Program: Output:
  • 87. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 87 40. Create sed script file to make following replacement on student database file:  Name- John as Joney  Rollno- 101 as 110  Percentage- 97 as 78  Address- Raipur as Durg Program: Output:
  • 88. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 88 41. Create a sed script file to perform following operation on student database:  Insertion.  Append  Deletion Program:
  • 89. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 89 Output:
  • 90. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 90 42. Write a linux shell script to implement system call that will check for disk appearance of child and exit return its p_id , modify its various used and keep child process. Program:
  • 91. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 91 Output:
  • 92. Unix/Linux MCA-IV N i k i t a K e s h a r w a n i Page 92 43. Write a linux shell script to implement system call signal () pass one argument that will contain signal () and if it is valid then display signal flag otherwise error will be generated. Program: Output: