systemctl command not found

Delete all directories and keep files in Linux

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.


  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! 🙂

Notify of
Inline Feedbacks
View all comments