How to remove non empty Directory in Linux

I am trying to delete a directory in Linux using the rmdir command. However, I am getting an error message that read as follows:rmdir: failed to remove 'trip-pictures': Directory not empty How can I remove non empty directory in Linux using the cli? There are two commands that one can use to delete directories in Linux operating system:

Adblock detected 😱

My website is made possible by displaying online advertisements to my visitors. I get it! Ads are annoying but they help keep this website running. It is hard to keep the site running and producing new content when so many people block ads. Please consider donating money to the nixCraft via PayPal/Bitcoin, or become a supporter using Patreon.

rmdir command – Delete directory only if it empty

rm command – Delete directory and all files even if it is NOT empty

Procedure to remove non empty directory in Linux

The syntax is:rm -rf dir-name rm -rf /path/to/dir/name Be careful when you use the rm command with -r and -f options. The -r option remove directories and their contents recursively including all files. The -f option to rm command ignore nonexistent files and arguments, never prompt for anything. There is no undo option. So you have to be very careful with rm -rf command. Let us see some examples.

To get prompt once before removing more than three files, or when removing recursively; less intrusive than -i, while still giving protection against most mistakes pass the -I option:rm -Ir bar Sample outputs:

rm: remove 1 argument recursively? y

For more info see the rm and rmdir command man pages by typing the following command:man rm man rmdir

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Your support makes a big difference:

I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft takes a lot of my time and hard work to produce. If everyone who reads nixCraft, who likes it, helps fund it, my future would be more secure. You can donate as little as $1 to support nixCraft: