To remove a directory in Linux, you can use either the rmdir
or rm
command.
To use rmdir
, navigate to the parent directory of the directory you want to remove, and then use the rmdir
command followed by the name of the directory you want to remove. For example:
$ cd /path/to/parent/directory $ rmdir directory_to_remove
Note that rmdir
can only remove directories that are empty. If the directory you want to remove is not empty, you will need to use the rm
command with the -r
option to remove the directory and all of its contents. For example:
$ cd /path/to/parent/directory $ rm -r directory_to_remove
The rm
command can also be used to remove individual files. Simply specify the name of the file you want to remove after the rm
command. For example:
$ rm file_to_remove
Be careful when using the rm
command, as it does not have a trash bin or recycle bin and deleted files cannot be recovered. It is always a good idea to use the -i
option to confirm each file before deleting it, especially if you are deleting multiple files at once.
$ rm -i file_to_remove
This will prompt you to confirm each file before it is deleted. You can also use the --verbose
option to display the names of the files being deleted.
$ rm -i --verbose file_to_remove