Sie sind auf Seite 1von 7

INDEX

No. SCRIPTS Page No.

1 Write a shell script to print the users logged in, the current 01
date and the calendar for the year 2010.
2 Write a shell script to check the present working directory, 03
then make a directory on that location, then create 3 files in it
and give executable permissions to them.
3 Write a shell script to take input for name, course and 05
university and print it in the format – I [name] study in
[course] from [university].
4 Write a shell script which creates one hard link and two soft 06
links of a file.

5 Write a shell script that accepts two filenames and your script 08
should copy file1 to file2 and display both the files. (take
input from keyboard and command line both).
6 Write a shell script that accepts four filenames f1, f2, f3 and 10
f4 and display them in the order f3, f1, f4 and f2. ( take input
from keyboard and command line both).
7 Write a shell script that accepts input as 1, 2, 3, 4, and 5 and 12
display in the order 5, 3, 4, 2, 1.
8 Write a shell script that should accept the output of the 13
current date and print the output in the form – 2009 Oct Tue.
9 Write a shell script that will display the files of the current 14
directory and number of files through positional arguments.

10 Write a shell script using if, copy source to target, if it copies 15


then echo copy process successful else echo unable to copy.
11 Write a shell script that will accept a number and then check 16
if number is less than 10. Display the results accordingly.

12 In a company, an employee is paid as under: 17


If Basic Salary<1500, then hra=10% of basic and da=90%
of Basic.
If Basic Salary>=1500, then hra=500, da=98% of Basic.
If the employee’s basic salary is entered through the
keyboard, then write a shell script to find the employee’s
gross salary.
13 Write a shell script where distance between two cities is 18
entered from keyboard in kms and then print that distance in
meters and cms.
14 Write a shell script that perform all the mathematical 19
operations on two numbers. (take input from keyboard and
command line both).
15 Write a shell script and check whether the number is even or 21
odd.
16 Write a shell script which displays the result of student as 22
follows:
If %age is less then 40 then FAIL.
If %age is 40-50 then Third Division.
If %age is 50-60 then Second Division.
If %age is 60-575 then First Division,
If above 75 then Distinction.
17 Write a shell script which accepts the age of a person and 24
checks:
If age is less than 10 yrs then is not allowed.
If age is 10-18 then allowed to swim in junior pool.
If age >18 then senior pool.
18 Write a shell script that accepts a year and check whether it 25
is a leap year or not.
19 Write a shell script which calculate area and perimeter of a 26
rectangle when length and breadth are entered into through
keyboard and through command line.
20 Write a shell script which calculate sum of digits of a five- 27
digit number and also checks whether the number is a
palindrome or not.
21 Make a menu driven shell script with 29
Option 1: Creates a dir d1/d2/d3 where all dir doesn’t
exist.
Option 2: Display some file f4 in the current dir.
Option 3: Check all the users who have logged in.

22 Make a menu driven shell script with 31


Option 1: Check read permission. If it is there then
display the file, if not then give the read permission.
Option 2: Check write permission. If it is there then
append the file, if not then give the write permission.
Option 3: Check execute permission. If it is there then
display the file, if not then say it is a text file.
23 Write a shell script t check whether a file entered from 33
command line is an ordinary file or directory. If it is a dir,
then check the required permissions and create a dir in it,
and in that sub-dir, create a file. If it is a file, then append the
file after checking the permissions.
24 Write a shell script that uses for loop to display the names of 35
files in the current directory which are only directory files.
25 Write a shell script to check the count of total number 36
of arguments entered if number of arguments is less
than or equal to 5, then echo your name else echo error
message, ie, invalid number of arguments. (Use while loop)
26 Write a shell script where day(In Capitals) is entered 37
in the command line. Check the string and display:
a) If it is MON display Unix test,
If it is TUE display Computer Organization test,
If it is WED display System Programming test,
If it is THUR display Maths test,
If it is FRI display Aptitude test,
then exit.

b) If it is MON | mon display Unix test, 38


If it is TUE | tue display Computer Organization test,
If it is WED | wed display System Programming test,
If it is THUR | thur display Maths test,
If it is FRI | fri display Aptitude test,
then exit.
27 Write table of 2, and 5 through two ways: 39
1 . Take the number inside the script.
2 . Through positional parameter.
28 Write a shell script which accepts number of arguments. 41
If number of arguments is equal to 5 then only it should
displays your name five times (You can try this, first, by
displaying your name once)?
29 Write a shell script to search whether the username passed 42
on command line has logged in or not, after each minute?
If user has logged in display the message and exit otherwise
display a message “ Not logged in Yet” (i.e. The process will
go in background).
30 Write a shell script which scans your current directory 43
and the files which end with .doc, rename those files to .txt.
Suppose: the current directory named UNIX contains the file
unix01doc then it should be renamed to unix01txt, similarly
for all the files of that directory?
31 Write a shell script that scans the current directory (or any 44
path ) and the files ending with doc are to be moved to a new
directory name “word assignment” and the file ending with .c
(its dot c) are to be moved to a new directory named “c
assignments”?
32 Write a shell script that scans the current directory & 45
renames all the regular files & not the directory files
to the name of the log name i.e. filename. student” ?
33 Write a shell script that takes pattern and filename 46
as command line arguments and displays the result
appropriately i.e. pattern found/ pattern not found.
34 Write a shell script where you check whether the name 47
a . begins with ‘A’ and ends with ‘t’.
b . begins with ‘S’ and ends with ‘T’.
c . any word with fixed length of four characters.
35 Write a shell script where you can accept a word and echo the 48
message whether the name begins with a vowel, consonant or
a digit?
36 Write a shell script that computes the factorial of a given 49
number.
37 Write a shell script that display the prime numbers till the 50
number passed through command line.
38 Write a shell script that scans the current directory & 52
renames all the files to filename.pid, i.e. Process ID of the
current shell.
39 (a) Write a shell script that accepts a student database file. 53
This input file has format as follows:
Student Enrollment No: Student Name: Course
Cut the name column and display the names in the sorted list.

b) Write a shell script that accepts a student database file. 54


This input file has format as follows:
Student Enrollment No: Student Name: Course
Cut the name column and course column and display the
output in the sorted order of name and course.

40 Write a shell script that will create 84 users along with their 55
passwords.

Unix Lab questions:

Q1 Create a file f1. Create 2 hard links of f1 as f2 and f3. Check ls –l. Add contents in
f3 and display f1 and f3. Delete from f2 and check the contents of f1 and f2. Create two
more hard links of f1, i.e., f4 and f5. Check ls –l. Delete f3. Check ls –l. Display f1.
Delete f5. Check ls –l.

Q2 Create a file a1. Enter 4-5 lines in it. Check ls –li. Note down the inode no.,
permissions, links and size. Create 2 more hard links of a1, i.e., a2 and a3. Check ls –
li and again check the inode no., permissions, size, no. of links. Display a1, a2, a3. Add
contents in a3. Check the size of a1, a2, a3. Delete the contents of a2. Display a1, a2, a3.
Check contents, size, no. of links, permissions, inode no. Change the permissions of a3.
Check ls –l. Check contents, size, links, permissions, inode no. of a1, a2, a3. Delete f3.
Check size, links, permissions, inode number again.

Shell scripts:

Q1 Write a shell script which asks your name, age, department, course and then display
all your information in the given format:
I am ____, studying in ____ belongs to ____ department. My age is ____.

Q2 Write a Shell Sript which asks your enrollment number, names of 3 subjects and
marks obtained. Display the information in the format you want.

Q3 Write a shell script that declares 5 variables. Assign values to them, e.g., a1=20,
a2=15, etc. and then display the values in the given order: 1,5,2,4,3

Questions related to vi Editor:

Q1 Open the contents of file a1 in file f1 after third line.

Q2 Cursor position is at second line. Execute who command. Output must be displayed
after third line.

Q3 Go to 5th line, go temporarily to the shell and execute date command and then again
come back to vi editor.

Q4 Pick up lines 2 to 5 from a1 and create a file z1.

Q5 Pick up lines 2 to 9 from a1 and append in file z1.

Q6 Open f1. Go to line 3. Give output of ls command of current directory.

Q7 Pick up lines 3 to 7 from a1 and append in z1. Display z1.

Q8 Create a new file using vi, read contents of a1 into it.


Date command related questions:

Q1 Display date in the format Year Month Day

Q2 Display date in the following format:


Complete weekday, which is the day of the month, full month name, : hours, : minutes
and : seconds in 24 hour clock, / week number of the year.

Q 1) Explain the following commands with the output and example:


(a) comm
(b) diff
(c) sort
(d) uniq
(e) cut
(f) tee
(g) head
(h) tail
(i) pg
(j) more

3. Perform the followings.

/
|
usr
|
MCA5
------------------------------|------------------------
| |
MCA5A MCA5B
| |
---------------------------------------- -----------------
| | | | | |
file1 file2 d1 d2 d51 d52
| | |
d11 ----------------- -----------------
| | | | | |
d12 f3 f4 f5 d511 d512
| |
d13 -----------------
| | |
d14 f511 f512
|
-----------------
| |
f33 f44

*the items starting with f are files

a) Create the directory structure.


Create the files.
Show the output of "pwd" command at each step of directory
creation.

b) Write absolute and relative path of the files f11 and f512. Your
current directory is MCA5B.

c) Copy the file f33 to d52.


Move the files "file1" and "file2" to D511
Move file "f44" to d512

d) delete the file "f33" from d14


remove directory d2
remove directory d1

e) appen the coontents of "f512" with the contents of "f33"


remove directory 511
append "file1" with the contents of files "f44","f512" and "f513"

f) remove the directory d51 using a single command

Das könnte Ihnen auch gefallen