#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2010
    Posts
    1
    Rep Power
    0

    How to create a blank file if that file does not exists?


    Hi,

    I have a requirement like, I need to write a command which will check for a file and if the file does not exists in that directory then it will create a new file using touch command. If the file is already exists then it wouldn't do anything.

    Is it possible to get the result using any UNIX command?

    please help.

    Thanks in advance.

    Cheers,
    Satya.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2009
    Posts
    106
    Rep Power
    8
    Hi, you should be able to do what you want with:

    Code:
    #!/bin/bash
    
    file="path/to/your/file"
    
    if [[ ! -f $file ]]; then
      touch $file
    fi

    Live Support Chat for your website

IMN logo majestic logo threadwatch logo seochat tools logo