Linux Experiment 3: Directory Operations – Questions and Answers

Task: Use commands to complete the following operations

1. Create directories<span>/home/guestuser1/work1</span> and <span>/home/guestuser/work2</span>

mkdir /home/guestuser1/work1 /home/guestuser/work2

2. Change the current directory to<span>/home/guestuser/work1</span>

cd /home/guestuser/work1

3. Display the current path:

pwd

4. Switch to the root directory;

cd /

5. Display all contents in the current directory (including hidden files);

ls -a
# or
ll -a

6. Change the permissions of the work1 directory to allow all users to access it

chmod 777 /home/guestuser1/work1

7. Use<span>mkdir</span> to create the following directories:

    root -->|test1
    root -->|test2| abcd
    root -->|myjava

Implementation:

mkdir test1
mkdir -p test2/abcd
mkdir myjava

8. Use<span>cd</span> command to sequentially enter the directories <span>test1, test2, abcd, myjava</span> starting from <span>root</span>, and use <span>pwd</span> to verify;

cd /test1 && pwd
cd test2 && pwd
cd abcd && pwd
cd myjava && pwd

9. Use<span>cd ..</span> command to return to the root directory from <span>myjava</span>, and use <span>pwd</span> to verify;

cd /test1
cd test2
cd abcd
cd myjava
pwd  

10. Use<span>rmdir</span> to delete the subdirectory <span>abcd</span>:

rmdir /test1/test2/abcd

11. Use<span>ls</span> command to display detailed information about the files in the <span>root</span> directory. Describe what the permissions of test1 represent

ls -l /root  

Permission explanation (output shows drwxr-xr-x):

  • d: indicates that test1 is a directory.
  • rwx: the owner has read, write, and execute permissions.
  • r-x: the group has read and execute permissions, but no write permissions.
  • r-x: other users have read and execute permissions, but no write permissions.

12. Change the access permissions of test1 so that all users can add and delete files within it.

chmod 777 /test1

13. Change the access permissions of test2 so that other users in the same group cannot enter or add/delete files, but can only view.

chmod g-wx /test1/test2

Leave a Comment