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
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
bash
New contributor
marked as duplicate by RavinderSingh13, tripleee
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.
add a comment |
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
bash
New contributor
marked as duplicate by RavinderSingh13, tripleee
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
add a comment |
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
bash
New contributor
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
bash
New contributor
New contributor
edited 11 hours ago
user3081088
New contributor
asked yesterday
user3081088user3081088
31
31
New contributor
New contributor
marked as duplicate by RavinderSingh13, tripleee
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
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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.
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
add a comment |
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.
add a comment |
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.
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.
edited yesterday
answered yesterday
iovuioiovuio
597
597
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
edited 11 hours ago
user3081088
31
31
answered yesterday
SonnySonny
561310
561310
add a comment |
add a comment |
The wildcard you tried doesn't actually match the files you wanted to find. Maybe use
...$mois??"_*
– tripleee
yesterday