That much is intended behavior, but some users have reported cases where they faced this error despite using rmdir on an empty directory. This happens due to reasons like file system errors or broken symbolic links. We’ve detailed various ways to solve or work around this error on both Linux and Windows systems in the sections below.

Fix Rmdir Directory Not Empty Error on Linux

The easiest fix is to use the rm command instead of rmdir. If this workaround doesn’t appeal to you, or the rm command doesn’t work either, the rest of the solutions will be helpful.

Use rm Command

The base syntax for the rm command is rm . The -d flag removes the directory if it’s empty. But in the case of non-empty directories, you can use the -r flag to recursively delete the specified directory and its contents.

For instance, here’s a basic example:rm -r directoryTo force delete a directory, add the -f flag as such:rm -rf directoryIf your directory path or name contains spaces, use quotes “” as such:rm -rf “directory”Add sudo to resolve any permission issues as such:sudo rm -rf directory

Finally, make sure you don’t use sudo rm -rf / as this would cause the contents of the root directory, i.e., every mounted filesystem, to be deleted.

Delete via GUI

When things don’t work in the GUI, we turn to the command line. As unusual as this may sound, things are the opposite in this case. Numerous users have reported that deleting the folder via the File Browser worked for them. It’s worth trying this before checking out the other solutions.

Check File System

File system errors are a common reason for file deletion and similar issues. As such, using the fsck (File System Consistency Check) utility can be helpful. Here are the necessary steps for this:

Delete from Fileserver

There have been cases where the directory couldn’t be deleted because it was part of a filesystem mounted with CIFS (Samba). As there was a file that was a broken symbolic link, ls failed to mention it. Over CIFS, you wouldn’t be able to see this and thus could be mistakenly assuming that the directory is empty. In such cases, you would need to delete the file directly from the fileserver.

Node Fixes

Users have reported cases where the directory was open in a node.js app or where a node server was periodically accessing the files in the directory, causing minor meta files to exist inside the directory constantly. In such cases, shutting down the application or server that’s accessing the directory at the moment would resolve the issue.

Fix Rmdir Directory Not Empty on Windows

While the application slightly differs, the idea behind fixing this error on Windows is very similar to the methods listed for Linux.

Resolve Common Issues

First, make sure no process is currently accessing the directory. Also, make sure you’re not trying to delete the directory you’re currently on, as that would also prompt this error. In such cases, change to a different directory before trying this. Using the CHKDSK utility to resolve any file system issues has fixed this error for numerous errors. You can do the same with the chkdsk /f /r /x command.

Work Around the Error

Rmdir’s /s flag is meant to let you delete the specified directory and all the subdirectories and files. You can try a couple of things in cases where this doesn’t work as intended. You could delete the contents of the directory before deleting the directory itself as such: Alternatively, you could also try repeating the operation as shown below. Assuming there aren’t any permission issues, you should be able to delete the directory:

How To Fix  Rmdir  Directory Not Empty  Error In Linux - 25How To Fix  Rmdir  Directory Not Empty  Error In Linux - 24How To Fix  Rmdir  Directory Not Empty  Error In Linux - 86How To Fix  Rmdir  Directory Not Empty  Error In Linux - 63How To Fix  Rmdir  Directory Not Empty  Error In Linux - 11


title: “How To Fix Rmdir Directory Not Empty Error In Linux” ShowToc: true date: “2022-11-28” author: “Sarah Cary”


That much is intended behavior, but some users have reported cases where they faced this error despite using rmdir on an empty directory. This happens due to reasons like file system errors or broken symbolic links. We’ve detailed various ways to solve or work around this error on both Linux and Windows systems in the sections below.

Fix Rmdir Directory Not Empty Error on Linux

The easiest fix is to use the rm command instead of rmdir. If this workaround doesn’t appeal to you, or the rm command doesn’t work either, the rest of the solutions will be helpful.

Use rm Command

The base syntax for the rm command is rm . The -d flag removes the directory if it’s empty. But in the case of non-empty directories, you can use the -r flag to recursively delete the specified directory and its contents.

For instance, here’s a basic example:rm -r directoryTo force delete a directory, add the -f flag as such:rm -rf directoryIf your directory path or name contains spaces, use quotes “” as such:rm -rf “directory”Add sudo to resolve any permission issues as such:sudo rm -rf directory

Finally, make sure you don’t use sudo rm -rf / as this would cause the contents of the root directory, i.e., every mounted filesystem, to be deleted.

Delete via GUI

When things don’t work in the GUI, we turn to the command line. As unusual as this may sound, things are the opposite in this case. Numerous users have reported that deleting the folder via the File Browser worked for them. It’s worth trying this before checking out the other solutions.

Check File System

File system errors are a common reason for file deletion and similar issues. As such, using the fsck (File System Consistency Check) utility can be helpful. Here are the necessary steps for this:

Delete from Fileserver

There have been cases where the directory couldn’t be deleted because it was part of a filesystem mounted with CIFS (Samba). As there was a file that was a broken symbolic link, ls failed to mention it. Over CIFS, you wouldn’t be able to see this and thus could be mistakenly assuming that the directory is empty. In such cases, you would need to delete the file directly from the fileserver.

Node Fixes

Users have reported cases where the directory was open in a node.js app or where a node server was periodically accessing the files in the directory, causing minor meta files to exist inside the directory constantly. In such cases, shutting down the application or server that’s accessing the directory at the moment would resolve the issue.

Fix Rmdir Directory Not Empty on Windows

While the application slightly differs, the idea behind fixing this error on Windows is very similar to the methods listed for Linux.

Resolve Common Issues

First, make sure no process is currently accessing the directory. Also, make sure you’re not trying to delete the directory you’re currently on, as that would also prompt this error. In such cases, change to a different directory before trying this. Using the CHKDSK utility to resolve any file system issues has fixed this error for numerous errors. You can do the same with the chkdsk /f /r /x command.

Work Around the Error

Rmdir’s /s flag is meant to let you delete the specified directory and all the subdirectories and files. You can try a couple of things in cases where this doesn’t work as intended. You could delete the contents of the directory before deleting the directory itself as such: Alternatively, you could also try repeating the operation as shown below. Assuming there aren’t any permission issues, you should be able to delete the directory:

How To Fix  Rmdir  Directory Not Empty  Error In Linux - 81How To Fix  Rmdir  Directory Not Empty  Error In Linux - 49How To Fix  Rmdir  Directory Not Empty  Error In Linux - 87How To Fix  Rmdir  Directory Not Empty  Error In Linux - 70How To Fix  Rmdir  Directory Not Empty  Error In Linux - 19