Download as pdf or txt
Download as pdf or txt
You are on page 1of 35

Table of Contents

1. Introduction ............................................................................................................1
2. Objective ................................................................................................................2
3. Transcript ...............................................................................................................3
3.1. Creating New Directories ...............................................................................3
Task 1 .................................................................................................................3
3.2. Removing Existing Files and Directories .......................................................4
Task 2 .................................................................................................................4
Task 3 .................................................................................................................4
3.3. Usage of the echo command ...........................................................................5
Task 4 .................................................................................................................5
Task 5 .................................................................................................................6
Task 6 .................................................................................................................6
3.4. Usage of ls command ......................................................................................7
Task 7 .................................................................................................................7
Task 8 .................................................................................................................8
3.5. Usage of the cat command ............................................................................10
Task 9 ...............................................................................................................10
Task 10 .............................................................................................................11
Task 11 .............................................................................................................11
Task 12 .............................................................................................................12
Task 13 .............................................................................................................13
3.6. Usage of the chmod command ......................................................................13
Task 14 .............................................................................................................13
Task 15 .............................................................................................................16
3.7. Usage of the grep command .........................................................................19
Task 16 .............................................................................................................19

i
3.8. Aliasing .........................................................................................................22
Task 17 .............................................................................................................22
Task 18 .............................................................................................................23
Task 19 .............................................................................................................24
Task 20 .............................................................................................................25
Task 21 .............................................................................................................26
Task 22 .............................................................................................................26
3.9. Usage of your own commands......................................................................27
Task 23 .............................................................................................................27
Task 24 .............................................................................................................27
Task 25 .............................................................................................................27
3.10. Command history ........................................................................................27
Task 26 .............................................................................................................27
Task 27 .............................................................................................................30
Task 28 .............................................................................................................30
4. Conclusion ...........................................................................................................31

ii
Table of figures
Figure 1: File Structure ..............................................................................................3
Figure 2: Creating Directory ......................................................................................3
Figure 3: Changing into Miami directory and Creating Files ...................................4
Figure 4: Removing Existing File and Directory ......................................................4
Figure 5: Echo command and Changing to Lakers directory ....................................5
Figure 6: Command pwd; cd; pwd.............................................................................6
Figure 7: Command pwd; cd ..; pwd; cd ..; pwd........................................................6
Figure 8: Usage of cd; pwd command .......................................................................7
Figure 9: Usage of ls command .................................................................................7
Figure 10: Usage of ls -a command ...........................................................................7
Figure 11: Usage of ls -al command ..........................................................................8
Figure 12: Usage cd; pwd; cd cw2; pwd command ...................................................8
Figure 13: Usage of ls -R command ..........................................................................9
Figure 14: Creating file using cat utility ..................................................................10
Figure 15: Displaying file using cat utility ..............................................................11
Figure 16: Copying files to Brooklyn nets directory ...............................................11
Figure 17: Concatenating files using cat testX testY testZ command .....................12
Figure 18: Concatenating files using cat testX testY testZ > testResult command.12
Figure 19: Using 'cat test[XYZ]' command .............................................................13
Figure 20: Displaying access permissions for files .................................................13
Figure 21: Removing the access permission for testX file ......................................14
Figure 22: Displaying permission access for testX file ...........................................14
Figure 23: Reading file using cat utility ..................................................................14
Figure 24: Writing into file using cat utility ............................................................14
Figure 25: Adding read and write permission for file testX ....................................15
Figure 26: Displaying access permission for the file testX .....................................15
Figure 27: Reading testX file using cat utility .........................................................15
Figure 28: Writing into testX file using cat utility ..................................................15
Figure 29: Changing to NBA directory ...................................................................16
Figure 30: Displaying access permission for Chicago Bulls ...................................16
Figure 31: Removing all access permissions for Chicago Bulls .............................16
Figure 32: Displaying access permissions for Chicago Bulls .................................16
Figure 33: Reading file using cat utility ..................................................................17
Figure 34: Putting a file in Chicago Bulls using touch utility .................................17
Figure 35: Searching in Chicago Bulls ....................................................................17

iii
Figure 36: Granting all permissions for Chicago Bulls ...........................................17
Figure 37: Displaying access permissions for Chicago Bulls .................................17
Figure 38: Reading file using cat utility ..................................................................18
Figure 39: Putting file into Chicago Bulls using touch command ..........................18
Figure 40: Searching in Chicago Bulls using ls command ......................................18
Figure 41: Changing to Brooklyn nets directory .....................................................19
Figure 42: Using 'grep bb testX' command..............................................................19
Figure 43: Using 'grep –v bb testX' command.........................................................19
Figure 44: Using 'grep –n bb testX' command.........................................................20
Figure 45: Using 'grep –l bb *' command ................................................................20
Figure 46: Using 'grep –i bb *' command ................................................................20
Figure 47: Using 'grep –i BB *' command...............................................................21
Figure 48: Using 'grep –c bb *' command ...............................................................21
Figure 49: Using 'grep ‘^A’*' command ..................................................................21
Figure 50: Using 'grep –n ‘^’testX' command .........................................................22
Figure 51: Defining and displaying alias .................................................................22
Figure 52: Using lsaR in home directory .................................................................23
Figure 53: Using lsa in home directory ...................................................................23
Figure 54: Showing system does not store aliases. ..................................................23
Figure 55: Removing alias .......................................................................................24
Figure 56: Checking if the system stores aliases or not...........................................24
Figure 57: Defining alias permanently ....................................................................24
Figure 58: System storing permanent alias lsaR ......................................................25
Figure 59: System storing permanent alias lsa ........................................................25
Figure 60: noAllf alias .............................................................................................25
Figure 61: noAsubsir alias .......................................................................................26
Figure 62: noAcs alias..............................................................................................26
Figure 63: Using 'noAllf' command .........................................................................27
Figure 64: Using 'noAsubsir' command ...................................................................27
Figure 65: Using 'noAcs' command .........................................................................27
Figure 66: Creating text file of command history....................................................27
Figure 67: All commands used ................................................................................29
Figure 68: Re-executing command given eight commands ago ..............................30
Figure 69: Re-executing command that begins with 'm'..........................................30

iv
1. Introduction
The main objective of this coursework of Network and Operating System was to
introduce us to relevant UNIX commands, its internal details and practical
implementation and working of Linux as a system. As it was an individual
coursework, we were asked to conduct 28 tasks excluding sub-tasks. We performed
simple-file based operations in UNIX shell by using various commands in the
command line in order to enhance and make us familiar with respect to our
knowledge of the UNIX interface and commands.
We were asked to carry out various tasks using different commands in the terminal
in order to familiarize with the UNIX interface. Displaying and evaluating the
outputs was kind of a mandatory thing in this coursework. This helped us to
understand the UNIX shell operations and its uses. Linux is considered to be the
best-known and most-used open source operating system. It is a software that sits
underneath all of the other software on a computer. Linux is similar to many
operating systems such as Windows, macOS or iOS in many ways. It has a graphical
interface and the same types of software we are accustomed to such as photo editors,
video editors, word processors etc. The versatile thing about Linux is if one can use
computer or any other electronic device, that person can use Linux.
2. Objective
• To introduce to relevant UNIX commands, its internal details and
practical implementation.
• To perform simple file-based operations in UNIX shell following the
given tasks step by step.
• To use command line in order to create files, remove files, insert data
in the file, navigate directories as well as display the contents of the
directory.
• To get familiar with the command and its implementation on the
system.
• To familiarize coursework submission technique for this module
within the given time frame and understand time organization.
3. Transcript
3.1. Creating New Directories
Task 1
Starting from your home directory, create the directory structure shown in Figure 1,
staying in your home directory using relative pathnames.

Figure 1: File Structure

Figure 2: Creating Directory

Checking whether the user is in home directory or not before creating the parent
directory ‘NBA’ is a must. This step was done by using ls / pwd command. The
parent directory ‘NBA’ was created using ‘mkdir’ utility along with five sub-
directories Lakers, Miami, Chicago Bulls, Brooklyn nets and Dallas Maverick.
3.2. Removing Existing Files and Directories
Task 2
Change to the Miami directory typing a relative pathname.
Show that you are in this directory.
Create two files in the Miami directory using any UNIX utility.

Figure 3: Changing into Miami directory and Creating Files

To change the directory and getting into Miami directory, cd command was used.
The pwd command was used to check the path of the directory and to ensure the user
was in right directory. Creating two new files i.e. File1 and File2 was done by using
touch command in Miami directory. ls command was used to show the existing files
in the directory.

Task 3
Change to the NBA directory.
Remove both files and then the Miami directory using the corresponding commands
with the interactive mode (-i) option for the rm command respectively.
Show absence of these files and the directory.

Figure 4: Removing Existing File and Directory


To remove the files from Miami, the user should first exit from that directory by
using ‘cd ..’ command making NBA the working directory. The rm command should
be followed by ‘-i’ and the name of directory where the files are located in order to
remove the file. The –i prompts a confirmatory message from the user before
deleting it. The rm –r command was used to delete the directory Miami and ls was
used to view the directories present in the parent directory.

3.3. Usage of the echo command


Task 4
Print the following strings each in one echo command.
• Hello! I am big fan of NBA finals.
• 14<(2+2)
Now you are still in the NBA directory, give the pwd command. Change to the
Lakers directory typing a relative pathname. Show that you are in this directory.

Figure 5: Echo command and Changing to Lakers directory

The echo command was used to print the given data as strings whereas the pwd
command was used to view the path of directory. The cd commands lets us change
the directory and that’s how the directory was changed into Lakers directory.
Task 5
Give the group of the following commands:
pwd; cd; pwd

Figure 6: Command pwd; cd; pwd

Explanation: The pwd command was used to view the path of the current directory.
The cd command was used in order to change between directories. In this case, the
cd command changed the current working directory to the home directory and finally
the pwd was used again to view the current directory.

Task 6
Change to the Lakers directory again typing a relative pathname. Give the group
of the following commands:
pwd; cd..; pwd; cd..; pwd;

Figure 7: Command pwd; cd ..; pwd; cd ..; pwd

Explanation: The initial pwd command shows the path of the current working
directory that we are in. The ‘cd ..’ command switches to the directory which is one
step back from the current working directory. The pwd command again shows the
new working directory that we are currently in. This step repeats one more time.
3.4. Usage of ls command
Give the following commands and then give a short explanation for each ls
command:
Task 7
• cd; pwd

Figure 8: Usage of cd; pwd command

Explanation: The ‘cd’ command switches to the directory which is one step
back from the current working directory. The pwd command shows the new
working directory that we are currently in.
• ls

Figure 9: Usage of ls command

Explanation: The ls command shows the various files and directories that are
present in the working directory.
• ls —a

Figure 10: Usage of ls -a command

Explanation: The ls command only shows the various files and directories that
are present in the working directory whereas using –a at the end of the
command shows all the hidden as well as non-hidden files and directories.
Mostly hidden files are the files starting with the period and they are generally
system files and application setting files. The user environment settings that
can be changed by the user if needed is in “.bashrc” file.
• ls – al

Figure 11: Usage of ls -al command

Explanation: The ls-al command displays all files and sub-directories in the
current directory, including hidden “.” and “..” etc. details.

Task 8
• cd; pwd; cd cw2; pwd

Figure 12: Usage cd; pwd; cd cw2; pwd command

Explanation: The ‘cd’ command switches to the directory which is one step
back from the current working directory. The pwd command shows the new
working directory that we are currently in. The cd cw2 command tries to
switch to the cw2 directory but since it does not exist, it throws an error and
sends user the “No such file or directory” message and finally the pwd
command shows the current directory location.
• ls – R

Figure 13: Usage of ls -R command

Explanation: The command ls –R lists the directory hierarchies.


3.5. Usage of the cat command
Change to the Chicago Bulls directory.
Task 9
Create three following files using the cat utility:

Figure 14: Creating file using cat utility


Task 10
Display each of these files using the cat utility.

Figure 15: Displaying file using cat utility

Task 11
Copy these files to the Brooklyn nets directory typing a relative pathname.

Figure 16: Copying files to Brooklyn nets directory


Task 12
Concatenate the files using the following commands:
• cat testX testY testZ

Figure 17: Concatenating files using cat testX testY testZ command

• cat testX testY testZ > testResult

Figure 18: Concatenating files using cat testX testY testZ > testResult command
Task 13
Give the following command:
cat test[XYZ]

Figure 19: Using 'cat test[XYZ]' command

Explanation: The command cat test[XYZ] concatenates the content of testX, testY
and testZ together and displays it.

3.6. Usage of the chmod command


Task 14
Do the following sequence of actions.
• Display the access permissions for files in Chicago Bulls.

Figure 20: Displaying access permissions for files


The details are given on the left side of each file name and the name of the
file is given on the far-right of every line. The details to be checked for the
file permissions are:
✓ The letters and dashes on the far left of each line.
✓ Two columns that have Shraddha on them as shown in figure 20.
The dash (-) denotes that the file is a regular file whereas r denotes the read
permission and w denotes the write permission.

• Remove all the access permissions for the testX file.

Figure 21: Removing the access permission for testX file

The access permissions of the files are removed by chmod command.

• Display access permissions for the testX file.

Figure 22: Displaying permission access for testX file

• Try to read this file using any utility.

Figure 23: Reading file using cat utility

• Try to write into this file using any utility.

Figure 24: Writing into file using cat utility


• Add read and write access permissions for yourself for the testX file.

Figure 25: Adding read and write permission for file testX

• Display access permissions for the testX file.

Figure 26: Displaying access permission for the file testX

• Try to read this file using any utility.

Figure 27: Reading testX file using cat utility

• Try to write into this file using any utility.

Figure 28: Writing into testX file using cat utility


Task 15
Do the following sequence of actions.
• Change to the NBA directory.

Figure 29: Changing to NBA directory

• Display access permissions for Chicago Bulls directory.

Figure 30: Displaying access permission for Chicago Bulls

• Remove all access permissions for the Chicago Bulls directory.

Figure 31: Removing all access permissions for Chicago Bulls

• Display access permissions for Chicago Bulls.

Figure 32: Displaying access permissions for Chicago Bulls

• Try to read a file from Chicago Bulls using any utility.


Figure 33: Reading file using cat utility

• Try to put a file into Chicago Bulls using any utility.

Figure 34: Putting a file in Chicago Bulls using touch utility

• Try to search in Chicago Bulls using any command.

Figure 35: Searching in Chicago Bulls

• Add read, write, and execute access permissions for yourself for the
Chicago Bulls directory.

Figure 36: Granting all permissions for Chicago Bulls

• Display access permissions for Chicago Bulls.

Figure 37: Displaying access permissions for Chicago Bulls


• Try to read a file from Chicago Bulls using any utility.

Figure 38: Reading file using cat utility

• Try to put a file into Chicago Bulls using any utility.

Figure 39: Putting file into Chicago Bulls using touch command

• Try to search in Chicago Bulls using any command.

Figure 40: Searching in Chicago Bulls using ls command


3.7. Usage of the grep command
Change to the Brooklyn nets directory.

Figure 41: Changing to Brooklyn nets directory

Task 16
Give the following commands and give the explanation of each of the command.
• grep bb testX

Figure 42: Using 'grep bb testX' command

Explanation: Grep stands for Global Regular Expression Print which is a


command-line tool used to search for a string of characters in a specified file
and the search pattern is called a regular expression. After finding a match, it
prints the line with the result. This command searches the file testX and prints
the lines that contains string bb.

• grep –v bb testX

Figure 43: Using 'grep –v bb testX' command

Explanation: grep –v bb testX command displays all the lines that does not
contain bb.
• grep –n bb testX

Figure 44: Using 'grep –n bb testX' command

Explanation: This command prints all the bb pattern along with their
respective line number.

• grep –l bb *

Figure 45: Using 'grep –l bb *' command

Explanation: This command shows all the files that are in the respective
directory.

• grep –i bb *

Figure 46: Using 'grep –i bb *' command

Explanation: This command displays both lower case and upper case bb.
• grep –i BB *

Figure 47: Using 'grep –i BB *' command

Explanation: This command displays all the files as well as its content that has
bb irrespective of its case.

• grep –c bb *

Figure 48: Using 'grep –c bb *' command

Explanation: It counts the number times the pattern bb is seen in a file.

• grep ‘^A’*

Figure 49: Using 'grep ‘^A’*' command

Explanation: It shows the lines that begins with A with its respective file
name.
• grep –n ‘^’testX

Figure 50: Using 'grep –n ‘^’testX' command

Explanation: It shows all the files and their contents with respect to their line
numbers.

3.8. Aliasing
Task 17
Define two alias for the ls command: lsal for the ls-al command and lsa for ls –a
command.
• Show that your system stores them (giving the corresponding command)

Figure 51: Defining and displaying alias

Alias command is generally used to give instruction to the shell while


executing the commands to replace one string with another string. Here, two
temporary aliases are created which is valid till current running terminal
session.
• Use them in your home directory.
Using lsaR in home directory

Figure 52: Using lsaR in home directory

Using lsa in home directory

Figure 53: Using lsa in home directory

Task 18
Remove these aliases.
Show that your system does not store these aliases.

Figure 54: Showing system does not store aliases.


To remove entries from the current user’s list of aliases, the unalias command is
used. It removes aliases created during the current login session. It also suppresses
permanent aliases for the current login session and are restored again after the user
logs in.

Figure 55: Removing alias

Figure 56: Checking if the system stores aliases or not

Task 19
Define the aliases again preserving them for the next session. Stop the session exiting
from the UNIX operating system (log out) and log in again.
The aliases are saved in the user’s shell configuration in order to preserve it in
between the sessions.

Figure 57: Defining alias permanently


Figure 58: System storing permanent alias lsaR

Figure 59: System storing permanent alias lsa

Task 20
Define the noAllf alias for a group of commands counting and displaying the
number of all files in any working directory (including ones with invisible file
names) and put the alias in your environmental file.

Figure 60: noAllf alias


Task 21
Define the noAsubsir alias for a group of commands counting recursively and
displaying the number of all sub-directories encountered for any working directory
(including ones with visible file names) and put the alias in your environmental
file.

Figure 61: noAsubsir alias

Task 22
Define the noAcs alias for a group of commands counting and displaying the
number of all files in your account’s space with the names starting with g, t, and w,
and put the alias in your environmental file. Display all your aliases.

Figure 62: noAcs alias


3.9. Usage of your own commands
Task 23
noAllf

Figure 63: Using 'noAllf' command

Task 24
noAsubsir

Figure 64: Using 'noAsubsir' command

Task 25
noAcs

Figure 65: Using 'noAcs' command

3.10. Command history


Task 26
List your last commands executed giving the any history command.

Figure 66: Creating text file of command history


Figure 67: All commands used
Task 27
Re execute the command given eight commands ago.

Figure 68: Re-executing command given eight commands ago

Task 28
Re execute the last command which name begins with ‘m’.

Figure 69: Re-executing command that begins with 'm'


4. Conclusion
As per the task assigned to us, structured series of LINUX commands were
developed. This coursework has helped us to understand the basics of LINUX as an
operating system and the foundation of it in order to perform complicated and
important tasks in future. As a user coming from the windows operating system and
switching to Linux operating system was a whole new experience. It made me open
to learn about a new platform for studying and working purpose.
The installation of the whole system itself was a learning phase as we were installing
a second operating system inside the pre-existing system. Our module leader Mr.
Badri Lamichhane helped us during the installation process. Being able to
experience Linux system first hand and using its command line to implement various
commands and creating script file at the end has given us a new horizon in the
understanding of operating system and its working mechanism.
Understanding of the command line interface of UNIX system was not an easy task.
Conducting various researches inorder to understand the system was difficult as well
as important at the same time. The main problem faced while doing the coursework
was to implement the code line by line in the terminal and a simple mistake would
lead to a series of tons of errors in the process. There was no way of only correcting
the part where the mistake was made so had to redo the entire task if any mistakes
were made.

You might also like