LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-21-2022, 12:22 PM   #1
lokeshjoshi
LQ Newbie
 
Registered: Jul 2022
Location: India
Posts: 2

Rep: Reputation: 0
how i deleted Directory in Linux


Hello Everyone, I try to delete a directory by using the rm ./directory, but i am facing an error rmdir: failed to remove `directory': Directory not empty, I do not know why this happen, can anyone please help, how can i delete the directory.

Thank You
 
Old 07-21-2022, 12:26 PM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,918

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
try to understand. You can only remove empty directories by that command, so first you need to remove everything from that dir.
Or you may try to force remove, but that can be dangerous (rm -rf <dir>)
 
1 members found this post helpful.
Old 07-21-2022, 01:07 PM   #3
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,803

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by lokeshjoshi View Post
Hello Everyone, I try to delete a directory by using the rm ./directory, but i am facing an error rmdir: failed to remove `directory': Directory not empty, I do not know why this happen, can anyone please help, how can i delete the directory.
You may think the './directory' is empty but there must be hidden files or hidden directories lurking in there. Try:
Code:
$ find ./directory -ls
to see what's in there that's preventing it from being removable.

Clean those up and you should be able to remove './directory'. Note, though, that the correct command to remove the directory is
Code:
$ rmdir ./directory
If the 'find' command reveals that there are files under './directory' that you no longer need, you could issue
Code:
$ rm -frv ./directory
Warning: the above command recursively walks though './directory' and clobbers everything it finds providing that you own it. Obviously, you would want to be extremely careful using 'rm -frv' if you're logged in as root (where ownership doesn't matter), using it via 'sudo', etc.

I'd suggest reading the manpages for 'rm' and 'rmdir' and making sure the difference between is crystal clear.

Good luck... and be careful.
 
1 members found this post helpful.
Old 07-21-2022, 08:44 PM   #4
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,341
Blog Entries: 28

Rep: Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145
You could use

Code:
rm -r      <----r means recursive
See man rm for more.
 
Old 07-22-2022, 12:45 AM   #5
!!!
Member
 
Registered: Jan 2017
Location: Fremont, CA, USA
Distribution: Trying any&ALL on old/minimal
Posts: 997

Rep: Reputation: 382Reputation: 382Reputation: 382Reputation: 382
First, have a look (for 'hidden' .files) with the -a ls switch

IF you choose the 'dangerous' rm -r
I strongly suggest you include the -i switch!!!

Welcome to beginning Linux @LQ!!!
You might want to look in z-lib.org or your local library or store or search the internet for beginning Linux tutorials. Also, some LQ'ers have good links in their .sig

Best wishes in your LinuxJourney.com

Last edited by !!!; 07-22-2022 at 01:00 AM.
 
Old 08-06-2022, 06:55 AM   #6
lokeshjoshi
LQ Newbie
 
Registered: Jul 2022
Location: India
Posts: 2

Original Poster
Rep: Reputation: 0
Hi thank you for the reply, I also searched this on the internet and found this post, and also the solution provided by the members helps me a lot. to delete the directory I follow this rm -rf directory_name/, this really help me.
 
Old 08-08-2022, 12:21 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,918

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
Quote:
Originally Posted by lokeshjoshi View Post
Hi thank you for the reply, I also searched this on the internet and found this post, and also the solution provided by the members helps me a lot. to delete the directory I follow this rm -rf directory_name/, this really help me.
in that case you might want to mark the thread as solved, also if you wish to say thanks just click on yes.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Partitioned deleted by linux deleted ata.rehman Linux - General 3 04-16-2010 09:56 PM
directory can't be deleted because it's a directory Lord of the Board Linux - Newbie 1 09-06-2006 04:14 AM
Kmail crashes when deleted mail is deleted dufferin Slackware 0 03-21-2005 03:23 PM
deleted linux partition adn the boot loader was deleted also,now i have only gnu grub boris199 Linux - Laptop and Netbook 2 01-29-2005 04:53 PM
write permissions for directory - not accidently move/deleted the directory linuxgamer Linux - Newbie 10 12-02-2003 03:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration