Lab 2A - Linux Command - 2021125721 - Muhammad Shafiq Haqime

You might also like

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

ITT420: System and Network Administration

Lab Exercise 2A
Introduction to Linux Operating System
(10 marks)

Name: Muhammad Shafiq Haqime bin Mohd Isa Student No: 2021125721

Objectives
At the end of this lab exercise students should be able to:
● Identify basic information about the operating system
● Navigate around the file system using command ls, pwd, mkdir, cd, cat
● Explain and assign the required permission to a file or directory
● Explain the syntax for command in unix/linux operating system
● Demonstrate the operations to files i.e create, copy, rename and remove.
● Demonstrate the symbolic and hard link operations.

Instructions: Complete this Lab exercise and answer all the questions. Submit next week.

PART A

Important note: You can learn more about any Linux commands by using the man command. Try
using this to learn more about the echo command: man echo

1. a) What is the prompt of your Linux/Unix that you are currently use? : dollar sign_ (the last
character in the prompt?) _”$”_.
Do you know what is the shell that you are currently using? : Ubuntu

b) Can you change/customize the prompt? : __No__


If yes, then…
Try to change the prompt like this: Hello >>
Write the command: __________________

2. Type the following command at the command prompt and write the output produced.
a. whoami
Output: qime

b. date
Output: Sabtu 12 Nov 2022 01:08:04 +08

c. hostname
Output: qime-virtual-machine

d. ls
Output: Desktop Documents Downloads Music Pictures Public snap
Templates Videos

e. ps
Output:
PID TTY TIME CMD
2545 pts/0 00:00:00 bash
3550 pts/0 00:00:00 ps
RY’2019 Page: 1
f. uname
Output: Linux

g. pwd
Output: /home/qime

3. a) Type the following command:


mkdir ITT420 <enter> then next command
mkdir Itt420 <enter> then next command
mkdir itt420 <enter>

Then, issue this command:


ls <enter>
What happened after the three times command mkdir is executed? : New directory is
created

Explore the ls command by using the “man ls” command to see the options of what
type of list that you want.

b) What the command to ls does? : Display all the files name in the directory

Did you see the directory that you have just created in a)? : Yes

What option you should use to see the difference between a file and a directory? :

Use diff command

4. a) Execute the following command:

cd ITT420 <enter>

pwd <enter> What you see?: Directory path for ITT420 file

Proceed with these commands:


cat > Kamus1
beg kaban
duit okane
dompet saifu
<ctrl-D>

Explain what the above commands do: cat command is entered to open the argument file,
along with several data to be input into the file.

b) We can use the echo command and a feature called command output redirection to create
simple text files. Execute the following command:

echo “this is the first lab using and learning Linux in ITT420” > lesson1

This time use command more to view the content of lesson1. Type: more lesson1. You
can see the differences between cat & less or more if the content of the file is more

RY’2019 Page: 2
than 1 page. Create a file using man followed by any Linux command and redirect the
output to a file namely lesson2.

Type the command you use: echo lesson1 > lesson2

c) Use the mkdir, cd, and pwd commands to make another directory inside ITT420 /
Itt420 /itt420 directories.

Using man mkdir, what is the option that you can use to create sub-directories in a
directory? (e.g. you want to create directories in ITT420 / Itt420 / itt420 directories without
entering the directory?) : mkdir -p ITT420/{Itt420,itt420}

5. Previously we have used cat command in question number 4. Execute the following cat
command:

cat Kamus1 <enter>

What is the difference between the cat command executed in question number 4 and number
5?:

The difference is cat command in question 4 is to input the data into the file, while cat
command in question 5 is to open and read the files to standard output.

Explain what does the cat command actually do: cat command function to read data from the
file and gives their content as output.

Now use the less command to replace the cat command as 5. Can you find the differences
between cat and less?

6. Check what default permission given to Kamus1 file by using below command and write how
the output produced.

ls –l Kamus1

Output: -rw-rw-r-- 1 qime qime 34 Nov 14 20:51 Kamus1

a) From the web or from man command, find the meaning of each displaying permission
when we use ls –l command (there are basically three permissions i.e. r, w and x) and
what option you should use to see all the permissions? :

We can use ls -la command.

PART B

1. a. Go into your home directory.


b. Create two directory called Folder1 and Folder2.
c. Execute the following command:
touch File1
d. Execute the following command:

mv File1 File2
RY’2019 Page: 3
Describe what has happened to File1.
File1 is rename to File2
e. Execute the following command:

mv File2 Folder1
Describe what has happened to File2.
File2 has been move into Folder1
f. Based on the series of command executed above, explain what does the command mv
do exactly?
mv command is used to move a file or directory into one directory or another, or
rename the file or directory

2. a. Go into your home directory


b. Create a file called File3
c. Execute the following command:

rm File3
Observe what has happened to File3.
File3 is removed from the directory list.
d. Execute the following command:

rm Folder2
If you get an error message, write down the error message.
rm: cannot remove 'Folder2': Is a directory
By using man, find out the option that will enable you to execute the above command
successfully.
We can use rmdir to remove empty directory, eg : rmdir Folder2.

3. a. Go into your home directory


b. Create a folder called Folder3
c. Go inside the folder and then create a file called File3
d. Go back into your home directory and then tries to delete Folder3 using the command
you have discover in question 2.
If you get an error message, write down the error message.
rmdir: failed to remove 'Folder3': Directory not empty
e. By using man, find out the option that will enable you to execute the above rm
command successfully.
We can use rm -r to remove non-empty directory, eg: rm -r Folder3.

f. From man pages, what is option “r” for? Try to use it and write down the command
and see the result.
_____________________________________________________________________

RY’2019 Page: 4
4. a. In your home directory, create a file called File4
b. Execute the following command:

cp File4 File5

Describe what has happened to File4


File4 content is copied into File5
c. Still in your home directory, create a folder called Folder4.
d. Execute the following command:

cp Folder4 Folder5

If you get an error message, write down the error message.


cp: -r not specified; omitting directory 'Folder4'
e. By using man, find out the option that will enable you to execute the above cp
command successfully
Command: We can use cp -r to copy a directory to another directory, eg: cp -r Folder4
Folder5

5. a. In your home directory, create a file called File6.


b. Execute the following command:

ln –s File6 File7
c. Describe what has happened to File6 and File7.
File6 is linked with File7
d. Execute the following command:

echo “This is a content inside File6” > File6

e. Read the content of File7, what is the content of File7?


This is the content of File6.
f. Remove File6.
g. Read the content of File7, what is the content of File7 now?

No content is read.

If you get an error message, write down the error message.


cat: File7: No such file or directory
h. Create again file called File6.
i. Execute the following command:

echo “This is a new content for File6” > File6

j. Read the content of File7, what is the content of File7 now?


This is a new content inside File6
RY’2019 Page: 5
k. Based on the above series of command, explain what is the function of the command
ln?
Command ln is used to link one directory/file with another.
l. Explain what is the difference between hard link and soft link.
A hard link is a file all its own, and the file references or points to the exact spot on a
hard drive where the Inode stores the data. A soft link isn't a separate file, it points to
the name of the original file, rather than to a spot on the hard drive

6. a. In your home directory, execute the following command:

file File6

Write down the output of the command: File6: ASCII text

b. Try out the above command with other file and folder inside your home folder. Explain
what is the function of the command file? What are the types of files that are exist in
Linux Operating System? List out and describe them.

Command file is used to determine type of a file. There are several type of file in
Linux Operating System, which are:
- Regular File (PNG Image data, ASCII Text, RAR archive data, etc)
- Directory File
- Block Files
- Character File
- Pipe Files (FIFO)
- Symbol Link Files
- Socket Files

Continue explore by trying other commands. There are abundance of tutorial for
beginners in learning Linux/Unix operating system. Have fun. ☺

RY’2019 Page: 6

You might also like