Skip to content
Technology News Information & Jobs

Technology News Information & Jobs

Ubuntu Tutorials, Ubuntu How To , Linux Tips, Tech Jobs

  • Work with US
  • Search Jobs
  • Post a Job
  • Contact Us
  • Ubuntu
    • Ubuntu 18.04
  • Ubuntu 20.04
  • Ubuntu 22.04
  • Themes
  • Linux
  • Laptops
  • Tutorials
  • Job Dashboard
  • Toggle search form
How To Remove Files And Directories In Linux [Examples]

How To Remove Files And Directories In Linux [Examples]

Posted on March 12, 2022 By admin No Comments on How To Remove Files And Directories In Linux [Examples]

How To Remove Files And Directories In Linux With Examples.
There are multiple ways to remove files and directories in Linux.

How To Remove Files And Directories In Linux [Examples]

Let’s have a look into the methods to remove files and directories in Linux.

How To Remove Files with rm command

You can easily remove any files in Linux with rm command. Yes, it is pretty simple as you can delete a single file in the current directory with rm command.  Open the Linux terminal and type the rm command with the file name that you want to delete.

rm file_to_be_deleted.txt

What If the file is not in the current working directory?

Don’t worry if the file that you want to delete is not in the current working directory as you can provide path to the file’s location to delete the file.

rm ./path/to/the/file/file_to_be_deleted.txt

How To Remove Multiple Files With rm Command At Once

Run the following command if you want to delete more than one file in Linux with rm command.

rm file_to_be_deleted.txt file_to_be_deleted_1.txt

How To Remove Selected Groups Of Files In Linux

You can use the wildcards to select groups of files that you want to delete at once.  The following command will delete all of the doc image files in the current working directory. If the file that you are going to delete is write-protected you will be prompted before the file is deleted.

rm *.doc

How to Remove Directories with rm command in Linux

The process is almost the same as removing files with rm command in Linux. You can remove directories with rm command easily. To remove an empty directory, use the -d (directory) option.

rm -d directory-to-be-deleted

Run the following command to remove the directories that are not in the current working directory. You need to provide a path to the file’s location to remove the directory.

READ More Relevant Stuff:  Ubuntu 20.04 LTS Vs Linux Mint 20 : Which One To Install?

rm -d /path/to/directory-to-be-deleted

How To Remove Multiple Directories With rm Command At Once

Before removing directories, make sure that you are aware of your directory’s structure. if you are not then you easily do it by installing the tree command.

Run the following command to install this tree command on Ubuntu or another Debian-based distribution.

sudo apt-get install tree

Now, you can run the following command to see the directory structure.

tree
tree path/to/directory

Run the following command to remove multiple directories with rm command. Similarly, If a directory or a file is write-protected, you will be prompted to confirm the deletion.

rm -d directory-to-be-deleted1 directory-to-be-deleted2 /path/to/directory-to-be-deleted3

To delete directories that are not empty, use the -r (recursive) option. To be clear, this removes the directories and all files and sub-directories contained within them.

rm -r directory1 directory2 directory3

Run the following command to delete directories that are not empty. You need to be extra cautious while using rm -rf command as you might lose your data with one mistake.

rm -rf directory

How to Remove Directories with rmdir

Now, we will use another command to remove directories in Linux and the command is rmdir.

rmdir directory-to-be-deleted

rmdir can only delete directories that are empty. If you try to delete a folder that is not empty, rmdir will give you an error message. It will never delete files. Run the following command to delete multiple directories  :

rmdir directory-to-be-deleted1 directory-to-be-deleted2 directory-to-be-deleted3

Run the following command to remove the directories that are not in the current working directory.

rmdir /path/to/directory-to-be-deleted

Summary: This is the complete solution to remove files and directories with rmdir and rm commands in Linux. Let us know if you want to add more content and make this post more easy. Don’t forget to share this post on How To Remove Files And Directories In Linux [Examples]

READ More Relevant Stuff:  Wget Command Examples In Linux

 

Linux, Tutorials Tags:command

Post navigation

Previous Post: How To Run Linux Commands In background : Run Process In background
Next Post: How To Mount Windows 11 Shares On Ubuntu 22.04 LTS

Related Posts

Install Snapcraft, AppImage And Flatpak On Linux Linux
10+ Best Free Linux File Managers In 2023 10+ Best Free Linux File Managers In 2023 Linux
GNOME 42 Desktop Environment Released With Exciting Features GNOME 42 Desktop Environment Released With Exciting Features Linux
5 Best Screenshot Tools For Linux In 2021 5 Best Screenshot Tools For Linux In 2021 Tools
Useful Best Linux Data Recovery Tools For 2019 Useful Best Linux Data Recovery Tools For 2023 Linux
Arc Menu 47, Popular Gnome Extension Released With New Layout Arc Menu 47, Popular Gnome Extension Released With New Layout Linux

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • How To Enable Hibernate in Ubuntu 22.04 LTS May 20, 2024
  • Popular Ubuntu Games: Top 5 Games To Play March 17, 2024
  • WordPress | Your site doesn’t include support for the “generateblocks/container” block GenerateBlocks Plugin February 11, 2024
  • Ubuntu Autoremove Command Debian Autoremove Command February 10, 2024
  • How To Mount Windows 11 Shares on Debian Linux December 7, 2023
  • Anonymous Browsing 101: A Deep Dive Into Residential Proxies November 20, 2023
  • How To Correctly Install Uninstall Linux Ubuntu Nvidia Drivers Fast October 31, 2023
  • Ethical Web Design: The Dos and Don’ts October 28, 2023
  • Understanding the Role of Security Operations Center October 25, 2023
  • The Positive Effects of AI Tools and Online Services on Students Successful Essay-Writing Skills October 3, 2023
  • Linux Wget Examples September 27, 2023

Categories

  • Android
  • Apple
  • Blogs
  • Debian
  • Fix
  • Gadgets
  • Game
  • Google
  • How To Ubuntu
  • Internet
  • Laptops
  • Linux
  • Linux Commands
  • Linux Game
  • Linux Mint
  • News
  • Operating Systems
  • Security
  • Technology
  • Themes
  • Tools
  • Tutorials
  • Ubuntu
  • ubuntu 18.04
  • Ubuntu 20.04
  • Ubuntu 22.04
  • Windows 11
  • Wordpress
  • Search Jobs
  • Post a Job
  • Job Dashboard
  • Contact Us
  • About US
  • Cookie Policy
  • Terms and Conditions
  • Privacy Policy
  • Sitemap
  • Write For US

Tags

android apps centos ChatGPT command Commands Debian deepin Desktop docker Fedora fix game games Gaming gnome google kernel linux linux commands linux kernel Linux laptops Linux Mint Linux themes minecraft NVIDIA Python Raspberry Pi sysadmin themes ubuntu ubuntu 18.04 Ubuntu 18.04 LTS Ubuntu 20.04 ubuntu 20.04 lts Ubuntu 22.04 LTS Ubuntu games Ubuntu kernel ubuntu themes ubuntu tutorial VirtualBox Windows Windows 11 Wine WSL
itsubuntu.com is an Equal Opportunity Employer. For Advertisement, Jobs, Guest posts, and any other thoughts, email us at [email protected]
  • Prepared Foods Order Writer (Deli / Culinary – Buyer / Inventory Replenishment) – Full Time

    • Thayne, WY
    • Whole Foods Market
    • Full Time
  • Sr. Risk and Controls Compliance Policy Writer (on-site Phoenix, Chicago, San Fran)

    • San Francisco, CA
    • INSPYR Solutions
    • Full Time
  • Artificial Intelligence & Gen AI Engineer – Tampa, Hybrid

    • Tampa, FL
    • Citigroup Inc
    • Full Time
  • Sr. Technical Documentation Specialist – REMOTE

    • Atlanta, GA
    • HHS Technology Group, Inc.
    • Full Time
  • TECHNOLOGY VICE PRESIDENT, ARTIFICIAL INTELLIGENCE & MACHINE LEARNING AND DATA

    • Falls Church, VA
    • NLP PEOPLE
    • Full Time
  • Architectural Drafter

    • Sarasota, FL
    • Start To Finish Drafting
    • Full Time
  • Senior or Principal Data Scientist – Technical AI Ethicist

    • Seattle, WA (Remote)
    • salesforce.com, inc.
    • Full Time
  • Artificial Intelligence (AI) Data Scientist

    • Fairfax, VA
    • General Dynamics Information Technology
    • Full Time

Copyright © 2025 Technology News Information & Jobs.

Powered by PressBook Grid Blogs theme