Professional Documents
Culture Documents
Sampleforpractice 89403
Sampleforpractice 89403
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.
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.
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.
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
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;
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
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
Explanation: The ls command shows the various files and directories that are
present in the working directory.
• ls —a
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
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
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
Task 11
Copy these files to the Brooklyn nets directory typing a relative pathname.
Figure 17: Concatenating files using cat testX testY testZ command
Figure 18: Concatenating files using cat testX testY testZ > testResult command
Task 13
Give the following command:
cat test[XYZ]
Explanation: The command cat test[XYZ] concatenates the content of testX, testY
and testZ together and displays it.
Figure 25: Adding read and write permission for file testX
• Add read, write, and execute access permissions for yourself for the
Chicago Bulls directory.
Figure 39: Putting file into Chicago Bulls using touch command
Task 16
Give the following commands and give the explanation of each of the command.
• grep bb testX
• grep –v bb testX
Explanation: grep –v bb testX command displays all the lines that does not
contain bb.
• grep –n bb testX
Explanation: This command prints all the bb pattern along with their
respective line number.
• grep –l bb *
Explanation: This command shows all the files that are in the respective
directory.
• grep –i bb *
Explanation: This command displays both lower case and upper case bb.
• grep –i BB *
Explanation: This command displays all the files as well as its content that has
bb irrespective of its case.
• grep –c bb *
• grep ‘^A’*
Explanation: It shows the lines that begins with A with its respective file
name.
• grep –n ‘^’testX
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)
Task 18
Remove these aliases.
Show that your system does not store these aliases.
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.
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.
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.
Task 24
noAsubsir
Task 25
noAcs
Task 28
Re execute the last command which name begins with ‘m’.