Score:0

How to search/list for all files starting with dot (.) but .htaccess is excluded from the list

bw flag

Using SSH command line, I need to delete all the files starting with dot (.) but I don't want to delete .htaccess files.

I tried so far to list them like this

find . -type f -name ".*" 

It listed all the files properly.but .htaccess was there too. Thanks

Score:1
hr flag

You can use ! (or, in GNU find, -not) to logically invert a test. From man find:

   ! expr True  if  expr  is false.  This character will also usually need
          protection from interpretation by the shell.

   -not expr
          Same as ! expr, but not POSIX compliant.

So

find . -type f -name ".*" ! -name .htaccess

or

find . -type f -name ".*" -not -name .htaccess

Ex. given

$ find . -type f -name ".*"
./.bar
./.baz
./.foo
./.htaccess

then

$ find . -type f -name ".*" ! -name .htaccess -delete

leaving

$ find . -type f -name ".*"
./.htaccess
RahimM avatar
bw flag
Thanks for the answer, I want to delete the list after I show it . ofcourse I don't want to delete the .htacess Thanks a lot again
RahimM avatar
bw flag
It worked, Thank you so much for your help
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.