How to delete all contents of a FreeBSD folder


How to delete all contents of a folder.

Recursively delete.



There are times when you need to completely delete the contents of a folder while leaving the folder itself.




For example, you need to clear the temporary directory , that is, tmp just run the following command:



rm -R /tmp/*




Check if the folder has been cleared with the command:



ls /tmp



Either you need to recursively delete files of the same type.



For example, in the folder with ODF and TXT files, you need to delete all TXT files without affecting ODF.




It's not very convenient to do this in file managers, but here the console saves us because we don't have to search for the files we need by extension, but just execute the following command:



rm -R path to the folder * .txt


For example:


rm -R /home/max/1/*.txt


Or any other file extension to be removed.