Delete directory linux command

Delete directory linux command

To delete directory Linux run command:
rmdir dir1
rmdir /tmp/foo/
rmdir ~/Downloads/mp3s/

The directory must be empty to delete it. You can only delete or remove the DIRECTORY(ies), if they are empty. Otherwise you will get an error message on screen. To delete non empty directory including all files and subdirectories run:
rm -rf dir1
rm -rf /tmp/foo/
rm -rf ~/Downloads/a1040356326d175c20016ff81f62df24

To move DIRECTORY and its ancestors:
rmdir -p dir1/foo/bar
To get a diagnostic for every directory processed:
rmdir -v dir1
OR
rm -rf -v dir1
You can get prompt before every removal all files and dirs:
rm -rfi dir1
To remove a dir whose name starts with a ‘-‘, for example ‘-bar’, use one of these commands:
rm -rf -- -bar
rm -rf ./-bar

To get more help run:
rmdir --help
Outputs:

Usage: rmdir [OPTION]... DIRECTORY...
Remove the DIRECTORY(ies), if they are empty.
 
      --ignore-fail-on-non-empty
                  ignore each failure that is solely because a directory
                    is non-empty
  -p, --parents   remove DIRECTORY and its ancestors; e.g., 'rmdir -p a/b/c' is
                    similar to 'rmdir a/b/c a/b a'
  -v, --verbose   output a diagnostic for every directory processed
      --help     display this help and exit
      --version  output version information and exit

rm --help
Sample outputs:

Usage: rm [OPTION]... [FILE]...
Remove (unlink) the FILE(s).
 
  -f, --force           ignore nonexistent files and arguments, never prompt
  -i                    prompt before every removal
  -I                    prompt once before removing more than three files, or
                          when removing recursively; less intrusive than -i,
                          while still giving protection against most mistakes
      --interactive[=WHEN]  prompt according to WHEN: never, once (-I), or
                          always (-i); without WHEN, prompt always
      --one-file-system  when removing a hierarchy recursively, skip any
                          directory that is on a file system different from
                          that of the corresponding command line argument
      --no-preserve-root  do not treat '/' specially
      --preserve-root   do not remove '/' (default)
  -r, -R, --recursive   remove directories and their contents recursively
  -d, --dir             remove empty directories
  -v, --verbose         explain what is being done
      --help     display this help and exit
      --version  output version information and exit

Examples and usage: Delete / Remove a Directory Linux Command