Академический Документы
Профессиональный Документы
Культура Документы
2019-20 Autumn
Contents
Table of figure...................................................................................................................................4
Introduction........................................................................................................................................1
Main objectives:............................................................................................................................1
Transcript...........................................................................................................................................2
Assignment Tasks............................................................................................................................2
1) Creating new Directories........................................................................................................2
Task 1:.........................................................................................................................................2
2 ) Removing existing files and directories............................................................................3
Task 2:.........................................................................................................................................3
Task 3:.........................................................................................................................................3
4) Usages of echo command.....................................................................................................4
Task 4:.........................................................................................................................................4
Task 5:.........................................................................................................................................5
Task 6:.........................................................................................................................................5
4. Usage of the ls command.......................................................................................................5
Task 7 :........................................................................................................................................6
Task 8 :........................................................................................................................................7
5. Usage of the cat command....................................................................................................8
Task 9:.........................................................................................................................................8
Task 10:.......................................................................................................................................9
Task 11:.....................................................................................................................................11
Task 12:.....................................................................................................................................11
Task 13:.....................................................................................................................................13
6. Usage of the chmod command..........................................................................................15
Task 14:.....................................................................................................................................15
Task 15:.....................................................................................................................................17
7. Usage of the grep command...............................................................................................19
Task 16:.....................................................................................................................................19
8) Aliasing.....................................................................................................................................24
Task 17:.....................................................................................................................................24
Task 18:.....................................................................................................................................25
Task 19:.....................................................................................................................................25
Task 20:.....................................................................................................................................27
Task 21:.....................................................................................................................................28
Task 22:.....................................................................................................................................29
9) Usage of your own commands...........................................................................................29
Task 23 :....................................................................................................................................29
Task 24:.....................................................................................................................................30
Task 25 :....................................................................................................................................30
10. Command History................................................................................................................30
Task 26:.....................................................................................................................................30
Task 27:.....................................................................................................................................30
Task 28:.....................................................................................................................................31
Conclusion.......................................................................................................................................32
References.......................................................................................................................................33
Table of figure
Figure 1 Structure Needed For this CourseWork.........................................................2
Figure 2Using alias command #ttask 19....................................................................26
Figure 3 Using nano .task20 to definetask.20 in bashrc............................................28
Figure 4 Using nano .task21 noAsubsir alias in .bashrc...........................................28
Figure 5 Using nano .task22 to define noAcs alias in .bashrc...................................29
Network Operating System CS5001NA
Introduction
(Pronounced yoo-niks) UNIX is a popular multi-user, multitasking operating system (OS)
developed at Bell Labs in the early 1970s. Created by just a handful of programmers, UNIX
was designed to be a small, flexible system used exclusively by programmers. [ CITATION
Ban12 \l 1033 ]
Due to its portability, flexibility, and power, UNIX has become a leading operating system for
workstations. Historically, it has been less popular in the personal computer market.
UNIX was one of the first operating systems to be written in a high-level programming
language, namely C. This meant that it could be installed on virtually any computer for which
a C compiler existed. This natural portability combined with its low price made it a popular
choice among universities. It was inexpensive because antitrust regulations prohibited Bell
Labs from marketing it as a full-scale product. [ CITATION web12 \l 1033 ]
Main objectives:
1
Tabsum Khadka
Network Operating System CS5001NA
Transcript
Assignment Tasks
Task 1: Starting from your home directory, create the directory structure shown in Figure 1,
staying in your home directory using relative pathnames.
Show the structure
Stay in your home directory.
Cricket
Home Bangladesh
India
Pakistan
Australia England
2
Tabsum Khadka
Network Operating System CS5001NA
Command :
/home/tabsumkhadkaa> mkdir -p Cricket/{India,Australia,England,Pakistan,Bangladesh}
/home/tabsumkhadkaa> tree
Output
.
├── 18030084cw2paart1
└── Cricket
├── Australia
├── Bangladesh
├── England
├── India
└── Pakistan
Task 3: Change to the Cricket directory. Remove both files of the India directory and then
the India directory using the corresponding command(s) with the Interactive Mode (-i) option
for the rm command respectively.
Show absence of these files and the directory.
Command :
/home/tabsumkhadkaa/Cricket/India> cd ..
3
Tabsum Khadka
Network Operating System CS5001NA
/home/tabsumkhadkaa/Cricket> rm -i India/file1
rm: remove regular empty file 'India/file1'? y
/home/tabsumkhadkaa/Cricket> rm -i India/file2
rm: remove regular empty file 'India/file2'? y
/home/tabsumkhadkaa/Cricket> ls
/home/tabsumkhadkaa/Cricket> ls India
/home/tabsumkhadkaa/Cricket> rm -r India
/home/tabsumkhadkaa/Cricket> ls
Output : Australia Bangladesh England Pakistan
You know that the echo command can be used to print the argument of the command.
Show that you can do it.
Command :
/home/tabsumkhadkaa/Cricket> echo -e 'Cricket is a bat and ball game played between two
teams.\n14<(2+2)
Output : Cricket is a bat and ball game played between two teams. 14 < (2+2)
Now you are still in the Cricket directory. Give the pwd command. Change to the Australia
directory typing a relative pathname. Show that you are in this directory.
Command :
/home/tabsumkhadkaa/Cricket> pwd
/home/tabsumkhadkaa/Cricket
/home/tabsumkhadkaa/Cricket> cd Australia
4
Tabsum Khadka
Network Operating System CS5001NA
/home/tabsumkhadkaa/Cricket/Australia> pwd
/home/tabsumkhadkaa/Cricket/Australia
/home/tabsumkhadkaa/Cricket/Australia>
Task 5: Give the group of the following commands: pwd; cd; pwd Give a short explanation
of the group.
Command :
/home/tabsumkhadkaa> echo -e "Pwd first displays the new directory, which is Australia
directory, and then returns to the home directory using the cd command. The new directory,
which is the home directory is shown againby pwd at last."
Output : Pwd first displays the new directory, which is Australia directory, and then returns
to the home directory using the cd command. The new directory, which is the home directory
is shown againby pwd at last.
5
Tabsum Khadka
Network Operating System CS5001NA
Task 7 :
- Cd;pwd
/home/tabsumkhadkaa> cd;pwd
/home/tabsumkhadkaa
/home/tabsumkhadkaa> echo -e "Since that we are in home directory this command
will be showing our home directory."
Since that we are in home directory this command will be showing our home
directory.
- Ls
/home/tabsumkhadkaa> ls
Output : This command is used to list information about files and directories within
the file system.
- Ls -a
/home/tabsumkhadkaa> ls -a
Output : This command here is used to show the unhidden or the hidden files.
Ls -al
/home/tabsumkhadkaa> ls -al
total 24
Output : drwxr-xr-x 1 tabsumkhadkaa tabsumkhadkaa 4096 Apr 12 14:48 .
drwxr-xr-x 1 root root 4096 Apr 12 14:44 ..
-rw-rw-rw- 1 tabsumkhadkaa tabsumkhadkaa 8192 Apr 12 15:18
18030084cw2paart1
-rw-r--r-- 1 tabsumkhadkaa tabsumkhadkaa 220 Apr 12 14:44 .bash_logout
-rw-r--r-- 1 tabsumkhadkaa tabsumkhadkaa 3526 Apr 12 14:44 .bashrc
drwxrwxrwx 1 tabsumkhadkaa tabsumkhadkaa 4096 Apr 12 15:00 Cricket
-rw-r--r-- 1 tabsumkhadkaa tabsumkhadkaa 807 Apr 12 14:44 .profile
6
Tabsum Khadka
Network Operating System CS5001NA
Output : ls -al command is used to show the description of hidden and unhidden
files.
Task 8 :
cd; pwd; cd Cricket; pwd
/home/tabsumkhadkaa> cd; pwd; cd Cricket; pwd
/home/tabsumkhadkaa
/home/tabsumkhadkaa/Cricket
/home/tabsumkhadkaa/Cricket> echo -e " At first, cd or change directory command is used
which remains to the home directory.The pwd command then shows the latest working
directory which is home directory. After that cd Cricket changes the directory to Cricket from
home and pwd as we said shows the working directory,so we are still in Cricket directory
after pwd command."
Output : At first, cd or change directory command is used which remains to the home
directory.The pwd command then shows the latest working directory which is home
directory. After that cd Cricket changes the directory to Cricket from home and pwd as we
said shows the working directory,so we are still in Cricket directory after pwd command.
Ls -R
/home/tabsumkhadkaa/Cricket> ls -R
Output :
.:
Australia Bangladesh England Pakistan
./Australia:
./Bangladesh:
./England:
./Pakistan:
/home/tabsumkhadkaa/Cricket> echo -e "This cpmmand is used to show the files recursively
which means we will list folders and thier contents."
7
Tabsum Khadka
Network Operating System CS5001NA
Output : This cpmmand is used to show the files recursively which means we will list folders
and thier contents.
Command :
8
Tabsum Khadka
Network Operating System CS5001NA
/home/tabsumkhadkaa/Cricket/Australia> cat>testZ
aaabb Aaaaa
AAAAA
bbbcc Bbbbb
BBBBB
ff-ff Ccccc
CCCCC
cccdd Ddddd
DDDD
^C
Task 10: Display each of these files using the cat utility.
Command :
/home/tabsumkhadkaa/Cricket/Australia> cat testX
Output
aaabb Aaaaa
9
Tabsum Khadka
Network Operating System CS5001NA
AAAAA
bbbcc Bbbbb
BBBBB
ff-ff Ccccc
CCCCC
cccdd Ddddd
DDDDD
Command :
Command :
Output :
aaabb Aaaaa
AAAAA
bbbcc Bbbbb
BBBBB
ff-ff Ccccc
CCCCC
10
Tabsum Khadka
Network Operating System CS5001NA
cccdd Ddddd
DDDD
Task 11: Copy these files to the Bangladesh directory typing a relative pathname.
/home/tabsumkhadkaa/Cricket/Australia> cp testX ../Bangladesh/
/home/tabsumkhadkaa/Cricket/Australia> cp testY ../Bangladesh/
/home/tabsumkhadkaa/Cricket/Australia> cp testZ ../Bangladesh/
Task 12: Concatenate the files using the following commands (put 2–3 lines with
reasonable contents during the execution of the third command):
Output :
aaabb Aaaaa
AAAAA
bbbcc Bbbbb
BBBBB
ff-ff Ccccc
CCCCC
cccdd Ddddd
DDDDD
aaabb Aaaaa
AAAAA
bbbcc Bbbbb
BBBBB
ff-ff Ccccc
CCCCC
cccdd Ddddd
DDDDD
aaabb Aaaaa
AAAAA
bbbcc Bbbbb
BBBBB
ff-ff Ccccc
CCCCC
cccdd Ddddd
DDDD
11
Tabsum Khadka
Network Operating System CS5001NA
Output :
aaabb Aaaaa
AAAAA
bbbcc Bbbbb
BBBBB
ff-ff Ccccc
CCCCC
cccdd Ddddd
DDDDD
aaabb Aaaaa
AAAAA
bbbcc Bbbbb
BBBBB
ff-ff Ccccc
CCCCC
cccdd Ddddd
DDDDD
aaabb Aaaaa
AAAAA
bbbcc Bbbbb
BBBBB
ff-ff Ccccc
CCCCC
cccdd Ddddd
DDDD
Output :
aaabb Aaaaa
AAAAA
bbbcc Bbbbb
12
Tabsum Khadka
Network Operating System CS5001NA
BBBBB
ff-ff Ccccc
CCCCC
cccdd Ddddd
DDDDD
aaabb Aaaaa
AAAAA
bbbcc Bbbbb
BBBBB
ff-ff Ccccc
CCCCC
cccdd Ddddd
DDDDD
aaabb Aaaaa
AAAAA
bbbcc Bbbbb
BBBBB
ff-ff Ccccc
CCCCC
cccdd Ddddd
DDDD
aaabb Aaaaa
AAAAA
bbbcc Bbbbb
BBBBB
ff-ff Ccccc
CCCCC
cccdd Ddddd
DDDDD
I am Tabsum Khadka
I Study in Islington College
13
Tabsum Khadka
Network Operating System CS5001NA
Output :
aaabb Aaaaa
AAAAA
bbbcc Bbbbb
BBBBB
ff-ff Ccccc
CCCCC
cccdd Ddddd
DDDDD
aaabb Aaaaa
AAAAA
bbbcc Bbbbb
BBBBB
ff-ff Ccccc
CCCCC
cccdd Ddddd
DDDDD
aaabb Aaaaa
AAAAA
bbbcc Bbbbb
BBBBB
ff-ff Ccccc
CCCCC
cccdd Ddddd
DDDD
14
Tabsum Khadka
Network Operating System CS5001NA
Task 14: Do the following sequence of actions. Remember that any action costs 7/9 mark...
/home/tabsumkhadkaa/Cricket/Australia> cd ../
/home/tabsumkhadkaa/Cricket> ls -l Australia
Output :
total 0
-rw-rw-rw- 1 tabsumkhadkaa tabsumkhadkaa 338 Apr 13 14:50 testResult
-rw-rw-rw- 1 tabsumkhadkaa tabsumkhadkaa 72 Apr 13 14:43 testX
-rw-rw-rw- 1 tabsumkhadkaa tabsumkhadkaa 72 Apr 13 14:44 testY
-rw-rw-rw- 1 tabsumkhadkaa tabsumkhadkaa 72 Apr 13 14:45 testZ
/home/tabsumkhadkaa/Cricket> ls -l Australia
Output :
total 0
-rw-rw-rw- 1 tabsumkhadkaa tabsumkhadkaa 338 Apr 13 14:50 testResult
---------- 1 tabsumkhadkaa tabsumkhadkaa 72 Apr 13 14:43 testX
15
Tabsum Khadka
Network Operating System CS5001NA
Output :
bash: Australia/testX: Permission denied
Add read and write access permissions for yourself for the testX file.
Command :
Output :
-rw------- 1 tabsumkhadkaa tabsumkhadkaa 13 Apr 13 14:56 Australia/testX
16
Tabsum Khadka
Network Operating System CS5001NA
Command :
/home/tabsumkhadkaa/Cricket> cat Australia/testX
Output :
aaabb Aaaaa
AAAAA
bbbcc Bbbbb
BBBBB
ff-ff Ccccc
CCCCC
cccdd Ddddd
DDDDD
Task 15: Do the following sequence of actions. Remember that any action costs 9/12
mark...
Change to the Cricket directory.
Command :
/home/tabsumkhadkaa/Cricket/Australia> cd ../
17
Tabsum Khadka
Network Operating System CS5001NA
Output :
ls: cannot open directory 'Australia': Permission denied
Add read, write, and execute access permissions for yourself for the Australia directory.
Command :
18
Tabsum Khadka
Network Operating System CS5001NA
Output :
drwx------ 1 tabsumkhadkaa tabsumkhadkaa 4096 Apr 13 14:49 Australia
Task 16: Give the following commands and give the explanation of each of the command.
No marks without the comparison or an explanation!
-Grep bb testX
/home/tabsumkhadkaa/Cricket/Bangladesh> grep bb testX
19
Tabsum Khadka
Network Operating System CS5001NA
Output :
aaabb Aaaaa
bbbcc Bbbbb
Command :
/home/tabsumkhadkaa/Cricket/Bangladesh> echo -e " The text that contains bb
from the testX file is displayed with the help of this command."
Output :
The text that contains bb from the testX file is displayed with the help of this command.
-grep -v bb testX
/home/tabsumkhadkaa/Cricket/Bangladesh> grep -v bb testX
Output :
AAAAA
BBBBB
ff-ff Ccccc
CCCCC
cccdd Ddddd
DDDDD
/home/tabsumkhadkaa/Cricket/Bangladesh> echo -e " All the text line that contains the text
is displayed from testX except the test containing bb "
Output :
All the text line that contains the text is displayed from testX except the test containing bb
-grep -n bb testX
20
Tabsum Khadka
Network Operating System CS5001NA
Output :
1:aaabb Aaaaa
3:bbbcc Bbbbb
Output :
Texts conatining bb from the file testX is displayed along with thier line number using this
command.
-grep -l bb *
/home/tabsumkhadkaa/Cricket/Bangladesh> grep -l bb
Output :
/home/tabsumkhadkaa/Cricket/Bangladesh> grep -l bb *
testX
testY
testZ
-grep -i bb *
/home/tabsumkhadkaa/Cricket/Bangladesh> grep -i bb *
Output :
testX:aaabb Aaaaa
testX:bbbcc Bbbbb
21
Tabsum Khadka
Network Operating System CS5001NA
testX:BBBBB
testY:aaabb Aaaaa
testY:bbbcc Bbbbb
testY:BBBBB
testZ:aaabb Aaaaa
testZ:bbbcc Bbbbb
testZ:BBBBB
/home/tabsumkhadkaa/Cricket/Bangladesh> echo -e " This command ignores case sensitive
which means it shows all texts conatinng both bb and BB in it with its file name.”
Output
This command ignores case sensitive which means it shows all texts conatinng both bb and
BB in it with its file name.
-grep -I BB*
/home/tabsumkhadkaa/Cricket/Bangladesh> grep -i BB *
Output
testX:aaabb Aaaaa
testX:bbbcc Bbbbb
testX:BBBBB
testY:aaabb Aaaaa
testY:bbbcc Bbbbb
testY:BBBBB
testZ:aaabb Aaaaa
testZ:bbbcc Bbbbb
testZ:BBBBB
22
Tabsum Khadka
Network Operating System CS5001NA
This command here ignores case sensitive which means it shows all texts containing both
BB and bb in it with its file name.
-grep -c bb*
/home/tabsumkhadkaa/Cricket/Bangladesh> grep -c bb *
Output
testX:2
testY:2
testZ:2
/home/tabsumkhadkaa/Cricket/Bangladesh> echo -e " The command above shows the
number of
lines where the pattern matches with the file name in the working directory."
Output :
The command above shows the number of lines where the pattern matches with the file
name in the working directory.
-grep ‘^A’*
Output :
testX:AAAAA
testY:AAAAA
testZ:AAAAA
/home/tabsumkhadkaa/Cricket/Bangladesh> echo -e "All the texts starting with 'A' along with
thier files is displayed by this command ."
Output :
All the texts starting with 'A' along with thier files is displayed by this command .
23
Tabsum Khadka
Network Operating System CS5001NA
-grep -n ‘^’testX
/home/tabsumkhadkaa/Cricket/Bangladesh> grep -n '^' testX
Output :
1:aaabb Aaaaa
2:AAAAA
3:bbbcc Bbbbb
4:BBBBB
5:ff-ff Ccccc
6:CCCCC
7:cccdd Ddddd
8:DDDDD
8) Aliasing
Task 17:
Define two aliases for the ls Command : lsaR for the ls -aR command and lsa
for ls -a command.
Show that your system stores them (giving the correspondent command) Use them in
your home directory
ls -aR to lsar
Command :
/home/tabsumkhadkaa> alias lsar="ls -ar"
/home/tabsumkhadkaa> lsar
Output :
24
Tabsum Khadka
Network Operating System CS5001NA
ls -a to lsa
Command :
/home/tabsumkhadkaa> alias lsa="ls -a"
/home/tabsumkhadkaa> lsa
Output :
. .. 18030084cw2paart1 .bash_logout .bashrc Cricket .profile
Command :
/home/tabsumkhadkaa> unalias lsa
/home/tabsumkhadkaa> lsa
Output :
bash: lsa: command not found
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. Show that the system
keeps these aliases
25
Tabsum Khadka
Network Operating System CS5001NA
/home/tabsumkhadkaa> . .bashrc
tabsumkhadkaa@DESKTOP-6H6TTJ6:~$ script 18030084cw2paart1
Output : Script started, file is 18030084cw2paart1
Output :
.:
. .. 18030084cw2paart1 .bash_logout .bashrc Cricket .local .profile
./Cricket:
. .. Australia Bangladesh England Pakistan testResult
./Cricket/Australia:
. .. abcd testResult testX testY testZ
./Cricket/Bangladesh:
26
Tabsum Khadka
Network Operating System CS5001NA
./Cricket/England:
. ..
./Cricket/Pakistan:
. ..
./.local:
. .. share
./.local/share:
. .. nano
./.local/share/nano:
. ..
/home/tabsumkhadkaa> lsa
Output :
. .. 18030084cw2paart1 .bash_logout .bashrc Cricket .local .profile
Task 20: Define the noAllf alias for a group of commands counting and displaying the
number of all files and directories in any working directory (including ones with invisible file
and directory names) and put the alias in your environmental file.
27
Tabsum Khadka
Network Operating System CS5001NA
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 invisible file and directory names) and put the alias in your environmental file.
28
Tabsum Khadka
Network Operating System CS5001NA
Task 22: Define the noAcs alias for a group of commands counting and displaying the
number of all files and directories 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.
/home/tabsumkhadkaa> noAllf
Output : 8
29
Tabsum Khadka
Network Operating System CS5001NA
Task 24:
/home/tabsumkhadkaa> noAsubsir
Output : 26
Task 25 :
/home/tabsumkhadkaa> noAcs
Output : 8
Output :
559 nano .bashrc
560 unalias lsaR
561 unalias lsa
562 lsaR
563 lsa
564 cat > .bash_aliases
565 . .bashrc
566 PS1='$PWD> '
567 lsaR
568 lsa
569 nano .task20
570 nano .task21
571 nano .task22
572 noAllf
573 noAsubsir
574 noAcs
30
Tabsum Khadka
Network Operating System CS5001NA
/home/tabsumkhadkaa> fc -e- -8
Output :
Lsa
Task 28: Re execute the last command which name begins with ‘c’.
/home/tabsumkhadkaa> fc -e- c
Output : cd
/home/tabsumkhadkaa> exit
exit
Script done, file is 18030084cw2paart1
31
Tabsum Khadka
Network Operating System CS5001NA
Conclusion
This Coursework wasn’t very difficult, It was an excellent way to develop out UNIX
awareness and its different resources such as shell scripting. I took the help of the lecture
slides as a reference. The main purpose of this coursework is to help us studenrs
understand the UNIX operating system.
All the given task are completed successfully without errors and are recorded in the script file
named 18030084cw2paart1. Now with this , some rubbish is also cleaned before finalizing
the report.
32
Tabsum Khadka
Network Operating System CS5001NA
References
Beal, B., 2012. Unix Os, s.l.: s.n.
33
Tabsum Khadka