<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
> <channel><title>Comments on: Linux/UNIX: Find Out If File Exists With Conditional Expressions</title> <atom:link href="http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html/feed" rel="self" type="application/rss+xml" /><link>http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html</link> <description>This is a Linux sys admin journal by Vivek about sys admin work, Linux tips &#38; tricks, hacks, news and more.</description> <lastBuildDate>Fri, 10 Feb 2012 20:37:43 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>By: chey</title><link>http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-176367</link> <dc:creator>chey</dc:creator> <pubDate>Fri, 02 Dec 2011 15:41:48 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-176367</guid> <description>Thanks for the script, it was very useful.</description> <content:encoded><![CDATA[<p>Thanks for the script, it was very useful.</p> ]]></content:encoded> </item> <item><title>By: Ravi Theja</title><link>http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-173937</link> <dc:creator>Ravi Theja</dc:creator> <pubDate>Tue, 13 Sep 2011 20:05:00 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-173937</guid> <description>if [ -e filename ] works for me and checks fine ONLY when I&#039;m logged in as a power broker. It doesn&#039;t test when I log in as a normal user or call the script from a different scheduling tool.
Please help me ASAP</description> <content:encoded><![CDATA[<p>if [ -e filename ] works for me and checks fine ONLY when I&#8217;m logged in as a power broker. It doesn&#8217;t test when I log in as a normal user or call the script from a different scheduling tool.</p><p>Please help me ASAP</p> ]]></content:encoded> </item> <item><title>By: Sergani</title><link>http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-172963</link> <dc:creator>Sergani</dc:creator> <pubDate>Tue, 02 Aug 2011 01:32:11 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-172963</guid> <description>you could also have done the following:
find /home/username/thunderbird-directory/ -iname .parentlock -ok rm {} ;\
it&#039;ll find the file and attempt to remove it, but will ask you first... if you need it to remove it right away, replace -ok with -exec</description> <content:encoded><![CDATA[<p>you could also have done the following:</p><p>find /home/username/thunderbird-directory/ -iname .parentlock -ok rm {} ;\</p><p>it&#8217;ll find the file and attempt to remove it, but will ask you first&#8230; if you need it to remove it right away, replace -ok with -exec</p> ]]></content:encoded> </item> <item><title>By: Sergani</title><link>http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-172962</link> <dc:creator>Sergani</dc:creator> <pubDate>Tue, 02 Aug 2011 01:30:01 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-172962</guid> <description>cd /path/to/directory
for i in $(ls -1 *)
do
if [ -f $i ] ; then
ll $i
else
echo &quot;$i is not a file&quot;
fi</description> <content:encoded><![CDATA[<p>cd /path/to/directory<br
/> for i in $(ls -1 *)<br
/> do<br
/> if [ -f $i ] ; then<br
/> ll $i<br
/> else<br
/> echo &#8220;$i is not a file&#8221;<br
/> fi</p> ]]></content:encoded> </item> <item><title>By: Sergani</title><link>http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-172961</link> <dc:creator>Sergani</dc:creator> <pubDate>Tue, 02 Aug 2011 01:26:42 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-172961</guid> <description>Try ls -1D (that&#039;s ls -&#039;ONE&#039; -D)</description> <content:encoded><![CDATA[<p>Try ls -1D (that&#8217;s ls -&#8217;ONE&#8217; -D)</p> ]]></content:encoded> </item> <item><title>By: Ked</title><link>http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-172168</link> <dc:creator>Ked</dc:creator> <pubDate>Tue, 28 Jun 2011 13:05:47 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-172168</guid> <description>That was a great help, I needed a script to check if the .parentlock file was present in the Thunderbird profile directory and then delete it if it was.
Worked first time :)</description> <content:encoded><![CDATA[<p>That was a great help, I needed a script to check if the .parentlock file was present in the Thunderbird profile directory and then delete it if it was.</p><p>Worked first time :)</p> ]]></content:encoded> </item> <item><title>By: Lalit Mohan</title><link>http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-169602</link> <dc:creator>Lalit Mohan</dc:creator> <pubDate>Mon, 07 Mar 2011 06:35:32 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-169602</guid> <description>I want to check file that i fetching is complete or not, if file is still copying than  wait for few minutes, can this things possible, Reply me Please!!!</description> <content:encoded><![CDATA[<p>I want to check file that i fetching is complete or not, if file is still copying than  wait for few minutes, can this things possible, Reply me Please!!!</p> ]]></content:encoded> </item> <item><title>By: sonal</title><link>http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-168607</link> <dc:creator>sonal</dc:creator> <pubDate>Mon, 07 Feb 2011 06:34:51 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-168607</guid> <description>i need to check all the files in the current directory and display them.how can i do this?</description> <content:encoded><![CDATA[<p>i need to check all the files in the current directory and display them.how can i do this?</p> ]]></content:encoded> </item> <item><title>By: Betulino</title><link>http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-158834</link> <dc:creator>Betulino</dc:creator> <pubDate>Thu, 12 Aug 2010 08:06:16 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-158834</guid> <description>Hi,
I have /media/USBDisk0 and that the mount point for my USBDisk.
And a hard link  named /media/TheData/Data -&gt; /media/USBDisk0/Data
When the USB is mounted, the hard link is OK, but If something fail, the hard link is broken.... Can use the if to test the hard link?</description> <content:encoded><![CDATA[<p>Hi,</p><p>I have /media/USBDisk0 and that the mount point for my USBDisk.<br
/> And a hard link  named /media/TheData/Data -&gt; /media/USBDisk0/Data<br
/> When the USB is mounted, the hard link is OK, but If something fail, the hard link is broken&#8230;. Can use the if to test the hard link?</p> ]]></content:encoded> </item> <item><title>By: Jasper</title><link>http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-158649</link> <dc:creator>Jasper</dc:creator> <pubDate>Mon, 02 Aug 2010 10:57:52 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-158649</guid> <description>Hi,
I need to check if a file with the current date exists in a folder. How would I do that?</description> <content:encoded><![CDATA[<p>Hi,</p><p>I need to check if a file with the current date exists in a folder. How would I do that?</p> ]]></content:encoded> </item> <item><title>By: Anthony Youngman</title><link>http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-156251</link> <dc:creator>Anthony Youngman</dc:creator> <pubDate>Fri, 28 May 2010 20:40:22 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-156251</guid> <description>ls D
blah blah blah
drwx------ Program Files
if -d D/Program\ Files returns FALSE
It would be nice if I could find some way of successfully testing for names with spaces :-(
Cheers,
Wol</description> <content:encoded><![CDATA[<p>ls D<br
/> blah blah blah<br
/> drwx&#8212;&#8212; Program Files</p><p>if -d D/Program\ Files returns FALSE</p><p>It would be nice if I could find some way of successfully testing for names with spaces :-(</p><p>Cheers,<br
/> Wol</p> ]]></content:encoded> </item> <item><title>By: amit</title><link>http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-154219</link> <dc:creator>amit</dc:creator> <pubDate>Thu, 11 Mar 2010 17:09:02 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-154219</guid> <description>the only thing i can say is that -
if statement does&#039;nt allow wild card, you have to think a work around for this</description> <content:encoded><![CDATA[<p>the only thing i can say is that -</p><p>if statement does&#8217;nt allow wild card, you have to think a work around for this</p> ]]></content:encoded> </item> <item><title>By: krishna</title><link>http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-153109</link> <dc:creator>krishna</dc:creator> <pubDate>Sun, 24 Jan 2010 13:21:56 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-153109</guid> <description>I need the shell script to check whether the file exist or not
and whether the format of the file is .dat or not
expecting the help ASAP...pls</description> <content:encoded><![CDATA[<p>I need the shell script to check whether the file exist or not<br
/> and whether the format of the file is .dat or not</p><p>expecting the help ASAP&#8230;pls</p> ]]></content:encoded> </item> <item><title>By: Debbie</title><link>http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-151838</link> <dc:creator>Debbie</dc:creator> <pubDate>Tue, 24 Nov 2009 19:41:02 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-151838</guid> <description>I want to test if any file ending in *.DATGO exists.
Do you always have to use the exact name of the file?</description> <content:encoded><![CDATA[<p>I want to test if any file ending in *.DATGO exists.<br
/> Do you always have to use the exact name of the file?</p> ]]></content:encoded> </item> <item><title>By: Fred</title><link>http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-151737</link> <dc:creator>Fred</dc:creator> <pubDate>Tue, 17 Nov 2009 13:31:10 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-151737</guid> <description>For me, it only works without variables, like
if [ -f /home/user/hey.jpg ]; then
....
else
....
fi
Worth trying.</description> <content:encoded><![CDATA[<p>For me, it only works without variables, like</p><p>if [ -f /home/user/hey.jpg ]; then<br
/> &#8230;.<br
/> else<br
/> &#8230;.<br
/> fi</p><p>Worth trying.</p> ]]></content:encoded> </item> <item><title>By: Rajee</title><link>http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-150992</link> <dc:creator>Rajee</dc:creator> <pubDate>Fri, 09 Oct 2009 10:06:40 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-150992</guid> <description>How to check some set of files in the following directory and do the process.
my statement following is not working: pls explain
if [ -f &quot;$ROOT/abc/files/CUST*&quot; ]; then
echo &quot;inside customer file exists&quot;
else
echo &quot;No customer file exists&quot;
fi
CUST is the post fix of the files, expected to have more than 1 file on some days.</description> <content:encoded><![CDATA[<p>How to check some set of files in the following directory and do the process.<br
/> my statement following is not working: pls explain<br
/> if [ -f "$ROOT/abc/files/CUST*" ]; then<br
/> echo &#8220;inside customer file exists&#8221;<br
/> else<br
/> echo &#8220;No customer file exists&#8221;<br
/> fi<br
/> CUST is the post fix of the files, expected to have more than 1 file on some days.</p> ]]></content:encoded> </item> <item><title>By: Zach</title><link>http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-150896</link> <dc:creator>Zach</dc:creator> <pubDate>Thu, 01 Oct 2009 20:52:17 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-150896</guid> <description>I just hacked this together.  I plan to use it for my other scripts. The exit statements make the script exit with a 0 (bash standard for successful completion) or a 1 (non-zero is the bash standard for a failed action)
&lt;blockquote&gt;
#!/bin/bash
FILE=$1
if [ -f $FILE ];
then
exit 0
else
exit 1
fi
&lt;/blockquote&gt;</description> <content:encoded><![CDATA[<p>I just hacked this together.  I plan to use it for my other scripts. The exit statements make the script exit with a 0 (bash standard for successful completion) or a 1 (non-zero is the bash standard for a failed action)</p><blockquote><p> #!/bin/bash<br
/> FILE=$1</p><p>if [ -f $FILE ];<br
/> then<br
/> exit 0<br
/> else<br
/> exit 1<br
/> fi</p></blockquote> ]]></content:encoded> </item> <item><title>By: Bram</title><link>http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-148005</link> <dc:creator>Bram</dc:creator> <pubDate>Mon, 06 Apr 2009 09:02:48 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-148005</guid> <description>Bash knows the NOT procedure for IF.  So No ELSE would be used.  watch the !
&lt;pre&gt;#!/bin/bash
FILE=$1
if [ ! -f $FILE ];
then
echo &quot;File $FILE does not exists&quot;
fi&lt;/pre&gt;</description> <content:encoded><![CDATA[<p>Bash knows the NOT procedure for IF.  So No ELSE would be used.  watch the !</p><pre>#!/bin/bash
FILE=$1
if [ ! -f $FILE ];
then
   echo "File $FILE does not exists"
fi</pre>]]></content:encoded> </item> <item><title>By: Don Petrus</title><link>http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-146695</link> <dc:creator>Don Petrus</dc:creator> <pubDate>Wed, 14 Jan 2009 15:03:22 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-146695</guid> <description>Hello Volks:
I would like to look for a File: if it exists - AND -  it´smaller (lt/gt)  than  1000000,  then ... echo &quot; File too small&quot; , return 1 ... and so on:
#!/bin/bash
FILE=nec2.txt
if   -f  [ &quot;$FILE&quot; ]  &amp;&amp;  -f  [ &quot;$FILE&quot;  -lt 1000000 ] ;
then
echo &quot;File $FILE too small&quot;
else
echo &quot;File $FILE does not exists&quot;
fi
-rw-rw----    1 cas      lokus    31626 2008-12-15 14:00 xnec2.txt
I use linux 2.4.21-278-smp
Can you please  help there ?   Pleas reply to  donpetrus@hotmail.com
Many thanks in advance - Petrus</description> <content:encoded><![CDATA[<p>Hello Volks:<br
/> I would like to look for a File: if it exists &#8211; AND &#8211;  it´smaller (lt/gt)  than  1000000,  then &#8230; echo &#8221; File too small&#8221; , return 1 &#8230; and so on:</p><p>#!/bin/bash<br
/> FILE=nec2.txt<br
/> if   -f  [ "$FILE" ]  &amp;&amp;  -f  [ "$FILE"  -lt 1000000 ] ;<br
/> then<br
/> echo &#8220;File $FILE too small&#8221;<br
/> else<br
/> echo &#8220;File $FILE does not exists&#8221;<br
/> fi</p><p>-rw-rw&#8212;-    1 cas      lokus    31626 2008-12-15 14:00 xnec2.txt</p><p>I use linux 2.4.21-278-smp</p><p>Can you please  help there ?   Pleas reply to <a
href="mailto:donpetrus@hotmail.com">donpetrus@hotmail.com</a><br
/> Many thanks in advance &#8211; Petrus</p> ]]></content:encoded> </item> <item><title>By: thant</title><link>http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-146061</link> <dc:creator>thant</dc:creator> <pubDate>Mon, 08 Dec 2008 16:57:45 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html#comment-146061</guid> <description>DatePart=`date &#039;+%m%d%Y`
FileName =DataFile_${DatePart}.csv</description> <content:encoded><![CDATA[<p>DatePart=`date &#8216;+%m%d%Y`<br
/> FileName =DataFile_${DatePart}.csv</p> ]]></content:encoded> </item> </channel> </rss>
