CoderSathi
  • Tutorial
    • Java Tutorial
    • Swing Tutorial
    • JDBC Tutorial
    • Java String Tutorial
    • Servlet and JSP Tutorial
  • Mongo DB
  • AWS
  • DevOps
  • Linux
  • Git
Home > How to > Delete all directories and keep files in Linux

Delete all directories and keep files in Linux

Learn the concepts, implementation details, and practical steps with a clean developer-focused walkthrough.

Yuba Raj Kalathoki
By Yuba Raj Kalathoki
Last updated: July 1, 2026 · 1 min read · 0 Comments
Share: in X
systemctl command not found

In this short post, we will learn to delete all the directories (folders) and keep the file as it is. This means deleting all the directories and not removing the files available in a particular location.

Steps:

  1. Got to the main directory
  2. Use the command: sudo rm -r */
  3. That’s it.

Let’s say you were trying to delete all the folders inside backup folder then go to the backup folder and use the command mentioned in step 2.

This deletes all the folders available inside a backup folder and keeps all the files present.

Cheers! 🙂

Related Posts:

  • Working with Files and Directories in Java
  • MySQL Commands for Developers
  • Install and Set Up Java Development Environment
  • How to Solve “systemctl command not found” Error: A…
  • Clean Up Jenkins Home Directory
  • How to Import and Export Data in MongoDB: A…
Tags:devopslinux
Was this article helpful?
← Previous ArticleHow to Login/SSH to AWS EC2 linux instance?
Next Article →How to Upload File to AWS EC2 Instance From Local Machine?

Leave a Comment Cancel reply

You must be logged in to post a comment.

Recent Posts

  • How to implement Passwordless Authentication in Spring Boot: A Step-by-Step Guide
  • How to Use AWS CloudFront Signed URLs in Spring Boot?
  • How to Fix SSH Agent Forwarding on macOS: The Ultimate Guide for Developers
  • How to Read AWS Secrets Manager in Spring Boot (Step-by-Step)
  • How to Fix “Public Key Retrieval is not allowed” MySQL JDBC Error
CoderSathi

Your go-to resource for Java, Spring Boot, Microservices, AWS, and modern development tutorials.

Linkedin

Quick Links

  • About
  • Contact

Popular Topics

  • Java
  • Spring Boot
  • AWS
  • DevOps
  • MongoDB
  • Linux
  • Git
  • How to
© 2026 CoderSathi. All rights reserved. Privacy Policy · Sitemap