0% found this document useful (0 votes)
10 views5 pages

OSSA_Workshop 07_Shell Scripting

The document provides an overview of various Linux utilities and their usage, including commands like date, mv, tar, grep, chmod, more, tail, and cat. It explains the importance of background processes in UNIX, how to manage them, and the concept of environment variables. Additionally, it discusses how to retrieve a user's preferred shell using grep and cut commands, as well as the significance of the /etc/passwd file.

Uploaded by

tharushi742
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)
10 views5 pages

OSSA_Workshop 07_Shell Scripting

The document provides an overview of various Linux utilities and their usage, including commands like date, mv, tar, grep, chmod, more, tail, and cat. It explains the importance of background processes in UNIX, how to manage them, and the concept of environment variables. Additionally, it discusses how to retrieve a user's preferred shell using grep and cut commands, as well as the significance of the /etc/passwd file.

Uploaded by

tharushi742
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/ 5

Operating Systems and System Administration

Workshop sheet 05
Year 02 Semester 01
Department of Information Technology, Faculty of Computing

1) Briefly explain the usage of the following Linux utilities.


date, mv, tar, grep, chmod, more, tail, cat
date - print the current date and time
mv – rename a file
tar – archive a file
grep – prints a line matching a pattern
chmod – change the file access permission
more – option to view the content of a file in a screen and load more
tail – output the last part of the file
cat – concatenate the file content with the screen.

2) In UNIX environment, some of the processes are sent to background, to run the as background
processes.
a) What is the importance of this in UNIX operating system?

Execute more programs in the system.


Allows users to run multiple tasks simultaneously without being tied to the output or
completion of any single process in order to free up the terminal for other tasks while long
running processes continue to execute in background.

b) Explain how to send the processes to background?

Execution command and &


Using the ampersand (&): When you append an ampersand (&) to the end of a command,
it tells the shell to run the command in the background.

Eg: $ date &


c) What are the commands we can use to check the status of background process?

ps command – displays information about all processes running on the system, including
background processes as well.
jobs: The jobs command lists the status of all background processes running in the current
shell session. It displays the job ID, status, and command for each background process.

d) If required, how can we bring these processes to foreground again?

fg % <PID>
You can bring a background process to the foreground by specifying its job ID. The job ID
can be found using the jobs command. Then, use the fg command followed by the job ID.

Support your answer with suitable examples.


3) What does it means by “Environment variable”?
global variable refers to an environment variable that is accessible to all processes and
shells in the current session. Environment variables are used to store information that can
affect the behavior of running processes.

HOME – current users home directory


TEMP – which specified temporary directory for storing temporary files
PATH- which specified directories where executable programs are located.
4) Observe the following command sequence.

a) Explain the reason for the above error message.

the error message "Hello: no such a file or directory" occurs because the system is
trying to execute a command named hello, but it cannot find an executable file with
that name in any of the directories listed in the system's PATH environment variable.

To execute a script using only by it’s name it should be available in the path variable.
/home/sunit/demo is not in the path variable.

b) By using your knowledge about environment variables, explain how to avoid the above error.

The PATH environment variable tells the shell where to look for executable files. By
default, the current directory (.) is not included in PATH for security reasons.
echo $PATH
PATH=$PATH:/home/sunil/demo
echo $PATH #now the path is being added. Then execute and see no such error
5) Explain how “grep“ and “cut” commands can be used to retrieve the preferred shell of user “sunil”.
(hint: preferred shell is 7th field of a passwd file entry)

grep “sunil’’ /etc/passwd | cut -f7 -d “ ”


To retrieve the preferred shell of the user "sunil" using the grep and cut commands, you would
typically look into the system's user database, which is usually stored in the /etc/passwd file on
Unix-like systems.

-------------------------------------------------------------------------------------------------------
Grep – used to search pattern within the file
Cut – used to extract specific sections of each line form a file

/etc/password file is important file type in LINUX


- Store essential information about users on system
- Contains one entry per line, which stores one users information’s on one line
- Each user information contains, within 7 fields and each field is separated by a space

6) Write down the output of commands given below

a
Jan

b C1own Gi1d

| = pipe operator: take ouput of the command on its LHS and pass it as input to the
command on its RHs

Tr – translate characters
R to l
B to g
$ cat users
Andrew Roberts
Smith Samson Adams smith
Adams smith
Paul Alert
Smith Martinet

$ grep “smith” users | sort -

However, note that grep is case-sensitive by default, so it will only match "smith" and not "Smith".

sort -: This part of the command is intended to sort the output from grep.

You might also like