USP LAB Syllabus
USP LAB Syllabus
USP LAB Syllabus
COURSE OBJECTIVES
OBJ1 To understand and execute fundamental Unix commands for directory and file
handling, basic file operations, and viewing/editing files.
OBJ2 To gain proficiency in text manipulation and sorting commands, including `echo`,
`printf`, `sort`, `uniq`, `cut`, `paste`, and `split`.
OBJ3 To learn to retrieve user and system information and manage file permissions to
ensure security.
OBJ4 To develop skills in using networking commands and managing processes,
including monitoring disk usage, configuring network interfaces, and handling
system processes.
OBJ5 To write and execute shell scripts to automate tasks, manipulate text with `grep`,
`sed`, and `awk`, and develop Korn Shell scripts for various utilities and
applications.
WEEK-1
1. Directory and File Handling Utilities:
▪ Display the current working directory using the pwd command.
▪ Create a directory named lab1 using the mkdir command.
▪ Create three subdirectories named dir1, dir2, and dir3 inside lab1 using the mkdir
command.
▪ List the contents of the lab1 directory using the ls command.
2. Basic File Operations:
▪ Create three files named file1.txt, file2.txt, and file3.txt inside dir1 using the touch
command.
▪ Copy file1.txt to dir2 and rename it to file1_copy.txt using the cp command.
▪ Move file2.txt from dir1 to dir3 using the mv command.
1|Page
▪ Remove file3.txt from dir1 using the rm command.
3. Viewing and Editing Files:
▪ Use the cat command to concatenate file1.txt and file1_copy.txt and display the result.
▪ Use the more command to view the contents of file1.txt.
▪ Use the sort command to sort the contents of file1.txt and save the sorted output to
sorted_file1.txt.
▪ Use the uniq command to remove duplicate lines from sorted_file1.txt.
5. Cut, Paste, and Split Commands:
▪ Use the cut command to extract the first column from sorted_file1.txt and save it to
column1.txt.
▪ Use the paste command to combine column1.txt and sorted_file1.txt into a new file
pasted_file.txt.
▪ Use the split command to split file1.txt into pieces of 5 lines each.
6. User and System Information:
▪ Display the username of the current user using the whoami command.
▪ Display the system information using the uname -a command.
▪ Display the current date and time using the date command.
2|Page
WEEK-2
1. Disk Usage and File System Management:
▪ Use the du command to display the disk usage of the lab1 directory.
▪ Use the df command to display the available disk space on all mounted filesystems.
▪ Mount a temporary file system to the /mnt directory using the mount command.
2. Networking Commands:
▪ Display the hostname of the machine using the hostname command.
▪ Use the ping command to check the connectivity to google.com.
▪ Use the nslookup command to find the IP address of a given domain name.
3. Process Management:
▪ List all currently running processes using the ps command.
▪ Kill a process by its PID using the kill command.
▪ Set a process to run with a lower priority using the nice command.
WEEK-3
1. Standard Streams and Redirection:
▪ Write a command to redirect the output of the ls command to a file named ls_output.txt.
▪ Append the output of the date command to the same ls_output.txt file.
▪ Combine the cat and sort commands using a pipe to display the sorted contents of a
file named data.txt.
▪ Use the tee command to simultaneously display the output of the who command on
the terminal and save it to a file named who_output.txt.
3. Sorting and Counting:
▪ Sort the contents of unsorted.txt and save the sorted output to sorted.txt.
3|Page
▪ Use the uniq command to remove duplicate lines from sorted.txt and save the output
to unique_sorted.txt.
▪ Count the number of lines, words, and characters in unique_sorted.txt using the wc
command.
4. Command Substitution and Quotes:
▪ Use command substitution to store the output of the date command in a variable and
then display that variable.
▪ Demonstrate the difference between single quotes (') and double quotes (") by
creating a variable that contains a wildcard character (*) and displaying its value using both
types of quotes.
5. Job Control:
▪ Start a long-running process (e.g., sleep 1000) in the background and list all
background jobs.
▪ Bring the background job to the foreground and then stop it using ctrl+z.
▪ Resume the stopped job in the background using the bg command and then terminate
it using the kill command.
6. Aliases and Shell Customization:
▪ Create an alias named ll for the command ls -la and demonstrate its use.
▪ Remove the alias ll and verify it has been removed.
▪ Customize the shell prompt to display the current directory followed by a $ sign.
▪ Demonstrate the use of predefined environment variables like PATH, HOME, and
USER by displaying their values.
WEEK-4 (grep)
1. Basic Grep Usage:
Write a program that creates a file named `sample.txt` and fills it with random text. Use the
`grep` command to search for lines containing the word "example" and print those lines.
2. Counting Lines:
Create a file named lines.txt with random lines of text. Write a program using `grep`
options to:
4|Page
▪ Display the count of blank lines.
▪ Display the count of non-blank lines.
WEEK-5 (grep)
1. Extended Grep (egrep):
Write a program that creates a file named `extended.txt` with random lines of text. Use
`egrep` to search for lines containing the pattern "abc|def" and display those lines.
2. Character Set Matching:
Create a file named `char_set.txt` with various lines of text. Write a program using `grep`
to search for lines that start with any lowercase letter and contain the word "pattern".
Display the matching lines.
3. Fixed String Search (fgrep):
Write a program that creates a file named `fixed.txt` with random lines of text. Use
`fgrep` to search for the literal string "[ABC]123" and display the matching lines.
4. Pattern Matching with Line Anchors:
Create a file named anchors.txt with lines starting and ending with different words. Write
a program using `grep` to:
5|Page
5. Search for Multiple Patterns:
Write a program that creates a file named multi_pattern.txt with various lines of text. Use
`grep` to search for lines containing either "foo" or "bar" and display the matching lines.
6. Piping Commands:
Write a program that lists all files in the current directory and pipes the output to `grep` to
display only the files with names starting with "log".
WEEK-6 (sed)
1. Basic Sed Operations:
Write a script that creates a file named input.txt with lines of text. Use `sed` to replace the
first occurrence of the word "Hello" with "Hi" in the file and display the modified content.
2. Multiple Substitutions:
Create a file named `multi_sub.txt` with several lines of text. Write a `sed` script to:
▪ Replace "apple" with "orange".
3. Address Ranges:
Write a script that creates a file named `range.txt` with random lines of text. Use `sed` to
print lines between the 3rd and the 7th line inclusive.
4. Conditional and Unconditional Branching:
▪ Create a file named branch.txt with multiple lines. Write a `sed` script to:
5. Line Numbering:
Write a script that creates a file named `numbered_lines.txt` with random lines of text.
Use `sed` to display the file content with line numbers prefixed to each line.
6. Using Hold Space:
▪ Create a file named `hold_space.txt` with lines of text. Write a `sed` script to:
✓ Append the contents of the hold space to the end of the file.
WEEK-7 (sed)
1. Inserting and Appending Text:
6|Page
Write a script that creates a file named insert_append.txt with lines of text. Use sed to:
▪ Insert "Start" before the second line.
▪ Append "End" after the fourth line.
▪ Read the contents of `file2.txt` and insert it into `file1.txt` after the first line.
▪ Write specific lines from `file1.txt` to a new file `output.txt`.
4. Transform Command:
Create a file named `transform.txt` with text containing vowels. Write a `sed` script to
transform all lowercase vowels to uppercase vowels in the file and display the result.
5. Branching with Labels:
Write a script that creates a file named branch_labels.txt with multiple lines. Use sed to:
▪ Replace the word "old" with "new" only if it is not at the beginning of a line.
▪ Implement branching with labels to handle specific patterns and conditions.
WEEK-8 (awk)
1. Basic AWK Usage:
Write a script to create a file named `data.txt` with random lines of text. Use an AWK
command to print all lines containing the word "example".
2. Field Separator:
Create a file named `fields.txt` where fields are separated by commas. Write an AWK
script to print the second and fourth fields of each line.
3. Pattern Matching:
7|Page
Write a script that creates a file named `match.txt` with lines of text. Use an AWK
command to print lines where the third field matches the regular expression `[A-Za-z]+`.
4. Using Variables:
Create a file named variables.txt with numerical data in each line. Write an AWK script
to calculate and print the sum and average of the numbers in the second field.
5. BEGIN and END Blocks:
Write a script that creates a file named `begin_end.txt` with random data. Use an AWK
script with BEGIN and END blocks to print a header before processing the file and a
footer after processing the file.
6. String Functions:
Create a file named `strings.txt` with various strings. Write an AWK script to use the
length, substr, and toupper functions to process and print the strings.
WEEK-9 (awk)
1. Arithmetic Operations:
Write a script to create a file named `arithmetic.txt` with numerical data. Use an AWK
script to perform arithmetic operations on the fields and print the results.
2. Conditional Statements:
Create a file named `conditions.txt` with student names and their scores in three subjects.
Write an AWK script to print "Pass" if the average score is 50 or above, otherwise print
"Fail".
3. Loops:
Write a script that creates a file named loops.txt with multiple lines of data. Use an AWK
script to iterate over each field of the file and print each field value.
4. Associative Arrays:
Create a file named `words.txt` with lines of text. Write an AWK script to count the
frequency of each word and print the word along with its count.
5. Formatted Output:
Write a script that creates a file named `formatted.txt` with numerical data. Use an AWK
script with the printf function to print the data in a formatted table.
6. Using System Commands:
Create a file named `system.txt` with user information. Write an AWK script that pipes
the contents of the file to another command (e.g., sort) and processes the sorted data.
8|Page
WEEK-10 (Korn Shell Scripting)
1. Directory or File Check:
Write a shell script that takes a command line argument and reports whether it is a
directory or a file.
2. Uppercase Conversion:
Write a shell script that accepts one or more file names as arguments and converts all of
them to uppercase, provided they exist in the current directory.
3. Gross Salary Calculation:
Write a shell script that computes the gross salary of an employee according to the
following rules:
▪ If the basic salary is less than 1500, then HRA = 10% of the basic and DA = 90% of
the basic.
▪ If the basic salary is 1500 or more, then HRA = Rs.1500 and DA = 98% of the basic.
4. String Operations:
Write a shell script to perform the following string operations:
▪ Extract a substring from a given string.
▪ Find the length of a given string.
5. Login Notification:
Write a shell script that takes a login name as a command-line argument and reports when
that person logs in.
9|Page
Write a shell script to generate the multiplication table of a given number.
COURSE OUTCOMES
Students are able
CO1 To demonstrate the ability to use Unix commands for directory navigation, file
manipulation, and basic system operations.
CO2 To execute advanced text processing tasks, including sorting, searching, and
modifying file contents using command-line tools.
CO3 To efficiently gather system and user information, manage user permissions, and
perform security operations through Unix commands.
CO4 To apply networking commands to check connectivity, configure network settings,
and use process management commands to monitor and control system processes.
CO5 To develop and implement shell scripts for automating tasks, including text
manipulation, system monitoring, and user-defined operations, showcasing an
understanding of scripting logic and syntax.
10 | P a g e