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

CS314 Lab2

The document provides instructions for using basic Linux commands like pwd, cd, ls, mkdir, echo, cat, mv, cp, and rm to navigate directories, create and manage files and folders, copy, move, and delete files and folders on a Linux system through the command line. Key steps include using pwd to check the current directory, cd to navigate directories, ls to list directory contents, mkdir to create folders, echo to create text files, cat to view file contents, mv to move files and folders, cp to copy files, and rm to delete files and empty or non-empty folders. The rm command requires additional options like -r to delete non-empty folders.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

CS314 Lab2

The document provides instructions for using basic Linux commands like pwd, cd, ls, mkdir, echo, cat, mv, cp, and rm to navigate directories, create and manage files and folders, copy, move, and delete files and folders on a Linux system through the command line. Key steps include using pwd to check the current directory, cd to navigate directories, ls to list directory contents, mkdir to create folders, echo to create text files, cat to view file contents, mv to move files and folders, cp to copy files, and rm to delete files and empty or non-empty folders. The rm command requires additional options like -r to delete non-empty folders.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Jubail University College

Lab – 2

CS314 Operating System

Semester 391
Lab2 – Working with Linux Command Line
Introduction
In this lab, you will use the Linux command line to manage files and folders and perform some
basic administrative tasks.

Recommended Equipment
A computer with a Linux OS, either installed physically or in a virtual machine

Step 1: Access the command line.


a. Log on to a computer as a user with administrative privileges. The account ITEUser is used as
the example user account throughout this lab.
b. To access the command line, click Activities, and type terminal in the search field and press Enter.
The default terminal emulator opens. OR press Ctrl-Alt + T

Step 2: Display the man pages from the command line.


You can display command line help using the man command. A man page, short for manual page, is an
online documentation of the Linux commands. A man page provides detailed information about a command
and all the available options.
a. To learn more about the man page, type man man at the command prompt and press Enter.

Name a few sections that included in a man page.


____________________________________________________________________________________
____________________________________________________________________________________
b. Type q to exit the man page.

.
Lab2 – Working with Linux Command Line

c. Type man cp at the prompt to display the information about the cp command.

What command would you use to find out more information about the pwd command? What is the
function of the pwd command?
____________________________________________________________________________________
____________________________________________________________________________________

Step 3: Create and change directories.


In this step, you will use print work directory (pwd), the change directory (cd), make directory (mkdir), and list
directory (ls) commands.
a. Note: A directory is another word for folder. The terms directory and folder are used interchangeably
throughout this lab.
b. pwd — When you first open the terminal, you are in the home directory of your user. To know which
directory you are in, you can use the “pwd” command. It gives us the absolute path, which means the
path that starts from the root. The root is the base of the Linux file system. It is denoted by a forward
slash( / ). The user directory is usually something like "/home/username".

c. Type pwd at the prompt. What is the current directory?


____________________________________________________________________________________
d. Navigate to the /home/username directory if it is not your current directory. Type cd /home/ITEUser

e. Type ls at the command prompt to list the files and folders that are in the current folder.

f. In the current directory, use the mkdir command to create three new folders: ITEfolder1, ITEfolder2,
and ITEfolder3. Type mkdir ITEfolder1 and press Enter. Create ITEfolder2 and ITEfolder3.

g. Type ls to verify the folders have been created.


Lab – Working with Linux Command Line

f. Type cd ITEfolder3 at the command prompt and press Enter. Which folder are you in now?
____________________________________________________________________________________
Another way to determine your location in the directory tree is to looking at the prompt. In this
example, the prompt, ITEUser@iteuser-VirtualBox:~/ITEfolder3$, provides the name of the current
user, the computer name, the current working directory, and the privilege level.

~/ITEfolder3: is the current working directory. The symbol ~ represents the current user’s home
directory. In this example, it is /home/ITEUser.
$: indicates regular user privilege. If # is displayed at the prompt, this indicates elevated privilege (root).
g. Within the ITEfolder3 folder, create a folder named ITEfolder4. Type mkdir ITEfolder4. Use the
ls command to verify the folder creation.
h. Type cd .. to change the current directory. Each .. is a shortcut to move up one level in the directory tree.
After issuing the cd .. command, what is your directory now?

i. Note: typing cd with no argument always returns you to your home directory. This is very useful if you
are lost in the file system.
____________________________________________________________________________________
What would be the current directory if you issue this command at ITEUser@iteuser-VirtualBox:~$?
____________________________________________________________________________________
Step 4: Create text files.
a. Navigate to the /home/ITEUser/ITEfolder1 (~\ITEfolder1) directory. Type cd ITEfolder1 at the prompt.
b. Type echo This is doc1.txt > doc1.txt at the command prompt. The echo command is used to display
a message at the command prompt. The > is used to redirect the message from the screen to a file.
For example, in the first line, the message This is doc1.txt is redirected into a new file named doc1.txt.
Use the echo command and > redirect to create these files: doc2.txt, file1.txt, and file2.txt.

c. Use the ls command to verify the files are in the ITEfolder1 folder. To determine the file permission
and other information, type the ls –l command at the prompt.

The following figure breaks down the information provided by the ls –l command. The user ITEUser is
owner of file. The user can read and write to the file. The user ITEUser belongs to the group name
ITEUser. Anyone in the group ITEUser has the same permission. The group can read and write to the
file. If the user is not the owner or in the group ITEUser, the user can only read the file as indicated by
the permission for other.

d. Type the man ls command at the prompt. What option would you use to list all the files in the
directory, including the hidden files starting with .?
____________________________________________________________________________________
e. Use the cat command to view the content of the text files. To view the content of doc2.txt, type cat
doc2.txt.
Step 5: Copy, delete, and move files.
a. At the command prompt, type mv doc2.txt ~/ITEfolder2 to move the file doc2.txt to
the /home/ITEUser/ITEfolder2 directory.

b. Type ls at the prompt to verify that doc2.txt is no longer in the current directory.

c. Type cd ../ITEfolder2 to change the directory to ITEfolder2. Type ls at the prompt to verify doc2.txt
has been moved.

d. Type cp doc2.txt doc2_copy.txt to create a copy of doc2.txt. Type ls at the prompt to verify a copy of
the file has been created. Use the cat command to look at the content of doc2_copy.txt. The content in
the copy should be the same as the original file.

e. Now use the mv command to move doc2_copy.txt to ITEfolder1. Type mv doc2_copy.txt


../ITEfolder1. Use the ls command to verify that doc2_copy.txt is no longer in the directory.

f. A copy of doc2.txt can be created and renamed with the cp command. Type cp doc2.txt
../ITEfoler1/doc2_new.txt at the prompt.
g. Type ls ../ITEfolder1 to view the content in ITEfolder1 without leaving the current directory.

h. Change the current directory to ITEfolder1. Type cd ../ITEfolder1 at the prompt.


i. Move file1.txt and file2.txt into ITEfolder3. To move all the files that contain the word file into ITEfolder3
with one command, use a wildcard (*) character to represent one or more characters. Type mv file*.txt
..\ITEfolder3.
j. Now delete doc2_copy.txt from the ITEfolder1 directory. Type rm doc2_copy.txt. Use the ls
command to verify the file deletion.

Step 6: Delete directories.


In this step, you will delete a directory using the rm command. The rm command can be used to delete files
and directories.
a. Navigate to the /home/ITEUser/ITEfolder3 directory. Use the ls command to list the content of the
directory.

b. Use the rm ITEfolder4 to delete the empty directory, and the message rm: cannot remove
‘ITEfodler4/’: Is a directory.

c. Use the man pages to determine what options are necessary so the rm command can delete
directory. Type man rm at the prompt.
What option is needed to delete a directory?
____________________________________________________________________________________
d. Use the rm –d ITEfolder4 command to delete the empty directory and use the ls command to verify
the removal of the directory.

e. Navigate to /home/ITEUser.
f. Now remove the folder ITEfolder3 using the rm –d ITEfolder3 command to delete the non-empty
directory. The message indicates that the directory is not empty and cannot be deleted.

g. Use man pages to find out more information about the rm command.
What option is necessary to delete a non-empty folder using the rm command?
____________________________________________________________________________________
h. To remove a non-empty directory, type the rm –r ITEfolder3 command to delete the non-empty folder.
Use the ls command to verify that directory was deleted.

You might also like