Bash - Check if file exists when some of the filename is irrelevant [duplicate]2019 Community Moderator ElectionCheck if a file exists with wildcard in shell scriptHow to check if a string contains a substring in BashHow to check if a program exists from a Bash script?How do I tell if a regular file does not exist in Bash?How can I redirect and append both stdout and stderr to a file with Bash?Extract filename and extension in BashLooping through the content of a file in BashIn bash, how can I check if a string begins with some value?How to check if a variable is set in Bash?Check existence of input argument in a Bash shell scriptCheck number of arguments passed to a Bash script

Python 3.6+ function to ask for a multiple-choice answer

Why are special aircraft used for the carriers in the United States Navy?

Has a sovereign Communist government ever run, and conceded loss, on a fair election?

Can inspiration allow the Rogue to make a Sneak Attack?

Are healthy patients an appropriate control group?

Is divide-by-zero a security vulnerability?

Ignoring Someone as Wrongful Speech

Deal the cards to the players

Error in TransformedField

Iron deposits mined from under the city

Does the US political system, in principle, allow for a no-party system?

What does "rhumatis" mean?

Professor forcing me to attend a conference

Sundering Titan and basic normal lands and snow lands

Create chunks from an array

I can't die. Who am I?

Why is my explanation wrong?

When to use the term transposed instead of modulation?

Is being socially reclusive okay for a graduate student?

Quitting employee has privileged access to critical information

Why can't we use freedom of speech and expression to incite people to rebel against government in India?

I've given my players a lot of magic items. Is it reasonable for me to give them harder encounters?

Is every open circuit a capacitor?

Are small insurances worth it



Bash - Check if file exists when some of the filename is irrelevant [duplicate]



2019 Community Moderator ElectionCheck if a file exists with wildcard in shell scriptHow to check if a string contains a substring in BashHow to check if a program exists from a Bash script?How do I tell if a regular file does not exist in Bash?How can I redirect and append both stdout and stderr to a file with Bash?Extract filename and extension in BashLooping through the content of a file in BashIn bash, how can I check if a string begins with some value?How to check if a variable is set in Bash?Check existence of input argument in a Bash shell scriptCheck number of arguments passed to a Bash script










0
















This question already has an answer here:



  • Check if a file exists with wildcard in shell script [duplicate]

    21 answers



I want to check if file exists but only checking if some the filename exists



For example in some folder I have these files (Date format: AAAAMMDD):



Rejets_20190112.csv.zip



Rejets_20190312.csv.zip



Rejets_20190314.csv.zip



I want to check if there is a file that begins with Rejet_DAP_201903 exists in that folder. In other word I want to check if Rejet_DAP file with current year and month exist, the day doesn't matter.



Here's what I tried to do in my script:



jour=`date +%d`
mois=`date +%m`
annee=`date +%Y`


FILE="/appli/project/echanges/RTY/receptions/Rejet_$annee$mois"_*


if [[ -e $FILE ]]
then
echo "FILE EXISTS"
else
echo "FILE DOES NOT EXIST"

fi









share|improve this question









New contributor




user3081088 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











marked as duplicate by RavinderSingh13, tripleee bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
yesterday


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.


















  • The wildcard you tried doesn't actually match the files you wanted to find. Maybe use ...$mois??"_*

    – tripleee
    yesterday















0
















This question already has an answer here:



  • Check if a file exists with wildcard in shell script [duplicate]

    21 answers



I want to check if file exists but only checking if some the filename exists



For example in some folder I have these files (Date format: AAAAMMDD):



Rejets_20190112.csv.zip



Rejets_20190312.csv.zip



Rejets_20190314.csv.zip



I want to check if there is a file that begins with Rejet_DAP_201903 exists in that folder. In other word I want to check if Rejet_DAP file with current year and month exist, the day doesn't matter.



Here's what I tried to do in my script:



jour=`date +%d`
mois=`date +%m`
annee=`date +%Y`


FILE="/appli/project/echanges/RTY/receptions/Rejet_$annee$mois"_*


if [[ -e $FILE ]]
then
echo "FILE EXISTS"
else
echo "FILE DOES NOT EXIST"

fi









share|improve this question









New contributor




user3081088 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











marked as duplicate by RavinderSingh13, tripleee bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
yesterday


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.


















  • The wildcard you tried doesn't actually match the files you wanted to find. Maybe use ...$mois??"_*

    – tripleee
    yesterday













0












0








0









This question already has an answer here:



  • Check if a file exists with wildcard in shell script [duplicate]

    21 answers



I want to check if file exists but only checking if some the filename exists



For example in some folder I have these files (Date format: AAAAMMDD):



Rejets_20190112.csv.zip



Rejets_20190312.csv.zip



Rejets_20190314.csv.zip



I want to check if there is a file that begins with Rejet_DAP_201903 exists in that folder. In other word I want to check if Rejet_DAP file with current year and month exist, the day doesn't matter.



Here's what I tried to do in my script:



jour=`date +%d`
mois=`date +%m`
annee=`date +%Y`


FILE="/appli/project/echanges/RTY/receptions/Rejet_$annee$mois"_*


if [[ -e $FILE ]]
then
echo "FILE EXISTS"
else
echo "FILE DOES NOT EXIST"

fi









share|improve this question









New contributor




user3081088 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













This question already has an answer here:



  • Check if a file exists with wildcard in shell script [duplicate]

    21 answers



I want to check if file exists but only checking if some the filename exists



For example in some folder I have these files (Date format: AAAAMMDD):



Rejets_20190112.csv.zip



Rejets_20190312.csv.zip



Rejets_20190314.csv.zip



I want to check if there is a file that begins with Rejet_DAP_201903 exists in that folder. In other word I want to check if Rejet_DAP file with current year and month exist, the day doesn't matter.



Here's what I tried to do in my script:



jour=`date +%d`
mois=`date +%m`
annee=`date +%Y`


FILE="/appli/project/echanges/RTY/receptions/Rejet_$annee$mois"_*


if [[ -e $FILE ]]
then
echo "FILE EXISTS"
else
echo "FILE DOES NOT EXIST"

fi




This question already has an answer here:



  • Check if a file exists with wildcard in shell script [duplicate]

    21 answers







bash






share|improve this question









New contributor




user3081088 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




user3081088 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 11 hours ago







user3081088













New contributor




user3081088 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked yesterday









user3081088user3081088

31




31




New contributor




user3081088 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





user3081088 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






user3081088 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




marked as duplicate by RavinderSingh13, tripleee bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
yesterday


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 RavinderSingh13, tripleee bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
yesterday


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.














  • The wildcard you tried doesn't actually match the files you wanted to find. Maybe use ...$mois??"_*

    – tripleee
    yesterday

















  • The wildcard you tried doesn't actually match the files you wanted to find. Maybe use ...$mois??"_*

    – tripleee
    yesterday
















The wildcard you tried doesn't actually match the files you wanted to find. Maybe use ...$mois??"_*

– tripleee
yesterday





The wildcard you tried doesn't actually match the files you wanted to find. Maybe use ...$mois??"_*

– tripleee
yesterday












2 Answers
2






active

oldest

votes


















0














You have the directory path and the file pattern that you are looking for.



The ls command can be used to list files based on patterns.
All commands return an integer value after execution. 0 means the execution finished successfully. Any non-zero value means error.



ls will return a non-zero value if no files match the pattern.



That return code you can use within the if statement.



#!/bin/bash

jour=`date +%d`
mois=`date +%m`
annee=`date +%Y`


dir="/appli/ssie7/echanges/EDF/receptions"
file_prefix="Rejet_DAP_"


if ls $dir/$file_prefix$annee$mois* > /dev/null 2>&1
then
echo "FILE EXISTS"
else
echo "FILE DOES NOT EXIST"
fi


The #!/bin/bash line is called a shebang line and I highly recommend using it in your scripts.



The > /dev/null 2>&1 is so that you don't get output from the ls command and only have your output displayed.






share|improve this answer
































    -1














    You can use find for this



    $ if [[ `find /appli/project/echanges/RTY/receptions/ -type f |grep -i Rejet_DAP_$annee$mois|wc -l` -gt 0 ]] ; then 
    echo "FILE EXISTS"
    else
    echo "FILE DOES NOT EXIST"
    fi





    share|improve this answer































      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      You have the directory path and the file pattern that you are looking for.



      The ls command can be used to list files based on patterns.
      All commands return an integer value after execution. 0 means the execution finished successfully. Any non-zero value means error.



      ls will return a non-zero value if no files match the pattern.



      That return code you can use within the if statement.



      #!/bin/bash

      jour=`date +%d`
      mois=`date +%m`
      annee=`date +%Y`


      dir="/appli/ssie7/echanges/EDF/receptions"
      file_prefix="Rejet_DAP_"


      if ls $dir/$file_prefix$annee$mois* > /dev/null 2>&1
      then
      echo "FILE EXISTS"
      else
      echo "FILE DOES NOT EXIST"
      fi


      The #!/bin/bash line is called a shebang line and I highly recommend using it in your scripts.



      The > /dev/null 2>&1 is so that you don't get output from the ls command and only have your output displayed.






      share|improve this answer





























        0














        You have the directory path and the file pattern that you are looking for.



        The ls command can be used to list files based on patterns.
        All commands return an integer value after execution. 0 means the execution finished successfully. Any non-zero value means error.



        ls will return a non-zero value if no files match the pattern.



        That return code you can use within the if statement.



        #!/bin/bash

        jour=`date +%d`
        mois=`date +%m`
        annee=`date +%Y`


        dir="/appli/ssie7/echanges/EDF/receptions"
        file_prefix="Rejet_DAP_"


        if ls $dir/$file_prefix$annee$mois* > /dev/null 2>&1
        then
        echo "FILE EXISTS"
        else
        echo "FILE DOES NOT EXIST"
        fi


        The #!/bin/bash line is called a shebang line and I highly recommend using it in your scripts.



        The > /dev/null 2>&1 is so that you don't get output from the ls command and only have your output displayed.






        share|improve this answer



























          0












          0








          0







          You have the directory path and the file pattern that you are looking for.



          The ls command can be used to list files based on patterns.
          All commands return an integer value after execution. 0 means the execution finished successfully. Any non-zero value means error.



          ls will return a non-zero value if no files match the pattern.



          That return code you can use within the if statement.



          #!/bin/bash

          jour=`date +%d`
          mois=`date +%m`
          annee=`date +%Y`


          dir="/appli/ssie7/echanges/EDF/receptions"
          file_prefix="Rejet_DAP_"


          if ls $dir/$file_prefix$annee$mois* > /dev/null 2>&1
          then
          echo "FILE EXISTS"
          else
          echo "FILE DOES NOT EXIST"
          fi


          The #!/bin/bash line is called a shebang line and I highly recommend using it in your scripts.



          The > /dev/null 2>&1 is so that you don't get output from the ls command and only have your output displayed.






          share|improve this answer















          You have the directory path and the file pattern that you are looking for.



          The ls command can be used to list files based on patterns.
          All commands return an integer value after execution. 0 means the execution finished successfully. Any non-zero value means error.



          ls will return a non-zero value if no files match the pattern.



          That return code you can use within the if statement.



          #!/bin/bash

          jour=`date +%d`
          mois=`date +%m`
          annee=`date +%Y`


          dir="/appli/ssie7/echanges/EDF/receptions"
          file_prefix="Rejet_DAP_"


          if ls $dir/$file_prefix$annee$mois* > /dev/null 2>&1
          then
          echo "FILE EXISTS"
          else
          echo "FILE DOES NOT EXIST"
          fi


          The #!/bin/bash line is called a shebang line and I highly recommend using it in your scripts.



          The > /dev/null 2>&1 is so that you don't get output from the ls command and only have your output displayed.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited yesterday

























          answered yesterday









          iovuioiovuio

          597




          597























              -1














              You can use find for this



              $ if [[ `find /appli/project/echanges/RTY/receptions/ -type f |grep -i Rejet_DAP_$annee$mois|wc -l` -gt 0 ]] ; then 
              echo "FILE EXISTS"
              else
              echo "FILE DOES NOT EXIST"
              fi





              share|improve this answer





























                -1














                You can use find for this



                $ if [[ `find /appli/project/echanges/RTY/receptions/ -type f |grep -i Rejet_DAP_$annee$mois|wc -l` -gt 0 ]] ; then 
                echo "FILE EXISTS"
                else
                echo "FILE DOES NOT EXIST"
                fi





                share|improve this answer



























                  -1












                  -1








                  -1







                  You can use find for this



                  $ if [[ `find /appli/project/echanges/RTY/receptions/ -type f |grep -i Rejet_DAP_$annee$mois|wc -l` -gt 0 ]] ; then 
                  echo "FILE EXISTS"
                  else
                  echo "FILE DOES NOT EXIST"
                  fi





                  share|improve this answer















                  You can use find for this



                  $ if [[ `find /appli/project/echanges/RTY/receptions/ -type f |grep -i Rejet_DAP_$annee$mois|wc -l` -gt 0 ]] ; then 
                  echo "FILE EXISTS"
                  else
                  echo "FILE DOES NOT EXIST"
                  fi






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 11 hours ago









                  user3081088

                  31




                  31










                  answered yesterday









                  SonnySonny

                  561310




                  561310













                      Popular posts from this blog

                      Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

                      Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

                      Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved