Lab 1
Executing basic commands:
1. To display the current working directory, the command is:
pwd
The output is as follows.
/home/trg1
2. Display the path to and name of your HOME directory.
3. Display the login name using which you have logged into the system
4. Display the hidden files of your current directory.
5. List the names of all the files in your home directory.
6. Using the long listing format to display the files in your directory.
7. List the files beginning with chap followed by any number or any lower case alphabet.
(Example, it should display all files whose names are like chap1, chap2, chap3 …….,
chapa,ahapb,chapc,……..)
8. Give appropriate command to create a directory called C_prog under your home
directory. (Note: Check the directory using ls)
9. Create the following directories under your home directory. (Note: Check using ls)
newdir
newdirectory
10. List the names of all the files, including the contents of the sub directories under your
home directory.
11. Remove the directory called newdirectory from your working directory.
12. Create a directory called temp under your home directory.
13. Remove the directory called newdir under your home directory and verify the above with
the help of the directory listing command.
14. Create another directory directorynew under the temp directory.
15. Change the directory to your home directory.
16. From your home directory, change the directory to directorynew using relative and
absolute path.
17. Remove the directory called c_prog, which is in your home directory.
18. Change to the directory /etc and display the files present in it.
19. List the names of all the files that begin with a dot in the /usr/bin directory.
20. Create a file first.unix with the following contents.
Hi! Good Morning everybody.
Welcome to the First exercise on UNIX.
Hope you enjoy doing the assignments.
21. Copy the file first.unix in your home directory to first.unics.
(Note: checked using ls, first.unix file also should exist along with first.unics)
22. List the contents of first.unix and first.unics with a single command.
23. Create a new directory under the temp directory.
24. From your home directory, copy all the files to the directory created under the temp sub
directory.
25. Move the file first.unix to the directory temp as second.unix
26. Remove the file called first.unics from the home directory.
27. Change your directory to temp and issue the command rm *. What do you observe?
28. Move all files whose names end with a, c and o to the HOME directory.
29. Copy all files that end with a ‘UNIX’ to the temp directory.
30. Issuing a single command, remove all the files from the directory temp and the directory
itself.
31. Try commands cp and mv with invalid number of arguments and note the results.
32. Use the cat command to create a file friends, with the following data:
Madhu 6966456 09/07/68
Jamil 2345215 08/09/67
Ajay 5546785 01/04/66
Mano 7820022 09/07/68
David 8281292 09/09/60
Simmi 7864563 12/12/70
Navin 2224311 30/05/68
The fields should be separated by a tab.
33. Display contents of the file friends.
34. Copy contents of friends to newfriend without using the cp command.
35. Display contents of the file friends and newfriends in a single command.
36. Find all users currently working on the system and store the output in a file named as
users.
37. Append contents of friends file to the file, users.
38. Display current system date and time and record your observations. How is the time
displayed?
39. Display calendar for the month and year of your birth.
40. Try following commands and record your observations.
date “+ %”
date “+%m”
date “+%D”
date “+%/%Training Activity”
date “+%Training Activity”
date “+%r”
Viewing the File System and Granting/Removing Permissions (Note: Create required files if doesn’t
exists.)
1. Give the execute permission for the user for a file chap1
2. Give the execute permission for user, group and others for a file add.c
3. Remove the execute permission from user, give read permission to group and others for
a file aa.c
4. Give execute permission for users for a.c, kk.c, nato and myfile using single command
5. Change the directory to root directory. Check the system directories, like bin, etc, usr etc
Lab 2
2.1: Using Pipes and Filters:
1: Redirect the content of the help document ls, into a file called as lsdoc.
2: Display the content of the lsdoc page wise.
3: Display only the first 4 lines of the lsdoc file.
4: Display only the last 7 lines of the file lsdoc.
5: Remove the file lsdoc.
6: There will be B’day celebration from the friends file, find how many B’day parties will be held.
If two of the friends have the B’date on the same day, then we will be having one party on
that day.
7: Display the lines starting with Ma, in the file friends.
8: Display the lines starting with Ma, ending with i or ending with id, in the file friends.
9: Print all the files and the directory files from the current directory across all the sub directories,
along with its path
10: Print only the Directory files.
11: Display the files starting with chap, along with its path.
12: Sort the file friends in ascending order of names.
13: Display the contents of the file friends in uppercase letters.
14: Store the contents of your home directory in a file called dir.
15: From the above file dir, display the file permissions and the name of the file only.
16: From the same dir file, store only the file names in a file called files.
17: From the same dir file, store only the permissions of files in a file called perms.
18: From the same dir file, store only the file sizes in a file called sizes.
19: Display the file names, sizes and permissions from your directory in that order.
20: Display the number of users working on the system.
21: Find out the smallest file in your directory.
22: Display the total number of lines present in the file friends.
23:Create the following fixed record format files (with “|” delimiter between fields) with the
structure given below, and populate them with relevant data use these files to solve following
questions
emp.lst: Empid(4),Name(18),Designation(9),Dept(10),Date of Birth(8),Salary(5)
dept.lst : Dept.Code(2),Name(10),Head of Dept’s id(4)
desig.lst: Designation Abbr.(2), Name (9)
1. Find the record lengths of each file.
2. Display only the date of birth and salary of the last employee record.
3. Extract only employee names and designations. (Use column specifications). Save
output as cfile1.
4. Extract Emp.id, dept, dob and salary. (Use field specifications). Save output as cfile2.
5. Fix the files cfile1 and cfile2 laterally, along with the delimiter.
6. Sort the emp.lst file in reverse order of Emp. Names.
7. Sort the emp.lst file on the salary field, and store the result in file srtf.
8. Sort the emp.lst file on designation followed by name.
9. Sort the emp.lst file on the year of birth.
10. Find out the various designations in the employee file. Eliminate duplicate listing of
designations.
11. Find the non-repeated designation in the employee file.
12. Find the number of employees with various designations in the employee file.
13. Create a listing of the years in which employees were born in, along with number of
employees born in that year.
14. Use nl command to create a code table for designations to include designation code
(Start with dept. code 100, and subsequently 105, 110 …).
24: PCS has its offices at Pune, TTC and Mumbai. The employees’ data is stored separately
for each office. Create appropriate files (with same record structure as in previous
assignment) and populate with relevant data.
1. List details about an employee ‘Manu Sharma’ in the Mumbai office.
2. List only the Emp.Id. And Dept. of Manu Sharma.
3. List details of all managers in all offices. (O/P should not contain file names.).
4. Find the number of S.E. in each office.
5. List only the Line Numbers and Employee names of employees in ‘H/W’ in Pune file.
6. Obtain a listing of all employees other than those in ‘HR’ in the Mumbai file and save
contents in a file ‘nonhr’.
7. Find the name and designation of the youngest person who is not a manager.
8. Display only the filename(s) in which details of employee by the name ‘Seema Sharma’
can be found.
9. Locate the lines containing saxena and saksena in the Mumbai office.
10. Find the number of managers who earn between 50000 and 99999 in the Pune office.
11. List names of employees whose id is in the range 2000 – 2999: in Pune Office; in all
offices.
12. Locate people having same month of birth as current month in Pune office.
13. List details of all employees other than those of HR and Admin in file F1.
14. Locate for all Dwivedi, Trivedi, Chaturvedi in Pune file.
15. Obtain a list of people in HR, Admin and Recr. depts. sorted in reverse order of the
dept.
Extra Assignments
25: Write a command sequence that prints out date information in this order: time, day of week,
day number, month, year:
13:44:42 IST Sun 16 Sept 1994
26: Write a command sequence that prints the names of the files in the current directory in the
descending order of number of links
27: Write a command sequence that prints only names of files in current working directory in
alphabetical order
28: Write a command sequence to print names and sizes of all the files in current working
directory in order of size
29: Determine the latest file updated by the user
Lab3
3.1: Working wth Vi Editor
1. Create a file using Vi. Enter the following text:
A network is a group of computers that can communicate with each other, share
resources, and access remote hosts or other networks. Netware is a computer network
operating system designed to connect, manage, and maintain a network and its services.
Some of the network services are Netware Directory Services (NDS), file system, printing
and security.
a. Change the word “Netware” in the second line to “Novell Netware”.
b. Insert the text “(such as hard disks and printers)” after “share resources” in the first line.
c. Append the following text to the file:
“Managing NDS is a fundamental administrator role because NDS provides a single
point for accessing and managing most network resources.”
2: Create the data files, used in the previous lab sessions using vi editor.
Lab 5
Using Process-Related Commands
1. Find out the PID of the processes that are activated by you
2. Find out the information about all the processes that are currently active
3. Start a different process in the background. Find out the status of the background process
using the PID of the same.
Lab 4
Writing Shell-Scripts
1. Display the Primary and Secondary prompt. Change the primary prompt to your name:
temporarily
2: As soon as you login, the prompt should be changed to your name: also the name of the
home directory should be automatically displayed.
3: Check the content of the Environmental variable SHELL.
4: Try the below exercise and check the output.
Note: Type every line and press enter, do not type the entire code in a vi editor.
$continent=”Africa”
$echo “$continent”
------------→ Africa
$sh
$echo “$continent”
------------→ No Response
$continent=”Asia”
$echo “$continent”
------------→ Asia
$ctrl + d
$echo “$continent”
------------→ Africa
$sh
$echo “$continent”
------------→ No Response
$ctrl + d
5: Try the below exercise and check the output. (Export variables)
Note: Type every line and press enter, do not type the entire code in a vi editor.
$continent=”Africa”
export continent
$echo “$continent”
------------→ Africa
$sh
$echo “$continent”
------------→ Africa
$continent=”Asia”
$echo “$continent”
------------→ Asia
$ctrl + d
$echo “$continent”
------------→ Africa
6: Write a shell script that takes the user name as input and reports whether he / she has logged
in or not.
7: Write a shell script to display the file name and its contents of all the files that is there in the
current directory.
8: Write a shell script, which will take a file name as argument and check whether the file exists
and display its access permissions for user.
9: Pass three numbers as command line arguments and display the largest number in the given
three numbers.
10: Write a shell script which will accept a pattern and a file name. The pattern will be searched
in the file provided. Display appropriate messages and perform necessary validations on
file.
11: To create a menu program for a) creating a file, b) Creating a directory, c) copying a file,
d) moving a file. (use functions)
a. If the file exists already give the appropriate message
b. If the dir exists already give the appropriate error message
c. Source file should exist if not give a message, It should have read permission if not
another message, Destination file either there or not, if not there then create it and copy
it. If there, then ask whether to overwrite or not, if yes then overwrite it or else give a
message file exists already and not overwritten.
12: Write a function yesno() to display question to user and accept answer as y/n. If answer to
the question is y the function should return 0 otherwise 1.
Use yesno functions for asking different questions. Question will be passed as parameter
to the function.
Accept filename from user check whether it is file or directory. Use yesno() function to
display question do you really want to delete file? If the ans is y, then delete the file or
directory.
13: Write a shell script to store names of four employees and check whether those employees
are currently logged in or not. Display appropriate message.
14: Accept the user's first and last name and the echo the entire name along with some suitable
comment.
15: List all files that have been modified today.
16: Display long listing of only the regular files in the current directory.
17: Display details of all files in the 2 “paths” accepted from user. The display should be screen
by screen.
18: Let the script display its name and its PID.
19: Get the concatenated o/p of 2 files into a third file: Take 3 command line arguments: The
first argument is the name of a destination file, and the other two arguments are names of
files whose contents are to be placed in the destination file.
Stretched Assignments:
20: Write a menu driven shell program to:
a. Display calendar of current month
b. Search for a pattern in all the files/subdirectories from current directory.
c. Count the no. of directories / sub directories in current directory
21: Display day of week for a given date. (ddmmyyyy)
If day is Monday, display message “Monday Blues”
Friday display message “yeh! It’s week end.”
Similarly display different messages for each day of the week.
22: Display the contents of all .lst files in the current directory.
23: Design a simple calculator, which will add/subtract/multiply/divide 2 numbers.
eg. cal 10 20 + will give o/p as 30.
24: For a student file with the following fields, rollno, name, marks, Generate 2 files ‘Pass’ and
‘Fail’ containing records of student who have passed or failed. Also count the number of
students who have passed or failed.
25: Accept a date string from terminal and display employees born after the input date.