Directory Commands
Notes:
Some directory commands:
-
pwd - print working directory
(see navigating the filesystem)
-
cd - change directory (see navigating the
filesystem)
-
ls - display a directory listing (see directory
listings)
-
mkdir - This command creates a new directory. Examples:
-
mkdir sample
-
mkdir /home/abc/sample
-
rmdir -This command removes an existing directory. The directory must
be empty before it can be removed. Example:
Exercises:
-
Load Floppix and login on virtual console 1 using your own initials.
-
How many directories are stored under /var? _____
-
Try to view the contents of the directory /sbin? _____
What error message is displayed? ____________________
Why? ____________________
-
Change to the /var directory. Try to create a directory called ddd.
What error message is displayed? ____________________
Why? ____________________
-
Change to your own home directory and make a directory called ddd there.
This time the command should succeed.
-
Cd to the ddd directory and create a file called fff using the command:
touch fff
-
Try to make a subdirectory called fff using the command: mkdir
fff
What error message is displayed? ____________________
Why? ____________________
-
Still in the ddd directory, try to remove the ddd directory using the command:
rmdir ddd
What error message is displayed? ____________________
Why? ____________________
-
Change to your own home directory. Try to remove the ddd directory using
the command: rmdir ddd
What error message is displayed?____________________
Why? ____________________
-
Delete the file fff using the command: rm ddd/fff
Now remove the ddd directory. This time the command should succeed.
Questions & Answers:
-
What is the command to make a subdirectory called "mine"?
Answer: mkdir mine
-
Give 2 situations where the mkdir cmomand will fail?
Answer: mkdir will fail:
- when you try to make a subdirectory in a directory where you do not have
write permissions
- when a file or a directory already exists with that name
-
Give 2 situations where the rmdir command will NOT remove a directory.
Answer: rmdir will fail
- when the directory is not empty
- when you try to remove the working directory (or any of its parent
directories)
Copyright © L.
M. MacEwan