In bash, I have a directory that holds some file names that start with underscore _ and others that don't.

I want my script to check if a folder has any files that don't start with _. I write

if [[ -f $dir/[!_]* ]]
  then echo "There are unmarked files."
  else echo "All files marked."

But when I run using a folder with files that do and do not start with _, the if statement has the opposite effect of what I intended. I list the entries in the folder that clearly display files without _, but the output keeps saying, All files marked.

What am I missing?


1 Answer 1

if find -not -name '_*' -exec false {} +
  echo 'all files marked'
  echo 'unmarked file found'
  • @muru {} ';' is not the same as {} + - perhaps you could perform an apples for apples test before commenting further - thanks
    – Zombo
    Commented Feb 16, 2018 at 16:31

Not the answer you're looking for? Browse other questions tagged .