SnapOverflow

SnapOverflow Logo SnapOverflow Logo

SnapOverflow Navigation

  • Home
  • Server
  • Ubuntu

Mobile menu

Close
  • Home
  • System Administrators
    • Hot Questions
    • New Questions
    • Tags
  • Ubuntu
    • Hot Questions
    • New Questions
    • Tags
  • Help
Home / ubuntu / Questions / 217893
Accepted
naveen
naveen
Asked: 2012-11-16 20:37:24 +0800 CST2012-11-16 20:37:24 +0800 CST 2012-11-16 20:37:24 +0800 CST

How to delete a non-empty directory in Terminal?

  • 772

How do I delete the following directory?

I typed:

rmdir lampp

This error comes up:

rmdir: failed to remove `lampp': Directory not empty

Is there a command to delete all the files in the directory and delete the directory folder?

command-line
  • 4 4 Answers
  • 3974436 Views

4 Answers

  • Voted
  1. Best Answer
    Shantanu Banerjee
    2012-11-16T21:19:53+08:002012-11-16T21:19:53+08:00

    Use the below command :

    rm -rf lampp
    

    It deletes all files and folders contained in the lampp directory.

    In case user doesn't have the permission to delete the folder:

    Add sudo at the beginning of the command :

    sudo rm -rf folderName
    

    Otherwise, without sudo you will be returned permission denied. And it's a good practice to try not to use -f while deleting a directory:

    sudo rm -r folderName
    

    Note: this is assuming you are already on the same level of the folder you want to delete in terminal, if not:

    sudo rm -r /path/to/folderName
    

    FYI: you can use letters -f, -r, -v:

    • -f = to ignore non-existent files, never prompt
    • -r = to remove directories and their contents recursively
    • -v = to explain what is being done
    • 1077
  2. thomasrutter
    2012-11-16T20:56:37+08:002012-11-16T20:56:37+08:00
    rm -R lampp
    

    However, you need to be careful with a recursive command like this, as it's easy to accidentally delete a lot more than you intended.

    It is a good idea to always double-check which directory you're in, and whether you typed the command correctly, before pressing Enter.

    Safer version

    rm -R -i lampp
    

    Adding -i makes it a little safer, because it will prompt you on every deletion. However, if you are deleting many files this is not going to be very practical. Still, you can try this first.

    Note about -f option:

    Many people suggest using -f (combining it into -Rf or -rf), claiming that it gets rid of annoying prompts. However, in normal cases you don't need it, and using it suppresses some problems that you probably do want to know about. When you use it, you won't be warned if your arguments supply a non-existing directory or file(s): rm will just silently fail to delete anything. As a general rule, try first without the -f: if there are problems with your arguments, then you'll notice. If you start getting too many prompts about files without write access, then you can try it with -f. Alternatively, run the command from a user (or the superuser using sudo) that has full permissions to the files and directories you're deleting to prevent these prompts in the first place.

    • 105
  3. papseddy
    2012-11-16T21:38:48+08:002012-11-16T21:38:48+08:00

    There are lots of ways to delete a directory through CLI mode. It depends on which way you are comfortable with.

    rm -rvf /path/to/directory  
    
    • -r = remove directories and their contents recursively
    • -v = explain what is being done
    • -f = ignore nonexistent files, never prompt

    If you are new in Linux, use the man pages of commands (man rm) for more option and more accuracy.

    • 30
  4. Thomas
    2014-09-29T15:00:02+08:002014-09-29T15:00:02+08:00

    I was having some trouble with that today, but I overcame it with sudo.

    Caveat: Be very certain you want to delete the entire thing before using the command below.

    $ sudo rm -R [Directory name]
    

    I successfully did this today, and removed many non-empty directories that I confirmed I didn't want/need.

    I'm using 14.04 LTS

    • -1

Sidebar

Stats

  • Questions 681965
  • Answers 980273
  • Best Answers 280204
  • Users 287326
  • Popular
  • Answers
  • Marko Smith

    How to delete a non-empty directory in Terminal?

    • 4 Answers
  • Marko Smith

    How to unzip a zip file from the Terminal?

    • 9 Answers
  • Marko Smith

    How can I copy the contents of a folder to another folder in a different directory using terminal?

    • 8 Answers
  • Marko Smith

    How do I install a .deb file via the command line?

    • 11 Answers
  • Marko Smith

    How do I run .sh scripts?

    • 16 Answers
  • Marko Smith

    How do I install a .tar.gz (or .tar.bz2) file?

    • 14 Answers
  • Marko Smith

    What command do I need to unzip/extract a .tar.gz file?

    • 8 Answers
  • Marko Smith

    How to list all installed packages

    • 24 Answers
  • Marko Smith

    Unable to lock the administration directory (/var/lib/dpkg/) is another process using it?

    • 25 Answers
  • Marko Smith

    Change folder permissions and ownership

    • 9 Answers
  • Martin Hope
    ubuntu-nerd How to unzip a zip file from the Terminal? 2011-12-11 20:37:54 +0800 CST
  • Martin Hope
    pandisvezia How can I copy the contents of a folder to another folder in a different directory using terminal? 2011-12-11 17:19:37 +0800 CST
  • Martin Hope
    Scott Szretter Where is the cron / crontab log? 2011-08-12 04:06:43 +0800 CST
  • Martin Hope
    TheXed How do I install a .deb file via the command line? 2011-05-07 09:40:28 +0800 CST
  • Martin Hope
    EmmyS What command do I need to unzip/extract a .tar.gz file? 2011-02-09 14:50:41 +0800 CST
  • Martin Hope
    Ivan How to list all installed packages 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra Unable to lock the administration directory (/var/lib/dpkg/) is another process using it? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry How do I determine the total size of a directory (folder) from the command line? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher "The following packages have been kept back:" Why and how do I solve it? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford How can PPAs be removed? 2010-07-30 01:09:42 +0800 CST

Related Questions

Trending Tags

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • Home
  • Questions
    • Hot Questions
    • New Questions
  • Tags
  • Help

Footer

SnapOverflow

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Help

© 2022 SOF-TR. All Rights Reserve