If/Testing the existence of certain numerous files [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite













This question already has an answer here:



  • Test if there are files matching a pattern in order to execute a script

    8 answers



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."
fi


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?







share|improve this question












marked as duplicate by don_crissti, Timothy Martin, Kusalananda, Jeff Schaller, muru Feb 16 at 2:06


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















    up vote
    0
    down vote

    favorite













    This question already has an answer here:



    • Test if there are files matching a pattern in order to execute a script

      8 answers



    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."
    fi


    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?







    share|improve this question












    marked as duplicate by don_crissti, Timothy Martin, Kusalananda, Jeff Schaller, muru Feb 16 at 2:06


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite












      This question already has an answer here:



      • Test if there are files matching a pattern in order to execute a script

        8 answers



      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."
      fi


      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?







      share|improve this question













      This question already has an answer here:



      • Test if there are files matching a pattern in order to execute a script

        8 answers



      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."
      fi


      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?





      This question already has an answer here:



      • Test if there are files matching a pattern in order to execute a script

        8 answers









      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 15 at 19:27









      Jason

      174




      174




      marked as duplicate by don_crissti, Timothy Martin, Kusalananda, Jeff Schaller, muru Feb 16 at 2:06


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by don_crissti, Timothy Martin, Kusalananda, Jeff Schaller, muru Feb 16 at 2:06


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          if find -not -name '_*' -exec false +
          then
          echo 'all files marked'
          else
          echo 'unmarked file found'
          fi





          share|improve this answer




















          • @muru ';' is not the same as + - perhaps you could perform an apples for apples test before commenting further - thanks
            – Steven Penny
            Feb 16 at 16:31

















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          if find -not -name '_*' -exec false +
          then
          echo 'all files marked'
          else
          echo 'unmarked file found'
          fi





          share|improve this answer




















          • @muru ';' is not the same as + - perhaps you could perform an apples for apples test before commenting further - thanks
            – Steven Penny
            Feb 16 at 16:31














          up vote
          0
          down vote













          if find -not -name '_*' -exec false +
          then
          echo 'all files marked'
          else
          echo 'unmarked file found'
          fi





          share|improve this answer




















          • @muru ';' is not the same as + - perhaps you could perform an apples for apples test before commenting further - thanks
            – Steven Penny
            Feb 16 at 16:31












          up vote
          0
          down vote










          up vote
          0
          down vote









          if find -not -name '_*' -exec false +
          then
          echo 'all files marked'
          else
          echo 'unmarked file found'
          fi





          share|improve this answer












          if find -not -name '_*' -exec false +
          then
          echo 'all files marked'
          else
          echo 'unmarked file found'
          fi






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 16 at 0:24









          Steven Penny

          2,29021635




          2,29021635











          • @muru ';' is not the same as + - perhaps you could perform an apples for apples test before commenting further - thanks
            – Steven Penny
            Feb 16 at 16:31
















          • @muru ';' is not the same as + - perhaps you could perform an apples for apples test before commenting further - thanks
            – Steven Penny
            Feb 16 at 16:31















          @muru ';' is not the same as + - perhaps you could perform an apples for apples test before commenting further - thanks
          – Steven Penny
          Feb 16 at 16:31




          @muru ';' is not the same as + - perhaps you could perform an apples for apples test before commenting further - thanks
          – Steven Penny
          Feb 16 at 16:31


          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay