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

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:  Run Linux On Windows 11: Install Linux Bash Shell on Windows 11

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:  How To Install Pantheon On Ubuntu 18.04 LTS

 

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

How To Boot Into Rescue Mode Or Emergency Mode In Ubuntu 22.04 / 20.04 / 18.04 How To Boot Into Rescue Mode Or Emergency Mode In Ubuntu 22.04 / 20.04 / 18.04 Linux
OBS Linux 2023 Install OBS In Linux Operating System [2023] Linux
Top 9 Best Photoshop Alternatives For Linux Top 9 Best Photoshop Alternatives For Linux For 2023 Ubuntu
15+ Best Web Browsers For Linux In 2023 15+ Best Web Browsers For Linux In 2023 Linux
How To Install OpenCV On CentOS 8 How To Install OpenCV On CentOS 8 Linux
Never Run These Commands On Linux : Linux Guides Never Run These Commands On Linux : Linux Guides Linux

Recent Posts

  • New Job Search October 10, 2025
  • 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

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]
  • Nonclinical Writer

    • Philadelphia, PA
    • MMS
    • Full Time
  • Technical Writer 1

    • Clawson, MI
    • Experis
    • Temporary
  • Take 5 – Lube Tech/Service Writer

    • Derby, KS
    • VANTEDGE AUTO T5 LLC
    • Full Time
  • User Experience Writer

    • Chicago, IL
    • Tonic3
    • Full Time
  • Senior Document Writer – New Group Business

    • Carson City, NV
    • CVS Health
    • Full Time
  • Lead Data Architect & Engineer – AWS

    • Richardson, TX (Remote)
    • State Farm
    • Full Time
  • Grant Writer

    • Gillette, WY
    • YES House (Youth Emergency Services, Inc.)
    • Part Time
  • Grant Writer

    • Beverly Hills, CA
    • MY SERENITY SANCTUARY
    • Full Time

Copyright © 2025 Technology News Information & Jobs.

Powered by PressBook Grid Blogs theme