{"id":443,"date":"2018-01-25T13:51:28","date_gmt":"2018-01-25T13:51:28","guid":{"rendered":"https:\/\/mellowhost.com\/blog\/?p=443"},"modified":"2018-01-25T13:51:28","modified_gmt":"2018-01-25T13:51:28","slug":"programming-how-to-check-if-a-file-exists-or-not-in-bash-script","status":"publish","type":"post","link":"https:\/\/mellowhost.com\/blog\/programming-how-to-check-if-a-file-exists-or-not-in-bash-script.html","title":{"rendered":"Programming: How to Check If A File Exists or Not in Bash Script"},"content":{"rendered":"<h4>How to Check If A File Exists or Not in Bash Script<\/h4>\n<p>You can use if condition in bash script to do that. If conditions takes &#8216;-f&#8217; to test if a file exists or not. Syntax would be the following:<\/p>\n<p><code>$FILE = $1<br \/>\nif [ -f $FILE ]; then<br \/>\necho \"File Exists\"<br \/>\nelse<br \/>\necho \"File Do Not Exist\"<br \/>\nendif<\/code><\/p>\n<p>Now, if your script only demands to check if the file do not exist, you can use a unary operator for negate the boolean value as following:<\/p>\n<p><code>$FILE = $1<br \/>\nif[ ! -f $FILE ]; then<br \/>\necho \"File Do Not Exist\"<br \/>\nendif<\/code><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to Check If A File Exists or Not in Bash Script You can use if condition in bash script to do that. If conditions takes &#8216;-f&#8217; to test if a file exists or not. Syntax would be the following: $FILE = $1 if [ -f $FILE ]; then echo &#8220;File Exists&#8221; else echo &#8220;File &hellip; <a href=\"https:\/\/mellowhost.com\/blog\/programming-how-to-check-if-a-file-exists-or-not-in-bash-script.html\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Programming: How to Check If A File Exists or Not in Bash Script&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[282,193,12,271,191,21],"tags":[283,286,285,276,284],"_links":{"self":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts\/443"}],"collection":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/comments?post=443"}],"version-history":[{"count":1,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts\/443\/revisions"}],"predecessor-version":[{"id":444,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts\/443\/revisions\/444"}],"wp:attachment":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/media?parent=443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/categories?post=443"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/tags?post=443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}