0% found this document useful (0 votes)
0 views20 pages

SP23-BDS-054 OS Lab MId

The document is a lab midterm submission on the principles of operating systems, detailing various Linux commands and their usage. It includes tasks such as creating files and directories, copying and moving files, and modifying environment variables. Additionally, it covers the customization of the bash prompt and the management of command history and aliases.

Uploaded by

waliurehman4023
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)
0 views20 pages

SP23-BDS-054 OS Lab MId

The document is a lab midterm submission on the principles of operating systems, detailing various Linux commands and their usage. It includes tasks such as creating files and directories, copying and moving files, and modifying environment variables. Additionally, it covers the customization of the bash prompt and the management of command history and aliases.

Uploaded by

waliurehman4023
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/ 20

Principles of OS

Lab MidTerm

Submitted By
Wali Ur Rehman
SP23-BDS-054

Submitted To
Mam Zahida Walayat

1
Q1:

After ensuring the Desktop directory exists, try creating the file again:

• touch /home/wali/Desktop/myfile.txt

Q2:

Verify your current location:

• Run the command pwd (print working directory). This will show you where the
terminal is currently operating. It's unusual to not have your own home directory.

• mkdir -p /home/wali/Desktop/

Q3

• touch mydata.txt
• mkdir docs
• mv mydata.txt docs/
• mkdir old_dir
• ls -l
• mv old_dir new_dir
• ls -l

2
Q4

Here are the simple Linux commands shown in the image, presented as bullet points:

• touch mydata.txt

• mkdir docs

• mv mydata.txt docs/

• mkdir old_dir

• ls -l

• mv old_dir new_dir

• ls -l (run again)

3
Q5

• pwd # Verify your current working directory


• touch source_file.txt # Create the source file
• ls -l source_file.txt # Verify the file was created
• mkdir destination_dir # Create the destination directory
• ls -l destination_dir/ # Verify the directory was created
• cp source_file.txt destination_dir/ # Copy the file
• ls destination_dir/ # Verify the file is now in the destination directory

Q6

• cp: The cp command is used for copying files, as taught in the lab manual.
• mkdir: The mkdir command is used to create directories, which is essential for
organizing files. The -p option is a useful extension for creating nested
directories.

Q7

• rm: The command itself, short for "remove."

[options]: Optional flags that modify how the rm command works (e.g., -i for interactive
deletion, -f for force deletion).

4
file1 file2 ...: The names (or paths) of the files you want to delete. You can delete
multiple files at once.

Q8

Q9

• cp: The copy command.


• -r or -R: The recursive option. Both -r and -R achieve the same result in most
common Linux systems.
• source_directory: The directory you want to copy.
• destination: The location where you want to create the copy. If the destination is
an existing directory, the source directory will be copied into the destination. If
the destination is a non-existent path, the source directory will be copied to that
path (and the path will be created).

5
Q 10

• cp -r: The copy command with the recursive option.

• Europe/UK: The relative path to the source directory. This assumes your current
working directory is such that this path correctly locates the UK directory. If not,
you would use the absolute path.

• Europe/UnitedKingdom: The relative path to the destination. This will create a


directory named UnitedKingdom inside Europe and copy the contents of UK into
it. If a directory named UnitedKingdom already exists inside Europe, then the UK
directory and its contents will be copied inside the existing UnitedKingdom
directory.

Using Absolute Path (More Reliable):

Q 11
Using cat function to print content

Q 12

• To print the content of the file City.txt located at Asia/Pakistan/ISBD, you would
use the cat command with the file's pat

Q 13

6
Q 14

• cat: The command used for displaying file content, but here used to take
standard input.
• >>: The append redirection operator. This will add any text you type to the end of
the City.txt file. If City.txt does not exist at the specified path, this command will
create it.
• Africa/Egypt/Cairo/City.txt: The path to the file you want to modify.

Q 15

The touch command is used to create an empty file in Linux

Q 16

• mkdir -p Asia/China: This command creates the Asia directory and the China
subdirectory within your /home/ubuntu directory. The -p flag ensures that the
parent directory (Asia) is created if it doesn't exist.
• touch Asia/China/Country.txt: This command creates an empty file named
Country.txt inside the /home/ubuntu/Asia/China directory.

7
Q 17

Q 18

Q 19

Q 20

To view and navigate the contents of new_file.txt efficiently, you would use the less
command

less new_file.txt

Explanation:

8
As discussed in the answer to Question 19, less is a powerful pager program that allows
you to view file content with more efficiency and navigation options than more. It
doesn't load the entire file into memory, making it suitable for large files, and it allows
both forward and backward scrolling, searching, and jumping to the beginning or end of
the file.

1. Navigate using the less commands

o Spacebar: Scroll forward one screen.

o b: Scroll backward one screen.

o j: Scroll forward one line.

o k: Scroll backward one line.

o /pattern: Search forward.

o `?pattern: Search backward.

o g: Go to the start.

o G: Go to the end.

o q: Quit.

By using the less new_file.txt command, you can effectively view and navigate the
contents of the file in a more efficient and feature-rich manner compared to more.

Q 21

9
Q 22

Q 23

10
Q 24

Q 25

11
Q 26

Q 27

Q 28

Q 29

12
Q 30

Q 31

Q 32

Q 33

Q 34

The name of the shell variable that controls the format of your bash prompt is PS1

13
Q 35

To see the current value of the PS1 variable, which controls the format of your bash
prompt, you would use the echo command followed by the variable name prefixed with
a dollar sign ($)

Q 36

To change the bash prompt so that it displays only the text ubuntu-server, you would
assign that string directly to the PS1 variable:

Q 37

You would modify the special Bash variable PS1 to customize your prompt to display the
date, time, username, hostname, and working directory.
Here are some commonly used escape sequences for PS1:

• \d: The date in "Weekday Month Day" format (e.g., "Tue May 26").

• \t: The current time in 24-hour HH:MM:SS format.

• \u: The username of the current user.

• \h: The hostname up to the first '.'.

14
Q 38

To set the bash prompt to display the date, time, username, host, and current working
directory, you would assign a string containing the appropriate escape sequences to the
PS1 variable

Q 39

To create a custom alias named dt for the date command in Bash, you would use the
alias command followed by the alias name, an equals sign (=), and the command you
want to alias (enclosed in single or double quotes): alias: This is the bash built-in
command used for creating aliases.

dt: This is the name you want to give to your custom alias.

=: The assignment operator, linking the alias name to the command.

'date': The command you want the alias dt to execute. It's enclosed in single quotes
to ensure that it's treated as a single unit. Double quotes would also work in this simple
case.

Q 40

Once you've created the alias dt='date', you would use it to display the current date by
simply typing the alias name and pressing Enter:

15
Q 41

You can run the history command to view the history of previously executed commands
in Bash

Q 42

To print the value of the SHELL environment variable in Bash, you would use the echo
command followed by the variable name prefixed with a dollar sign ($):

• echo $SHELL

Q 43

To list all environment variables currently defined in your shell session, you can use
either the env command or the printenv

16
Q 44
To set an environment variable named OFFICE with the value caleston for the current
shell session only, you would use the assignment operator (=) directly in the terminal:

Q 45

The command that allows you to set an environment variable like OFFICE=caleston
and make it available to child processes as well is the same basic assignment, but it's
important to understand how environment variables are inherited.

17
Q 46

To make environment variables persistent across reboots and logins, you modify shell
configuration files. These files are executed when a new shell session starts, ensuring
your variables are set. The primary file for user-specific settings in Bash is .bashrc .

• nano ~/.bashrc
• export OFFICE=caleston
• source ~/.bashrc

Q 47

To display the value of the LOGNAME environment variable, you would use the echo
command followed by the variable name prefixed with a dollar sign ($):

echo $LOGNAME

Example of the expected output:

Given your current user wali in the prompt, the output would likely be:

Wali

18
Q 48

To see all directories defined in the PATH environment variable, you would use the echo
command followed by the variable name prefixed with a dollar sign ($):

echo $PATH

Q 49

Commands are :

• sudo apt update


• sudo apt install obs-studio
• sudo dnf install obs-studio
• sudo pacman -S obs-studio

Q 50

To add a new directory (/opt/obs/bin) to the PATH environment variable, you would
modify the PATH variable by prepending or appending the new directory to the existing
list, separated by a colon (:).

For the current shell session only:

You can add it to the beginning of the PATH like this:

• export PATH="/opt/obs/bin:$PATH"
• export PATH="$PATH:/opt/obs/bin"
19
20

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy