Inas Fadzlina Lab3a Dec 16

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 19

LAB 3A: Explore Linux directory

structure using file manager


and using command line
utilities
Program Learning Outcome (PLO 1)
Apply fundamental principles of computing and mathematics to be competent and possess strong understanding
in programming;

Program Learning Outcome (PLO 2)


Demonstrate strong analytical and critical thinking skills to troubleshoot and solve problems within realistic
constraints by applying knowledge, principles and skills in Information Technology

Course Learning Outcome (CLO 2)


Use the various graphical and command line utilities to perform daily tasks and administration to ensure the system
works properly (P4, C3)

Learning Outcomes
By the end of this lab, students should be able to:

1. Navigate the directory structure


2. Navigate the directory structure using cd and pwd
3. View filenames and file types using ls and type
4. Use the wildcards to specify multiple filenames
5. Display the contents of the text files using cat, more, less, head and tail
6. Search text files for regular expressions using grep

THEORY:
The command in managing directories are:
i. cd : change directory use to change between directories.
Syntax:
cd [Options] [Directory]

EXAMPLE OF DESCRIPTION
COMMAND
$ cd / Move to the / directory
$ cd /var/log Change to another folder
$ cd .. move back one folder
$ cd Quickly get back
$ cd Back to your home folder

ii. ls : list short use to list the specified files.


Syntax:
ls [Options]... [File]...

EXAMPLE OF DESCRIPTION
COMMAND
$ ls List the contents of your home directory
$ ls ~ list everything in current directory:
$ ls al list everything in a vertical list:
$ ls -d */ List the directories in the current directory:
$ ls * list ALL subdirectories
iii. pwd : print working directory use to display the path of the current directory.
Syntax:
pwd [-LP]

iv. type : is a shell builtin that display the kind of command the shell will execute, given a particular
command
Syntax:
type [Options] [Command]

View a file using the following commands:


i. cat: Allows you to look, modify or combine a file.
ii. more : file perusal filter for crt viewing.
iii. less: use to display the content of a file page by page.
iv. head: use to view only the first few lines of a file.
v. tail: Delivers the last part of the file.

Search text files for regular expressions using grep


Syntax:
grep text to find file*

TOOLS/SOFTWARE:
- Ubuntu operating system

PROCEDURE:

Activity 1: Navigate the directory structure

1. Launch Ubuntu using VMware.

2. To view the the home folder click on Places > Home Folder
Figure 1: Home folder of user zura
3. To view the directory structure of file system click on File System.

Figure 2: File system of ubuntu

Activity 2: Navigate the directory structure using cd and pwd


1. Launch terminal in ubuntu.

2. To show the name of working directory use command


$pwd

3. To change working directory to Desktop use commamnd


$cd Desktop
print your working directory now.
Spwd

4. To change working directory from Desktop to /home/ubuntu


$ cd ..
@
$cd
@
$cd ~

5. Change the directory to /var/log directory use command


$ cd /var/log
print your working directory now.
$ pwd

6. To change working directory from /var/log to /home/ubuntu


$cd
@
$cd ~

Activity 3: View filenames and file types using ls and type

1. Launch terminal in ubuntu.

2. To display the kind of command the shell will execute with a particular command name.
$ type mkdir

3. To list the contents of your home directory use command


$ ls
4. To list everything in current directory use command
$ ls ~

5. To list everything in a vertical list use command


$ lsal

6. To list the directories in the current directory use command


$ ls -d */

7. To list ALL subdirectories


$ ls *

8. To list file and directory in a vertical list use command


$ls l

Activity 4: Display the contents of the text files using cat, more, less, head and tail

1. Launch the terminal.


2. Create 3 file name try1, try2 and try3. Use command
$touch try1 try2 try3

3. Insert 15 lines of data in file try1, try2 and try3 that had been create. Double click on file to insert
data.

4. Type cat try1 to view the entire file.


$ cat try1

5. Type cat try1 try2 to combine both file.


$ cat try1 try2

6. Type cat try1 try2>>try3 to combine the content of both file try1 and try2 in file try3 which is file
try3 already create.
$ cat try1 try2 >>try3

7. Type cat try1 try2 try3>>combine3 to combine the content of 3 file try1 try2 and try3 in file
combine3 which is file combine3 had not been create yet .
$ cat try1 try2 try3>>combine3

8. Type more combine3 to view file perusal filter for crt viewing.
$ more combine3

9. Type less try1 to to display the content of a file page by page.


$ less combine3

10. Type head try1 to view 10 first line of file (by default).
$ head try1

11. Type head 5 try1 to view 5 first line of file try1.


$ head -5 try1

12. Type tail try1 to view the 10 last line of file (by default).
$ tail try1

13. Type tail -7 try1 to view 7 last line of file try1.


$ tail -7 try1

Activity 5: Search text files for regular expressions using grep

1. Launch the terminal.

2. Create 1 file name grep1


$ touch grep1 grep2

3. Insert data in file grep1 using gedit. Double click the file then insert data example word search

4. To search text files for regular expressions using grep use command
$grep search grep1*

Activity 6: Use the wildcards to specify multiple filenames

1. Launch the terminal.


2. Create 4 file name a.html b.html c.txt d.txt by using command
$ touch a.html b.html c.txt d.txt

3. Wildcards can be combined with other characters to represent parts of strings. For example, to
list a web page file that use .html as extension file by using command
$ ls *.html

4. To list web page file that use .html as extension file and .txt file use command
$ find *.html *.txt

Note: Please delete file that had been create in this lab. Use command :
$ rm try1 try2 try3 combine3 grep1 grep2 a.html b.html c.txt d.txt

Students Name: INAS FADZLINA BINTI MUSTARZAN


Registration Number:03DIP15F1064
Class:DIP4B
Lab Exercise: 3.

1. Draw the directory structure of your Linux File system start from /.
(2 marks)

2. Write the command/output of each below:


i. Change to the directory /etc/apt
Command : cd /etc/apt

ii. Print your working directory


Command : pwd -P
Output :

iii. Move back one folder


Command : cd ..
iv. Back to your home folder
Command : $cd
(5 marks)

3. Print screen the command and output of Activity 3.


2.

3.

4
5
6
7
8

(7 marks)
4. Given 2 file name lab3a.txt and lab3b.txt. By using given file write the command of each below:
i) Combine file lab3a.txt with lab3b.txt.
Command :cat lab3a lab3b
ii) View 3 first line of file lab3a. .txt
Command : head-3 lab3a
iii) View 6 last line of file lab3b.txt
Command :tail-6 lab3b
iv) View file lab3b.txt in page by page.
Command :less lab3b

(4 marks)
v) Write a command to find text diploma in file programme.
Command: : grepdiplomaprogramme*
(1 marks)

vi) Write a command to list all files in .txt


Command: ls~
(1 marks)

You might also like