Starting from:

$30

CSC3320- Lab 3: (Post-Lab) Solved

Purpose: Learn how to set permissions for the files and directories. Practices on editing a file via the vi editor.  

Note: Please follow the instructions below step by step, and then write a report by answering the questions and upload the report (named as Lab3_FirstNameLastName.pdf or

Lab3_FirstNameLastName.doc) to Google Classroom, under the rubric Lab 3 Out-of-lab Assignemnt.    

Please add the lab assignment NUMBER and your NAME at the top of your file sheet.  

Part 1: VI Editing - Small file  

Open your terminal and connect to snowball server. Change your directory to your home directory (cd ~ ), and then create a new directory named as “Lab3” (mkdir Lab3). After that, go to directory Lab3 (cd Lab3) and please download the file  "Try.c" (content shown in table below) by the following command (internet access required):    

 cp                                       /home/bbello1/Public/Try.c                               Try.c  

Be sure it succeeds using “ls” to see the file name “Try.c” listed.   

Try the following steps by issuing some commands in your vi  editor 1) Open "Try.c" with vi editor  

             $vi Try.c  

1  

Move cursor to the beginning of “Error!” use UP DOWN LEFT RIGHT arrow to control cursor    
Insert “xxx”.  
i  

type “xxx” (hit x three times)  

  

Append a blank line after the current line.
 Hit Esc to command mode o (lowercase

o)
  

Delete “xxx”.
Hit Esc to command mode.  

Move cursor to the beginning of "xxx", press x three times or press 3s to delete "xxx"  

Copy the first 2 lines, move cursor to the beginning of file, and then paste it after current line
:1,2y  

          :0 p    

Delete the first 2 lines :1,2d  
Save it
:w  

Replace all "fptr" with "FPTR" :1,$s/fptr/FPTR/g  
Save and exit.
:wq  

 2  

Part 2: VI Editing - Large file  

Go into your Lab3 directory.
$cd ~/Lab3  

Copy "RealEstate.csv" from instructor's public directory to your Lab3 directory
         again.  

$cp /home/bbello1/Public/RealEstate.csv .  

Please write the commands you will issue to complete the following tasks and answering corresponding questions step by step in your report.  3) Use vi to open “RealEstate.csv”. 

Move the cursor to the last line (without knowing the number of last line).
Display line number.
Search for the transaction for the estate located at "111 EAST"

Which line is this string located? (Please just write down the line number) 

Delete this line. 

Move the cursor to the line 50.
Substitute all comma "," with colon ":" from line 50 to line 54.
Copy line 50 to line 54 to the end of file.
Remove line 50 to line 54.
Describe how to enter the text mode and insert a new line "Recorded in year 2008" between line 1 and line 2. 
Switch back to command mode.
Save the file and quit vi. 
3  

Part 3: Permissions for files    

Follow the instructions step by step and finish the questions as required.  1) Go into your Lab3 directory.  

$cd ~/Lab3   

Check the file permissions for file "Try.c" in your own Lab3 directory.
$ls -l Try.c  

You may see similar output as below, in which rw-rw-r-- of the first field is the file permission string for "Try.c".
                                      [bbello1@gsuad.gsu.edu@snowball Lab3]$ ls -l Try.c  

-rw-rw-r--. 1 bbello1@gsuad.gsu.edu bbello1@gsuad.gsu.edu 379 Sep 8 10:44 Try.c    

 The leftmost 3 characters rw- tells us that the user (owner of the file) can only read and write the file.

 The middle 3 characters rw- tells us the other users in the same group as the owner can only read and write the file.

 The last 3 characters r-- tells us the other users in the other groups different from owner can only read the file.

Note: once you copy a file from other directory or download a file from other resources, you are the owner of the new copied or downloaded file.  

Remove the read permission for the owner (yourself).
$chmod u-r Try.c  

Check the file permissions for file "Try.c" again.
$ ls -l Try.c   

You may see similar output as below, in which -w-rw-r-- of the first field is the file permission string for "Try.c".   
                                      [bbello1@gsuad.gsu.edu@snowball Lab3]$ ls -l Try.c  

--w-rw-r--. 1 bbello1@gsuad.gsu.edu bbello1@gsuad.gsu.edu 379 Sep 8 10:49  Try.c  

So -w- in the leftmost 3 characters tells us that the user (owner of the file ) only has the permission to write something into the file.    

Try the vi editor again to modify the file.
$vi Try.c    

4  

However, you may find following message displayed at the bottom of the screen which means you do not have the right to read "Try.c"
Quit vi editor.
:q    

Try read "Try.c" again using cat.
$cat Try.c  

Attach a screenshot of the output.  

Use chmod with an octal number to let all the users only have read permission for "Try.c".  
$chmod 444 Try.c  

Note: The permission string to be set should be r--r--r--. Convert each group of three characters into decimal to form an octal number, which should be 444.  

Check the file permissions for file "Try.c" again. And explain the meaning of each character in the file permission string.
Try the vi editor again to modify the file. Then remove one line by pressing dd
 $vi Try.c  

Move your cursor to some line and press dd   

Try to save the file in the vi editor.
:w  

Can you find some error message at the bottom of the screen? If yes, what is     it and how to quit the vi editor without saving the modification.  
Write answer in your answer sheet.  

Use chmod to add write the permission to all the users for "Try.c".
Write answer in your answer sheet.   

Check the file permissions for file "Try.c" again. And explain the meaning of each character in the file permission string.  
Write answer in your answer sheet.  

 5  

Part 4: Permissions for directories  

  

The permissions also work for the directories. However, the permissions for the directories may have different behaviors.    

Let us learn the permissions for directories by only changing different permissions to the owner of the file.  

Go to your home directory and then check the permissions for directory Lab3.
$cd ~  

$ls -ld ~/Lab3  

Note: -d option will let you check the detailed information for the directory instead of its contents.    

You may see similar output as below, in which rwxrwxr-x of the first field is the permission string for directory Lab3.
Use chmod with octal number to forbid all permissions to all users.
$chmod 000 ~/Lab3  

Check the permissions for directory Lab3. You may see similar output as below. The permission string is changed to ---------.
Finishing the following tasks and fill out the blanks in the row for owner's permission "---" in the table below. If the task or command can be executed successfully, mark Y in the table, otherwise, mark N in the table. Please mark N/A if the task or command is not executed.
Check the contents in directory Lab3.
$ls ~/Lab3  

Create a directory named as "test" in Lab3.
$mkdir ~/Lab3/test   

Create a file named as "test.txt" in Lab3.
$cat>~/Lab3/test.txt  

A test  

^D  

6  

If (B) succeeds, remove the created directory "test" of Lab3.
$rm -r ~/Lab3/test    

If (C) succeeds, copy "test.txt" from your Lab3 into your home directory.
$cp ~/Lab3/test.txt .   

Go into directory Lab3.
$cd ~/Lab3  

The blanks in row "---" have been filled out in the table. Please compare it to your answers.    

6) Fill out the blanks in other rows by repeating 3) to 5) when the owner is assigned different permissions as in the first column of the table. However, when setting the permissions, we still need to forbid all the permissions to all other users. So the last two bits in the octal number should always be kept as 00.  

For example, since owner's permissions is --x at next row, we should first set the file permission by issuing the command chmod  100 ~/Lab3. And then fill out the blanks in the row for  

permissions --x by repeating 5).                                                                                                                                                                            

Owner's permissions  
ls                      
mkdir  
cat >  
rm  
cp  
cd  
A. Read          
B. Create  
C. Create file  
D. Remove  
E. Copy  
F. Enter into  
  

  
contents         

              
sub-directory  

  
  

  
contents  

  
contents from  
directory  

  
---  
N                     
N  
N  
N/A  
N/A  
N  
--x  
              
  
  
  
  
  
-w-  
              
  
  
  
  
  
-wx  
   
r--  
                
r-x  
rw-  
              
  
rwx  
              

Note: Since you need to try at least 56 commands, to save the time, you can press upper arrow or down arrow to repeat previous or next command.  

 7    

Appendix:  

Table: The mapping of permissions of three characters to octal/decimal  

Permissions  
Binary  
Octal/Decimal  
---  
000  
0  
--x  
001  
1  
-w-  
010  
2  
-wx  
011  
3  
r--  
100  
4  
r-x  
101  
5  
rw-  
110  
6  
rwx  
111  
7  
 

More products