CIT050 Index > Assignment Files

Assignment 3–The Linux Filesystem

Read everything before doing anything!

During this exercise, you may use the pwd command at any time to verify where you are in the directory hierarchy, and ls -F to see what files you have. If you are a visual learner, you may want to draw a diagram of the directory hierarchy on a piece of paper and use a coin to mark your current directory.

If you are missing some of the files named in this assignment, you may need to uncompress a2files.tar.bz2 to restore them. Get that file with these commands. There's a blank and a dot at the end of the cp command.

cd
cp ~linux199/a2files.tar.bz2 .

You will want to “rehearse” these steps. Do them a few times until you are sure you know what the correct commands are. Then, do them one more time as the final result to send to the instructor.

Since you may need to re-do commands several times to get everything right, you will need a way to reset everything to the way it was before you started. To do this, type the following command at the command prompt:

~linux199/reset_assignment_files
  1. Log in and type script at the prompt. The system will respond with

    Script started, file is typescript

    This means that the system will start “recording” all your input and output into a file named typescript .

  2. List all the files in your home directory, including hidden files, after you log in.

  3. Create a directory called textfiles

  4. Change to that directory, and create a file named empty.txt by using the touch command (page 89 in second edition, page 94 in third edition).

  5. Change back to your home directory without typing the directory path name! (hint: page 84 second edition, page 89 third edition, first paragraph).

  6. Now create a file named empty2.txt in the textfiles directory, using the touch command with an absolute path name.

  7. Create a directory named subdir in the textfiles directory, using a relative pathname. (Remember, you’re still in your home directory.)

  8. Change directory to textfiles/subdir .

  9. With one command, copy file announce2.txt.bz2 from your home directory to the current directory. Do notuse any absolute pathnames or ~ in your answer. Hint: use .. (and you may have to use it more than once) to get to the home directory, and use . to specify the current directory.

    Note: You created file announce2.txt.bz2 in the previous assignment.

  10. Change directory to your home directory.

  11. Use gunzip to uncompress announce.txt.gz , which you created in assignment 2.

  12. Move files dijkstra.txt and announce.txt to the textfiles directory with one command (Hint: page 90 in second edition, page 94 in thirrd edition)

  13. Copy file /etc/group to your home directory.

  14. Create the directory chap4/permissions with one command. Hint: pages 86-87 in 2nd edition, pages 90-92 in third edition)

  15. In a similar manner, create the directory chap4/temporary with one command.

  16. Change to the chap4 directory and remove the temporary directory.

  17. Without changing directories, create a file permissions/file1 using the touch command.

  18. Without changing directories, try removing directory permissions ; see what kind of an error message you receive.

  19. Change to your home directory.

  20. Copy a file named chapter4a from user linux199 ’s home directory to your current directory. Use the ~ notation to access linux199 ’s home directory, and . for the current directory.

  21. Type exit at the command line to save the script file you started in step 1. The system will respond with:

    Script done, file is typescript
  22. Rename file typescript to part_one

Part Two

For more information about setting file permissions, read this tutorial, especially the sections on using numbers to set file permissions (the last two sections).

Since you may need to re-do commands several times to get everything right, you will need a way to reset everything to the way it was before you started this part of the assignment. To do this, type the following command at the command prompt:

~linux199/reset_assignment_files2

You can use a command like ls -ld filename to see the permissions of a file or directory.

  1. Log in and type script part_two at the prompt. This will put all your input and output into a file named part_two . The system will respond with

    Script started, file is part_two
  2. Change to the chap4/permissions directory (you created it in the previous part of this assignment). The file file1 should already be in that directory.

  3. With one command, create empty files named file2 , file3 , file4 , and file5 .

  4. Create a directory named testdir

  5. Presuming that you do not know its current permissions, use symbolic arguments to add write permission for “other” users to file file1

  6. Presuming that you do not know its current permissions, write a single command to remove execute permissions for “group” and “others” from directory testdir

  7. Presuming that you do not know its current permissions, add write and execute permissions for all users to file2 .

  8. Presuming that you do not know its current permissions, remove write permissions for the “group“ from file2 .

  9. Using symbolic arguments, set the following permissions for file3 . (You can do this all in one command by separating mode specifications with commas, or you can use several commands.) Presume that you do not know the current status of file3, so you can not use the plus or minus signs.

  10. Using numeric notation, set the following permissions for file4 with one chmod command:

  11. Return to your home directory.

  12. Create a hard link to file textfiles/dijkstra.txt ; the link name will be edsger.txt . (Note: If you have done a reset, the textfiles directory does not exist any more; you will have to re-create it and then cp ~/dijkstra.txt textfiles

  13. Do this: ls -li edsger.txt

    The first column will be the inode number for that file. Take note of the number of links to the file (the third column).

  14. Do this: ls -li textfiles/dijkstra.txt

    The first column is the inode number for that file. Look at this number as well as the number of hard links to the file (the third column).

  15. Remove file textfiles/dijkstra.txt . Since that is only one of the two files linked to that inode, the other filename link still exists. You can prove that in the following step:

  16. Show the contents of edsger.txt using cat.

  17. Create a symbolic link to file textfiles/announce.txt ; the link name will be torvalds.txt

  18. Do this: ls -li torvalds.txt

  19. Do this: ls -li textfiles/announce.txt

    Note the different inode numbers and file lengths.

  20. Rename file textfiles/announce.txt to textfiles/message.txt

    Now the file that the symbolic link points has a new name.

  21. Do this: ls -li torvalds.txt

    On most systems, you will see a blinking line, indicating that the symbolic link is broken.

  22. Try showing the contents of torvalds.txt using the cat command.

  23. Now do this:

    echo "Announcing a new product." >> textfiles/announce.txt

    That command re-creates the file that the symbolic link points to.

  24. Try showing the contents of torvalds.txt using the cat command.

  25. Type exit at the command line to save the script file you started in step 1. The system will respond with:

    Script done, file is part_two

Now type this command to join together parts one and two into one large script file. You will learn more about how this works in the next assignment.

cat part_one part_two > file_script

Part Three

In a text file, answer questions 1, 7, 8, and 10 on pages 113-115 (2nd edition) / 120-122 (3rd edition) of the book. For question 8, try removing all permissions from a file and experiment with various file manipulation operations to see what you can and cannot do. For example, can you append to the file? Can you delete it? Can you rename it? Can you copy it to another file name?

In question ten, you must tell me what happens for each class of users for each command. You should give me something like this (it does not have to be in a table). The answers given here are not necessarily the the correct answers; they are just there as an example

commandownergroupother
a) cd command works ok gets message "access denied" gets message "no such directory"
b) ls command ... ... ...
c) cat command ... ... ...

Create a plain text file. I do not want a word processing file of any kind. Name your file in the form lastname_firstname_files.txt

When You Finish

Upload your text file to Moodle. Once the instructor sees the text file, he will know you’ve finished the assignment and he can look at your file_script file. (If you look at it yourself, you’ll see lots of hard-to-read stuff. Don’t get stressed about it.)