Brief: This command is used to delete an existing directory/folder in a linux system.
Syntax: rmdir directoryname
Command: rmdir newfolder
Description:
The rmdircommand will delete an existing directory in present working directory. If the user is working in /home/username/ directory then newfolder directory can be deleted using below command.
rmdir /home/username/newfolder .
User can also specify the path where the existing directory needs to be deleted in the rmdir command.
For ex: Assume that user is presently working in /home/username/newfolder , but wants to delete a directory with name student in /home/class/ then following command will do.
rmdir /home/class/student/
Here it is assumed that home and student directory already exist. If any folder in the path mentioned does not exist then an error will be shown.
Note: rmdir command will not work if the directory to be deleted contains some files or directories. But can be achieved by rm -r command.
Arguments:
-p : This argument deleted the existing parent directories also along with the leading directory.
Command : rmdir -p class/student/result
In above command if class and student directory will also be deleted along with result directoy.
-v : Displays the log message for each directory deleted. This parameter is mostly used -p parameter to get information about the directories deleted.
Important Examples:
1. Delete one or more directory in a single command. Try below command
rmdir /home/user/student /home/user/teacher/
output: student and teacher directory gets deleted
2. Delete parent directories along with leading directory and print message against each directory deleted.
rmdir -pv student/classes/bca
output: deletes 3 directories student,classes,bca
Great
ReplyDelete