0% found this document useful (0 votes)
183 views10 pages

Le Nguyen Nhat Minh - B2205994 - CT104H - Lab02

The document provides instructions for a lab assignment on operating systems. Students are asked to complete tasks like navigating directories, editing text files, searching for files that match certain criteria, and writing shell scripts. They are instructed to show the commands and output screenshots in their submitted report.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
183 views10 pages

Le Nguyen Nhat Minh - B2205994 - CT104H - Lab02

The document provides instructions for a lab assignment on operating systems. Students are asked to complete tasks like navigating directories, editing text files, searching for files that match certain criteria, and writing shell scripts. They are instructed to show the commands and output screenshots in their submitted report.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

CT104H – Operating System

CAN THO UNIVERSITY


COLLEGE OF INFORMATION AND COMMUNICATION TECHNOLOGY
OPERATING SYSTEMS (CT104H)
LAB #2

Student name: LÊ NGUYỄN NHẬT MINH ID:B2205994

- Submission: Students submit 1 file named StudentName_ID_CT104H_Lab02.pdf to the Google classroom


(where StudentName is the student’s name, and ID is the student’s ID).
- Instructions on how to present in the report file
⮚ For each question, students MUST provide the commands/scripts AND screenshots of the commands
used and/or the content of files/scripts, CLEARLY. Note: the screenshot needs to include the name of
the Ubuntu Virtual machine.
⮚ Student creates an Ubuntu Virtual machine named UbuntuID (ID is the student’s ID). For example, we
have a virtual machine named Ubuntu20043, such that the student ID is 20043.
Question 0: Navigate to your home directory
Answer: $cd

Study from the Linux CLI Fundamentals (Sections: Nano Text Editor, Shell Scripting Basics), the book An
Introduction to the Linux Command Shell for Beginners, and the book Linux Bible of Christopher Negus (Chapter
5: Working with the Text Files, and Chapter 7: Writing Simple Shell Scripts )

Solve all the questions from 1 to 10 in the Section Exercises of Chapter 5 (Linux Bible of Christopher Negus)

Solve all the questions from 1 to 5 in the Section Exercises of Chapter 7 (Linux Bible of Christopher Negus)
CT104H – Operating System

CHAPTER 5
1. Copy the /etc/services file to the /tmp directory. Open the /tmp/services file in vim, and search for
the term WorldWideWeb. Change that to read World Wide Web

cp /etc/services /tmp/
vi /tmp/services

# Inside vi, search for WorldWideWeb using: /WorldWideWeb

# Press 'n' to find the next occurrence

# Change it to World Wide Web and save the file:


cwWorld Wide Web

2. Find the following paragraph in your /tmp/services file (if it is not there, choose a different paragraph) ,
and move it to the end of that file.

# open /tmp/services in a text editor and manually find and move the specified paragraph to the end of
the file.

vi /tmp/services
/New ports
3dd
G
p
CT104H – Operating System

BEFORE

AFTER
CT104H – Operating System

3. Using ex mode, search for every occurrence of the term tcp (case-sensitive) in your /tmp/services file
and change it to WHATEVER.

ex -sc ':%s/tcp/WHATEVER/g | :wq' /tmp/services

4. As a regular user, search the /etc directory for every file named passwd. Redirect error messages from
your search to /dev/null.

find /etc -name passwd 2> /dev/null

5. Create a directory in your home directory called TEST. Create files in that directory named one, two, and
three that have full read/write/execute permissions on for everyone (user, group, and other). Construct a
find command to find those files and any other files that have write permission open to “others” from your
home directory and below.

mkdir ~/TEST
touch ~/TEST/{one,two,three}
chmod 777 ~/TEST/{one,two,three}

Then, construct a find command to find files with write permissions for others:
find $HOME -perm -002 -type f -ls
CT104H – Operating System

6. Find files under the /usr/share/doc directory that have not been modified in more than 300 days.
find /usr/share/doc -type f -mtime +300

7. Create a /tmp/FILES directory. Find all files under the /usr/share directory that are more than 5MB and
less than 10MB and copy them to the /tmp/FILES directory.
mkdir /tmp/FILES
find /usr/share -type f -size +5M -size -10M -exec cp {} /tmp/FILES \;
du -sh /tmp/FILES/*
CT104H – Operating System
8. Find every file in the /tmp/FILES directory, and make a backup copy of each file in the same directory.
Use each file's existing name, and just append .mybackup to create each backup file.

find /tmp/FILES/ -type f -exec cp {} {}.mybackup \;

9. Install the kernel-doc package in Fedora or Red Hat Enterprise Linux. Using grep, search inside the
files contained in the /usr/share/doc/kernel-doc* directory for the term e1000 (case-insensitive) and list
the names of the files that contain that term.

sudo apt install linux-doc

grep -irl "e1000" /usr/share/doc/linux-doc*


CT104H – Operating System

10. Search for the e1000 term again in the same location, but this time list every line that contains the term
and highlight the term in color.
grep -ir --color=always "e1000" /usr/share/doc/kernel-doc*
CT104H – Operating System

CHAPTER 7
1. Create a script in your $HOME/bin directory called myownscript. When the script runs, it should output
information that looks as follows:
Today is Sat Dec 10 15:45:04 EST 2016.
You are in /home/joe and your host is abc.example.com.
Of course, you need to read in your current date/time, current working directory, and hostname. Also,
include comments about what the script does and indicate that the script should run with the /bin/bash
shell.

Using any text editor, create a script called $HOME/bin/myownscript that contains the following:
#!/bin/bash
# myownscript
# List some information about your current system
echo "Today is $(date)."
echo "You are in $(pwd) and your host is $(hostname)."
-------------------------------------------------
chmod 755 $HOME/bin/myownscript

To execute use: ./myownscript

2. Create a script that reads in three positional parameters from the command line, assigns those
parameters to variables named ONE, TWO, and THREE, respectively, and outputs that information in the
following format:
There are X parameters that include Y.
The first is A, the second is B, the third is C.
Replace X with the number of parameters and Y with all parameters entered. Then replace A with the
contents of variable ONE, B with variable TWO, and C with variable THREE.

Using any text editor, create a script called $HOME/bin/myposition that contains the following:
#!/bin/bash
# myposition
ONE=$1
TWO=$2
THREE=$3
echo "There are $# parameters that include: $@"
CT104H – Operating System
echo "The first is $ONE, the second is $TWO, the third is
$THREE."
-----------------------------------------------
chmod 755 $HOME/bin/myposition
To execute use: ./myposition Where Is My Hat Buddy?

3. Create a script that prompts users for the name of the street and town where they grew up. Assign town
and street to variables called mytown and mystreet, and output them with a sentence that reads as shown in
the following code (of course, $mystreet and $mytown will appear with the actual town and street the user
enters):
The street I grew up on was $mystreet and the town was $mytown.

Using any text editor, create a script called $HOME/bin/myposition that contains the following:

#!/bin/bash
# myhome
read -p "What street did you grow up on? " mystreet
read -p "What town did you grow up in? " mytown
echo "The street I grew up on was $mystreet and the town was $mytown."
---------------------------------------
chmod 755 $HOME/bin/myhome
./myhome

4. Create a script called myos that asks the user, “What is your favorite operating system?” Output an
insulting sentence if the user types Windows or Mac. Respond “Great choice!” if the user types Linux. For
anything else, say “Is <what is typed in> an operating system?”
Using any text editor, create a script called $HOME/bin/myposition that contains the following:

#!/bin/bash
# myos
read -p "What is your favorite operating system, Mac, Windows or Linux? " opsys
CT104H – Operating System
if [ $opsys = Mac ] ; then
echo "Mac is nice, but not tough enough for me."
elif [ $opsys = Windows ] ; then
echo "I used Windows once. What is that blue screen for?"
elif [ $opsys = Linux ] ; then
echo "Great Choice!"
else
echo "Is $opsys an operating system?"
fi

5. Create a script that runs the words moose, cow, goose, and sow through a for loop. Have each of those
words appended to the end of the line “I have a….”
Using any text editor, create a script called $HOME/bin/myposition that contains the following:
#!/bin/bash
# animals
for ANIMALS in moose cow goose sow ; do
echo “I have a $ANIMALS”
done
------------------------------------
chmod 755 $HOME/bin/animals
./animals

You might also like