-1

I'm using the following script to make all files in a directory hidden by adding a dot "." at the beginning.

GLOBIGNORE=".:.."
for file in *; do
     mv -n "$file" ".$file";
done

How can I exclude the already hidden files?

Thanks for your help!

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Dimitris
  • 1
  • 4

1 Answers1

3

The wildcard already doesn't match any hidden files, unless you have separately enabled dotglob.

If you have configured dotglob to include hidden files, you can momentarily turn it off with

shopt -u dotglob

Using GLOBIGNORE enables dotglob so maybe the simplest fix is to take that out. You could also change it to

GLOBIGNORE='.*'

but this is effectively the same as unsetting it.

tripleee
  • 175,061
  • 34
  • 275
  • 318