How to Remove Linux Directories

There will be times when you want to remove an entire directory including all subdirectories and files. You can do this in Linux with a few simple commands typed at a command line.

Things You'll Need

  • Linux
Show More

Instructions

  1. Instructions

    • 1

      Open a terminal window. Terminal windows are usually found under Utilities in the Start Menu.

    • 2

      Go to one directory above the directory you want to remove. For example, if your directory tree is /home/user/Documents/oldDocs, and you want to remove oldDocs, you would go to /home/user/Documents.
      cd /home/user/Documents
      or
      cd ~/Documents
      The ~ (tilde) signifies your home directory.

    • 3

      List the contents of the current directory to make sure you are in the correct directory with the following command:
      ls

    • 4

      List the contents of the directory you are going to remove to make sure you are not deleting anything important.
      ls -a oldDocs
      The -a option will show all files, including any hidden files in a directory.

    • 5

      Remove the directory and all its contents:
      rm -r oldDocs
      The -r option specifies that the command should be recursive. It is necessary if there are files in the directory.

    • 6

      If there are no files in the directory, use the following command:
      rmdir oldDocs

Tips & Warnings

  • If your operating system prompts you for a yes/no response for each file while executing the rm command, you can tell it to force the removal of files with the command "rm -rf oldDocs." You can perform the directory removal from your home directory by specifying the exact path to the directory "rm -r /home/user/Documents/oldDocs" or "rm -r ~/Documents/oldDocs."

  • There is no undelete command in Linux. If you are not sure that you really want to delete the files, use the Graphical User Interface (GUI) and place the file in the Trash folder. This folder acts the same as Windows Recycle Bin. Do not use the rm -rf command in the root file system. This will delete your entire file system.

Related Searches:

References

Comments

You May Also Like

  • How to Create a Directory in Linux

    Linux organizes files into directory hierarchies, like most other operating systems. Linux is much more often operated from a "command prompt" than...

  • How to Remove Viruses With Linux

    Few viruses affect the Linux operating system. However, you can still pass viruses to Windows users. There are two free virus scanners...

  • How to Uninstall a Program in Linux

    Linux has many ways to install programs. The graphical package manager, RPMs, the Debian package manager, the apt and yum utilities, and...

  • How to Make a New Directory in Linux

    Directories are an important component of keeping your files and your hard drive organized in Linux. Each directory can have its own...

  • How to Navigate Directories in Linux

    Linux is one of the more popular Unix like operating systems in use today. It is simple to use, even for casual...

  • How to Remove Linux From a Dual Boot System

    Removing an operating system is making a drastic change to your computer. You are removing complicated system files that are tied directly...

  • How to Add a Second Hard Drive in Linux

    Installing an additional hard disk and setting it up for use in a typical Linux environment requires that you are familiar with...

  • How to Remove Programs in Linux

    Linux, an alternative operating system to Windows, is far less user-friendly to new users. Even something as simple as uninstalling a program...

  • How to Delete Web Pages

    Publishing a web page can be a fun, exciting adventure where the publisher shares information with the world. When the time comes...

Related Ads

Featured