delete directory linux terminal code example
Example 1: how to forcefully delete a directory in linux
rm -rf dirname
Example 2: remove directory linux
unlink filename
rm filename
rm filename1 filename2 filename3
rm -d dirname
rmdir dirname
rm -r dirname
rm -rf dirname
rm -r dirname1 dirname2 dirname3
Example 3: remove directory from linux
rm -r filename
rm -rf filename
this command remove the directory and subdirectory forecefully
Example 4: sudo rmdir recursive
sudo rm -r -f /path/
Example 5: how to remove folder from linux terminal
To remove an empty directory, use the rmdir command as follows:
$ rmdir foldername
If the directory still contains files or subdirectories, the rmdir command does not remove the directory.
To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r.
$ rm -r foldername