Delete all files & directories in a folder except one file

by Dushyant Joshi   Last Updated July 12, 2019 05:00 AM

I want to delete all files & directories in a folder say 'A'. But except one file in that folder say .keep. I have tried the following command.

find A ! -name '.keep' -type f -exec rm -f {} +

But above command also deletes folder A. I do not want that. There are several answers related to this. But they all mentions going into that directory. I want to mention that directory in the command without cd-eing into the directory.

Tags : linux command rm

Related Questions

Updated February 21, 2019 18:00 PM

Updated May 30, 2017 11:00 AM

Updated July 25, 2017 16:00 PM