total crap, it doesn’t actually test if the file is there or not, it just tests if the command line argument is there. There’s a giant f*cking differences.
Adam said on December 3, 2008
I don’t think you’re using it quite right Young Padawan
ayw said on February 10, 2009
if [ -e testfile ]; tests whether a file exists.
if [ -f testfile ]; only tests whether file is a regular file
Shouldn’t that one have some brackets or something?
David said on March 24, 2009
No. From the man page: ” -f filename True if filename exists and is a regular file.”"
Joeblackspirit said on May 29, 2009
Perfect and simple!!
Third Rook said on July 26, 2009
Regardless what the man page says. -f didn’t work in my script, and -e did.
Thanks ayw.
Anonymous said on September 9, 2009
And what to do if I have several files smth.gz but I don’t know how much and I don’t know actual names. I need to run some command if one of such files exists.
Anonymous said on September 10, 2009
Well, I’ve found the solution:
for *.gz do my_command done
Incognito said on September 5, 2010
-f didn’t work for me either. Maybe different Version of bash or whatever. -e worked well.
Well, at least they are acting like idiots. WTF does “AND” mean to you?
Jscrobinson said on March 10, 2011
I think a lot of you should grow up a little bit and try and do something about your bad language.
Shabeer said on March 14, 2011
does the -f or -s option work if the filename has a white space. below is the file and when I use the file name in if condition it throws an error. I tried with double quotes, single quotes etc.. if condition throws an error
Swearing in this way is just a demonstration of childish bad behavior. If you don’t want to help or you don’t have anything constructive to say then please don’t say it. If you disagree with someone then explain your opinion respectfully, you may both be right or either of you may be wrong. But either way there is no need for bad language is there?
Teen said on June 28, 2011
idiot
NeoVG said on August 22, 2011
@Shabeer: You have to escape the whitespaces. So try this:
bash-3.00$ ls file \name
@Others: -f fails, if the target is a symbolic link, as a link is NO regular file, although you can read it like one.
DaVince said on October 27, 2008
Just what I needed, thanks.
anonymous said on November 24, 2008
if [ -f testfile ];
then
echo Blablabla
fi
James said on November 26, 2008
total crap, it doesn’t actually test if the file is there or not, it just tests if the command line argument is there. There’s a giant f*cking differences.
Adam said on December 3, 2008
I don’t think you’re using it quite right Young Padawan
ayw said on February 10, 2009
if [ -e testfile ]; tests whether a file exists.
if [ -f testfile ]; only tests whether file is a regular file
iGuide said on March 5, 2009
Shouldn’t that one have some brackets or something?
David said on March 24, 2009
No. From the man page: ” -f filename
True if filename exists and is a regular file.”"
Joeblackspirit said on May 29, 2009
Perfect and simple!!
Third Rook said on July 26, 2009
Regardless what the man page says. -f didn’t work in my script, and -e did.
Thanks ayw.
Anonymous said on September 9, 2009
And what to do if I have several files smth.gz but I don’t know how much and I don’t know actual names.
I need to run some command if one of such files exists.
Anonymous said on September 10, 2009
Well, I’ve found the solution:
for *.gz
do
my_command
done
Incognito said on September 5, 2010
-f didn’t work for me either.
Maybe different Version of bash or whatever.
-e worked well.
Blake Galbreath said on September 26, 2010
Um…
“True if filename exists AND is a regular file”
So, let me break it down for you idiots.
-f tests for an existing REGULAR file. If the file exists, but is NOT regular, then -f returns FALSE.
-e tests for an existing file, regardless if its regular or not. If the file is there (regular or not) it returns TRUE.
Hope I helped
;)
Drain said on September 30, 2010
You are rude.
sims said on December 9, 2010
Well, at least they are acting like idiots. WTF does “AND” mean to you?
Jscrobinson said on March 10, 2011
I think a lot of you should grow up a little bit and try and do something about your bad language.
Shabeer said on March 14, 2011
does the -f or -s option work if the filename has a white space. below is the file and when I use the file name in if condition it throws an error. I tried with double quotes, single quotes etc.. if condition throws an error
bash-3.00$ ls file name
file name
bash-3.00$
Jan Stammes said on April 21, 2011
just where I was looking for
it doesn't matter said on June 11, 2011
Swearing in this way is just a demonstration of childish bad behavior. If you don’t want to help or you don’t have anything constructive to say then please don’t say it.
If you disagree with someone then explain your opinion respectfully, you may both be right or either of you may be wrong. But either way there is no need for bad language is there?
Teen said on June 28, 2011
idiot
NeoVG said on August 22, 2011
@Shabeer: You have to escape the whitespaces. So try this:
bash-3.00$ ls file \name
@Others: -f fails, if the target is a symbolic link, as a link is NO regular file, although you can read it like one.