Assignment Detail:- KIT501 ICT Systems Administration Fundamentals
Goal
The main purpose of this fourth practical is to give you familiarity with UNIX file permissions-
Relative AssignmentChanging permissions using relative assignment -adding or subtracting permissions to existing permissions-:
$ chmod u+x file1-txtThis adds x permission to the owner for file1-txt$ chmod ugo+x file1-txtThis adds x permission to the owner, group owner and other users for file1-txt$ chmod a+x file1-txtThis is an alternative for adding x permission for all users -a=ugo, a for all-$ chmod a-x file1-txtThis removes x permission from all users for file1-txt$ chmod a-rwx file1-txtThis removes all permissions from all users for file1-txt
Absolute AssignmentWe can use absolute assignment for changing file permissions, when you want to set permissions explicitly, without worrying about of a file's current permissions- For example:
$ chmod a=r file1-txtThis sets r permission to all users, and removes w and x for all users-$ chmod u=rwx file1-txtThis sets rwx permissions for the owner -group and other are unaffected--$ chmod u=r,g=w,o= file1-txtThis sets r permission for the owner, w for the group and no permissions for other-
The write permission for a directory determines whether you can create or remove files in it- Whether you can modify a file depends solely on whether the file itself has write permission-1- Directory's write permission not set, file's write permission not set:The safest arrangement- The file cannot be deleted nor modifed2- Directory's write permission not set, file's write permission set:The file cannot be deleted, but it can be edited -modified--3- Directory's write permission set, file's write permission not set: The file can be deleted, but it cannot be edited -modified--4- Directory's write permission set, file's write permission set: The file can be deleted, and it can be edited -modified--
A "write-protected" file in UNIX cannot be written to, but it can be removed if the directory haswrite permission-
2- Hands-on Exercises
A-- If the kit501 directory is still under your home directory continue, otherwise you can create it now using mkdir- Then under the directory kit501 make a subdirectory called testdir-B-- Change directory into testdir- Create a text file called file-txt using joe ornano under testdir- Enter any message as the content of the file-
Verify the content of the file$ cat file-txtC-- Check the current file attributes of file-txt-$ ls -l file-txt
Make sure that you understand each piece of information in the output -especially the permissions--
Remove the read permission from the owner/user of the file, and verify the effect$ chmod u-r file-txt$ ls -l file-txt
Then see if you can view the content of the file now$ cat file-txt
Restore the read permission of the file and try to view its content again$ chmod u+r file-txt$ ls -l file-txt$ cat file-txt
Next, remove the write permission from the owner/user of the file, and verify the effect$ chmod u-w file-txt$ ls -l file-txt
Then see if you can use the joe editor to modify the file content- If not, press CTRL-C to exit-
Restore the write permission for the owner-$ chmod u+w file-txt$ ls -l file-txtD-- Use the following commands to change the permissions of file-txt- Verify the effect of each command each time using ls -l- Make sure you understand the permissions represented by each octal number -the first one is done for you-:
$ chmod 666 file-txt$ ls -l file-txtOwner: rw, group: rw, other users: rw
$ chmod 444 file-txt$ ls -l file-txt
$ chmod 646 file-txt$ ls -l file-txt
$ chmod 600 file-txt$ ls -l file-txt
$ chmod 466 file-txt$ ls -l file-txt
$ chmod 251 file-txt$ ls -l file-txt
$ chmod 111 file-txt$ ls -l file-txt
$ chmod 700 file-txt$ ls -l file-txt
$ chmod 000 file-txt$ ls -l file-txt
$ chmod 777 file-txt$ ls -l file-txtE-- Remove file-txt-F-- Check the current attributes of the following file:/etc/passwdG-- Change the permissions of this file to 777- If this is impossible, think about why-H-- Copy this file -/etc/passwd- to your directory testdir-I-- Repeat step G- Think about why you can change the permissions now-J-- Create two more text files and store them under testdir-K-- Set the permissions of all the files stored under testdir to 700 using a single and short command line-L- Under the directory kit501 make another subdirectory named testdir2- Check the current attributes of testdir2-$ ls -l
Make sure that you understand each piece of information in the output -especially the directory permissions--M- Create a text file called file2-txt using joe or nano under testdir2-N- Remove the owner's read permission of testdir2-O- Change into testdir2, use ls to list all the files stored under it- Can you see any????P- Use joe or nano to edit file2-txt- Use cat to verify the added content-Q- Restore the read permission of testdir2- Use ls to list files stored under it again-R- Remove the owner's write permission of testdir2- Change into testdir2- Try to remove file2-txt from testdir2- Can you do it????S- Remove the write permission of file2-txt- Can you then add new content into the text file????T- If somebody asks you to create a file which cannot be modified, and cannot be deleted, you should know how to do it now-U- Restore the write permission of file2-txt- Restore the write permission of testdir2- But remove the owner's execute permission of testdir2- Then try to change directory into testdir2- Can you do it????V- Restore the owner's execute permission of testdir2- Remove testdir2 together with its content-
3- Hands-on Exercises -compressing files-
To conserve disk space you may need to compress large and infrequently used files- The most notable compression programs available in UNIX arebzip2 gzip zip
zip can group multiple files into a single file -called an archive-- For example:
$ zip -r emailsdir emails
This compresses a directory tree under emails directory -including emails itself-, and produces emailsdir-zip, which is a single zip file- Please note, the output file name -emailsdir- is specified by you -the user--gzip can only do this with tar:$ tar -cvf emailsdir-tar emailsThis produces an archive file named emailsdir-tar, with NO compression- You can then usegzip to compress it-
To restore the original directory tree under emails directory, you would use the following:$ tar -xvf emailsdir-tar
A-- Under the directory kit501 create a text file named f1-txt-An easy way for creating a text file is to redirect the output of a command to a single file, like this:$ man pwd > f1-txt
The above command line saves the man pages of pwd into f1-txt- What is the size of this file???? -Use ls -l f1-txt-B-- Use bzip2, gzip, and zip to compress and then decompress f1-txt- Verify the effect of compression using ls -l -check file size before and after compression--
$ bzip2 f1-txt -This produces f1-txt-bz2 and removes the original file-$ ls -l -Check the file size after compression using bzip2-$ bunzip2 f1-txt-bz2 -Decompress to restore the original file-$ ls -l -Verify result of decompression-
$ gzip f1-txt$ ls -l$ gunzip f1-txt-gz$ ls -l
Please note that the zip command requires that you specify the output file name -result of compression-- It also retains the original file after the file is compressed-
$ zip f1-txt-zip f1-txt$ ls -l
You can remove the original file, and then use unzip to restore it:$ rm f1-txt$ ls$ unzip f1-txt-zip$ ls$ rm f1-txt-zip$ lsC-- Create two more text files using:$ man ls > f2-txt$ man man > f3-txtD-- Make a subdirectory called testdir -if it does not exist- and move the three text files into the subdirectory with a single command- Check the sizes of the three files-E-- Use zip to compress the directory tree testdir -produce testdir-zip-- Adirectory tree refers to the directory together with all the files stored under it- How big is
testdir-zip???? Compare the size of this compressed file with the sum of the sizes of the three text files mentioned above-F-- Use gzip to compress the directory tree testdir- You have to use tar first to archive the directory tree -produce testdir-tar-- The output of gzip should be testdir-tar-gz-G-- Compare the sizes of the two compressed files: testdir-zip, testdir-tar-gz- Which one is smaller???? Which compression program is easier to use????H- After you feel confident with using these compression programs, remove all the temporary files and directories -house cleaning-, but keep the directory kit501 so that you can use it again in the future-
Attachment:- ICT Systems Administration Fundamentals-rar
Most Recent Questions