Empty Linux Folder: Safe Command Guide

To clear the contents of a folder, you can use the following command:

  1. Delete
rm -rf /path/to/folder/*

Please note that this command will directly delete all contents in the folder, including subfolders and files, without prompt for confirmation, so please use it carefully.

  1. To only delete the files within a folder while keeping the folder itself and its subfolders, you can use the following command:
rm -f /path/to/folder/*

This command will only delete all files within the folder, without removing the folder itself or its subfolders.

Please be very cautious when using the rm command, make sure the file you are deleting is the correct one to avoid accidentally deleting important files.

bannerAds