How To Fix "Rmdir: Directory Not Empty" Error In Linux (2024)

The rmdir command is used to remove empty directories. If you attempt to remove a non-empty directory with this command, you’ll encounter the Rmdir Directory Not Empty error.

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 <options> <file>. 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 directory
    How To Fix "Rmdir: Directory Not Empty" Error In Linux (1)
  • To force delete a directory, add the -f flag as such:
    rm -rf directory
  • If 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
    How To Fix "Rmdir: Directory Not Empty" Error In Linux (2)

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.

How To Fix "Rmdir: Directory Not Empty" Error In Linux (3)

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:

  1. Use the df -h command and note the file system on which you want to run fsck.
  2. Let’s take /dev/sda4 as an example. Use the sudo umount /dev/sda4 command to unmount it. If it’s a root filesystem, you’ll need to boot from a live CD to be able to unmount it.
  3. Next, use sudo fsck /dev/sda4 and accept the prompts to approve the repair actions.
    How To Fix "Rmdir: Directory Not Empty" Error In Linux (4)
  4. After the repair is complete, use the sudo mount /dev/sda4 command to remount the device and check if the issue is resolved now.

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 <drive letter> /f /r /x command.

How To Fix "Rmdir: Directory Not Empty" Error In Linux (5)

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:

del /f /s /q directory 1>nulrmdir /s /q directory

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:

rmdir /s /q c:\directory
if exist c:\directory rmdir /s /q c:\directory
How To Fix "Rmdir: Directory Not Empty" Error In Linux (2024)
Top Articles
What Is Only Child Syndrome? 6 Signs to Look Out For — Best Life
Bronny James: LA Lakers take LeBron James' son in NBA draft second round
123Movies Encanto
Cottonwood Vet Ottawa Ks
New Slayer Boss - The Araxyte
Call of Duty: NEXT Event Intel, How to Watch, and Tune In Rewards
41 annonces BMW Z3 occasion - ParuVendu.fr
Phillies Espn Schedule
Oriellys St James Mn
Slag bij Plataeae tussen de Grieken en de Perzen
Babyrainbow Private
Cvb Location Code Lookup
Check From Po Box 1111 Charlotte Nc 28201
Kp Nurse Scholars
2020 Military Pay Charts – Officer & Enlisted Pay Scales (3.1% Raise)
Lcwc 911 Live Incident List Live Status
Vrachtwagens in Nederland kopen - gebruikt en nieuw - TrucksNL
Satisfactory: How to Make Efficient Factories (Tips, Tricks, & Strategies)
Acts 16 Nkjv
Quadcitiesdaily
Juicy Deal D-Art
Understanding Genetics
Puss In Boots: The Last Wish Showtimes Near Cinépolis Vista
Aes Salt Lake City Showdown
Roane County Arrests Today
Ontdek Pearson support voor digitaal testen en scoren
Jcp Meevo Com
Discord Nuker Bot Invite
Xpanas Indo
Bfsfcu Truecar
897 W Valley Blvd
Tokioof
Alima Becker
Rust Belt Revival Auctions
Tas Restaurant Fall River Ma
Timothy Kremchek Net Worth
House Of Budz Michigan
Instafeet Login
Bianca Belair: Age, Husband, Height & More To Know
WorldAccount | Data Protection
World Social Protection Report 2024-26: Universal social protection for climate action and a just transition
This 85-year-old mom co-signed her daughter's student loan years ago. Now she fears the lender may take her house
The Realreal Temporary Closure
VPN Free - Betternet Unlimited VPN Proxy - Chrome Web Store
Caphras Calculator
Unblocked Games 6X Snow Rider
Terrell Buckley Net Worth
Is TinyZone TV Safe?
Poster & 1600 Autocollants créatifs | Activité facile et ludique | Poppik Stickers
Campaign Blacksmith Bench
Sj Craigs
Swissport Timecard
Latest Posts
Article information

Author: Rob Wisoky

Last Updated:

Views: 5692

Rating: 4.8 / 5 (48 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Rob Wisoky

Birthday: 1994-09-30

Address: 5789 Michel Vista, West Domenic, OR 80464-9452

Phone: +97313824072371

Job: Education Orchestrator

Hobby: Lockpicking, Crocheting, Baton twirling, Video gaming, Jogging, Whittling, Model building

Introduction: My name is Rob Wisoky, I am a smiling, helpful, encouraging, zealous, energetic, faithful, fantastic person who loves writing and wants to share my knowledge and understanding with you.