0% found this document useful (0 votes)
74 views

Ngkenzi 202367 Lab2oslinux

The document provides instructions for several Linux terminal commands: 1. It shows how to open the terminal, check the user and directory, and describes the prompt. 2. It demonstrates using touch to create files, echo to add text to files and the screen, and more/less to view file contents. 3. The ls command is used with options like -l and -a to list directory contents with different levels of detail. 4. The mkdir and cd commands are used to create and navigate directories, while rmdir removes empty directories. 5. Commands like cp, mv, and rm are used to copy, rename, and delete files while rm -r removes directories and their

Uploaded by

Ng Kenzi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views

Ngkenzi 202367 Lab2oslinux

The document provides instructions for several Linux terminal commands: 1. It shows how to open the terminal, check the user and directory, and describes the prompt. 2. It demonstrates using touch to create files, echo to add text to files and the screen, and more/less to view file contents. 3. The ls command is used with options like -l and -a to list directory contents with different levels of detail. 4. The mkdir and cd commands are used to create and navigate directories, while rmdir removes empty directories. 5. Commands like cp, mv, and rm are used to copy, rename, and delete files while rm -r removes directories and their

Uploaded by

Ng Kenzi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Lab Exercises 2

1. Task : Open a command line shell’s window in Linux GUI (KDE) interface:

Find the ‘terminal emulator’ (computer monitor) icon and double-click. The terminal emulator
(command prompt window) will appear. Type the command in the provided prompt (something
like ~$).

Who are you in the system? (type whoami to identify)


ubuntu
What directory are you in?
/home/ubuntu
What does the prompt look like?

2. Task : Working with files touch command allows creating an empty file without editing.

Create two files named ‘a.txt’ and ‘b.txt’ in the current directory.

• type: touch a.txt


• type: touch b.txt echo command is used to send (print) a text on the screen.

Use echo “sometext”. Print out the text ‘this is a text’ to the computer screen.
• type: echo “this is a text” echo command can be used to send (print) a text to file using

redirection operator (>). Send the text ‘this is a text’ to the file a.txt
• type: echo “this is a text” > a.txt.

You can add more content to the file using echo with redirection operator (>>)

• type: echo “adding more text” >> a.txt

Why don’t we use ‘>’ to add content to the non-empty file? Try it and observe. What happened
to the content of the file?
Because the > is used to send (print) a text to file using redirection operator but not to add
content

more and less command can be used to view the content of a file. View the content of the file
a.txt using more or less

• type: more a.txt


• type: less a.txt What is the difference between the two commands (more and less)?

How to copy the content of a.txt into b.txt using more command?
cp a.txt b.txt

3. Task : Displaying directory’s contents


ls command will list directories and files in a directory

(Tips: use ls –l to show attributes. Entries with directory types are specified with ‘d’ in the
beginning of a line e.g. ‘drwxr-x--- …’. The command displays the related information for the files
and directories, such as the permission, owner, timestamp of the file/directory created etc.)

Show a list of the directories located on a drive.

• type: cd $root change to the root directory


• type: ls What happened?

• type: ls -a
• type: ls -l

Based on your observation, describe the differences between –a and –l switches

What does the -l switch do?


ls -l command, display detailed information of non-hidden files and directories.

4. Task : Create and change a directory

To create directories, use the mkdir command. To change directories, use the cd command. To
move up one level in the directory structure, use the command cd ..

Create an IT directory in the root directory

• type: cd (or cd $root) to change to the root directory


•type: mkdir IT

Verify the creation of the directory


• type: ls Is the IT directory in the list?
yes

How to go into the IT directory?


cd IT

5. Task : Managing Files using cp, mv, rm, rmdir

You can use the cp command to make a copy of a file, with a new name.

Create a dummy file to IT directory (touch lab.doc).


How to verify whether lab.doc file is in the IT directory?

Make a backup of the lab.doc file with other name lab.bak


• type: cp lab.doc lab.bak

How to verify the new backup file and the original file are there?
To rename a file, you can use the mv command. Rename lab.doc to labfile.doc
• type: mv lab.doc labfile.doc

Did the file renamed? How do you know?


Yes ,Check command using ls

Delete files by using the rm command.


• type: rm labfile.doc Is the file deleted?
How do you know?
Because the file does not exist in there

6. Task : Delete a directory

To delete a directory in Linux, use the rmdir directory_name command.

Delete the IT directory


• type: rmdir
it Is the directory deleted? No
Why? The directory is not empty
If your directories can’t be deleted, it might be because the directory is not empty. To remove
non-empty directory (and also for empty directory), use rm -r
• type: rm IT -r
• type Y to confirm the removal of the it directory and all its subdirectories

(Tips: The deletion process will skip the question if using –f switch (force) e.g. rm IT -fr )

Verify directory removal. Is the directory still exists? How do you know? No IT directory existing

7. Task : View currently running process

To view currently running process(es) in user space, use the ps command.


• type: ps

How many process(es) is/are currently running?

A current process can be suspended by pressing Ctrl+Z (e.g. open an application and then
pressing Ctrl+Z will cause the application to stop and display the shell).

• type: vim this will run the vim text editor. Press Ctrl+Z.

To view the stopped process,


• type: ps
When user suspend a process, the process can be brought back by using the command fg. To
bring back the Vim editor,
• type: fg
(to exit vim - press Esc, then type :q and press Enter)

8. Task : Exploring other commands Students are encouraged to search and practice other
commands that are provided by the command prompt shell to have more exposure to the shell
(search from the documentation, Internet, book etc), or study further the commands already
learned. Use man to get help about a specific command e.g. man ls or use -- help switch e.g. ls –
help , and answer the following question (answer either one):

Explain two new options/switches for any two commands that you have learned by showing
examples how you used the commands with the switches.
Su -h is a command used to display a lists of the commands.

su –p [other_user] is to use a different shell or operating environment.

You might also like