Week 2 - Assignment Linux PDF

Title Week 2 - Assignment Linux
Course Operating System Fundamentals (GNU/Linux)
Institution Algonquin College
Pages 13
File Size 1.1 MB
File Type PDF
Total Downloads 64
Total Views 133

Summary

CST8207 Linux...


Description

CST8207_Linux System Support

Algonquin College

By: Arsalan

Assignment 2 – Working with Standard Linux commands (Files & Directory manipulation)

Prerequisites • To boot up your CentOS Linux Box and open Terminal

Deliverables •

A MS-Word or pdf file of Q/A and necessary screenshots, to be uploaded in Week2 DropBox



Due date: as written on Dropbox of your lab section

Note: You can open this pdf in MS-Word to answer in front of each questions. Then save as pdf format and upload it into the Dropbox. (Make sure you answer all questions with necessary screen shots, beyond the shadow of doubt. These are performance based questions so you lose mark for each mistake. Make sure you understand what you doing & if you had any question, ask your Lab professor, also take notes from your observation in the lab which helps you a lot in your tests)



Working with Standard Linux commands

 man – help for each command  cd

– change directory

 ls

– list directory content

 touch – create an empty file  rm – delete a file  mv – Rename/Move a file  mkdir – create one or more new empty directories  pwd – show present ( current ) working directory  rmdir – remove empty directories  rm – remove files or non empty directories  less or more - Sending long output into the pagination commands

inux System Support

Algonquin College

By: Arsalan

CST8207_L

man “man” is powerful built in command helps for Linux user, if you need help for Linux command one way is to use man command, e.g. “man pwd” or “man touch ( type “q” to quit reading) Use “space key” to show you the next page of the help file. Try below command

Find DESCRIPTION in man page (looks like below):

a) Read the man page for the pwd command and give its full NAME (one-line description) in your word file as 1.a) answer, do the same for all other questions. Answer: - pwd – printing the name of the other questions. Now the answers to the following questions are under DESCRIPTION in man page: b) What does bold text mean in the SYNOPSIS section of a man page? Answer: - Do not change, just type exactly as shown. c) What does italic text mean in the SYNOPSIS section of a man page? Answer: - italic text are used to indicate replaceable arguments. d) What do square brackets [] mean in the SYNOPSIS section of a man page? Answer: - Brackets [ ] always denote optional switches, arguments, options, etc.

CST8207_Linux System Support

Algonquin College

By: Arsalan

e) What does the pipe symbol | (SHIFT-\) mean in the SYNOPSIS section of a man page? Answer :- the pipe | means or, particularly when inside brackets. Also, Options surrounded by | can not be used together. f) What do three dots (ellipsis) ... mean in the SYNOPSIS section of a man page? Answer :- That means a repeatable argument.

“cd” , “pwd” To traverse (navigate) through the Linux directory from current to another directory we use cd command $ cd [directoryname] Typing cd with no directoryname argument will take you to your personal HOME directory (which is not the same thing as the directory called /home - be careful!). Providing a single directoryname parameter will change your shell's current working directory to the given directory. While you are working with the cd command, watch the shell prompt; it will change to display the basename of the current working directory after each cd command.

Your HOME directory is indicated in the shell prompt by a tilde character:

g) At the command prompt type cd without any parameters. Record here the directory basename shown at the right end of the bash shell prompt: ~ Tilde h) Type pwd at the prompt and record the output here: ___/home/user1_____ i)

cd / This will change the current directory to the top-level “ ROOT” directory. What directory basename is shown in the bash prompt after this command? ____/___

j)

Give the output of the pwd command now: ____/____

k) cd /etc

What directory basename is shown in the bash prompt after this command?

CST8207_L ___etc_____ l)

Give the output of the pwd command now: _/etc___

m) cd .. (Two periods.) This command will “go up” one directory level (to the ROOT). What directory basename is shown in the bash prompt after this command? ________/_____________ n) Give the output of the pwd command now:_ / _ o) cd home/user1 What directory basename is shown in the bash prompt after this command? ~ (tilde)

p) Give the output of the pwd command now: ____/home/user1_______ q) cd /usr/local/bin

What is the basename in the bash prompt after this command? _____bin_____

r) Give the output of the pwd command now: __/usr/local/bin_____ s) cd ../../sbin

What is the basename in the bash prompt after this command? ____local______

t)

Give the output of the pwd command now: _____/usr/local______

u) cd ../local/bin What is the basename in the bash prompt after this command? _____bin_______ v) Give the output of the pwd command now: ____/usr/local/bin________ w) cd ../../bin

What is the basename in the bash prompt after this command? ____local______

x) What is the output of the pwd command now:

CST8207_Linux System Support

Algonquin College

By: Arsalan

Screenshot

ls To list the content of a directory we use ls command, Read the man page for ls to learn more about options. Two important one is : -a to show hidden files and -l (long listing) as follows: •

ls -a -l



ls -la

Perform the following commands and observe output a)

ls /bin/ls

b)

ls -l /bin/ls

c)

ls -lis /bin/ls

d)

ls /home/user1

e)

ls -a /home/user1

f)

ls -al /home/user1

g)

ls -ld /home/user1

CST8207_L

mkdir , touch To create one or more new, empty directories use mkdir command To create new, empty file, use touch command

Execute following commands and use ls to verify what you have created $ mkdir lab2 $ cd lab2 $ mkdir dir1 dir2 $ ls

CST8207_Linux System Support

Algonquin College

By: Arsalan

Screenshot

$ cd dir1 $ ls –a $ touch f1 #create file called “f1” in dir1 directory $ touch f2 #create file called “f2” in dir1 directory $ touch f3 ls –a

#create file called “f3” in dir1 directory $

CST8207_L Screenshot

$ mkdir subdir $ ls –a

Screenshot

CST8207_Linux System Support

$ cd .. $ mkdir parent/child

Algonquin College

Note: two dot means: go up one directory level

By: Arsalan

CST8207_L Screenshot

a) Explain why the above command failed and did not execute as expected: Because “parent directory does not exist. Moreover, “child” directory cant be created in that directory which does not exists. b)

$ mkdir –p parent/child

# look up -p in the man page for mkdir

c) The above command succeeds with no errors. What does the -p option to the mkdir command do? Command -p create the parent directory first before creating child directory. -----------------------------------------------------------------------------------------------------------------------------

rmdir , rm , mv To remove one or more EMPTY directories, use rmdir command Execute following commands and use ls to verify what you have created $ cd $ mkdir lab2A

# create a new, empty sub-directory $ cd lab2A

# make lab2A the current directory $ mkdir dir1 dir2 test

# create three new, empty directories

CST8207_Linux System Support

Algonquin College

$ touch f1 f2 f3 $ ls -l

By: Arsalan

# create three new files # option -l is lower-case letter L, not the digit 1

$ mv f3 f4

#rename f3 to f4

$ ls –l What happened to f3 file? _f3 renames to f4__ $ rmdir test $ rm f1 f2

#delete test directory

f4

#delete f1 f2 f4 files

$ ls Screenshot

$ mkdir

–p

dir1/subdir

parent/child

$ cd dir1 $ rmdir dir2

# this fails with an error message

d) Record the error message: rmdir: failed to remove ‘dir2’: No such file or directory e) Why did the command generate this error message? Explain why the command failed: Because no such file or directory exists.

CST8207_L

$ rmdir ../dir2 $ cd ../dir2

# this fails with an error message

Screenshot

$ cd ..

# two dots means go up one directory level

$ rmdir dir1/subdir $ rmdir dir1 $ ls -l Screenshot

$ rmdir

parent/child

parent

m) Why doesn't the above command produce an error message about the non-empty directory parent? _Because above command has 2 parts. 1st it deleted the child and then parent directory. Or 1st part of the command deleted the “child” and second delete “parent”.

Assignment Practice: 1. Create directory called “Week2” 2. Change to that directory 3. Create following directory structure inside Week2 exactly as you see in the following:

CST8207_Linux System Support

Algonquin College

4. Run ls –l command and take a screenshot of the output and paste it here

 Keep your week 2 directory for next week  After you done, shut down Linux Box gracefully as you learned previously

By: Arsalan...


Similar Free PDFs