Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't remove a directory in Unix

I've got a seemingly un-deletable directory in Unix that contains some hidden files with names that start with .panfs. I'm unable to delete it using either of these commands:

rm -R <dir> rm -Rf <dir> 

Does anyone have any suggestions?

like image 252
fugu Avatar asked Jun 05 '13 18:06

fugu


People also ask

How do I force delete a directory in Unix?

To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r . Directories that are removed with the rmdir command cannot be recovered, nor can directories and their contents removed with the rm -r command.

Can't rm is a directory?

Try cd into the directory, then remove all files using rm -rf * . Then try going out of the directory and use rmdir to delete the directory. If it still displays "Directory not empty" that means that the directory is being used. Try to close it or check which program is using it then re-use the command.

How do I completely remove a directory in Linux?

To permanently remove a directory in Linux, use either rmdir or rm command: For empty directories, use rmdir [dirname] or rm -d [dirname] For non-empty directories, use rm -r [dirname]


2 Answers

Try to delete it with root user or use sudo, if you are in trouble

Use rm -rf dir with root account and it will be deleted, since you should be facing a permissions issue.

like image 145
Paulo Fidalgo Avatar answered Sep 23 '22 13:09

Paulo Fidalgo


To those who prefers to separate the options for a full mastering of their linux command lines so

rm -r -f directory_name

rm → remove

-r → recursively

-f → force (includes chmod permissions)

like image 45
marcdahan Avatar answered Sep 23 '22 13:09

marcdahan