If file not exist create a new one


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting If file not exist create a new one
# 1  
Old 05-28-2008
If file not exist create a new one

i want a script to check whether the file name exits or not if not it has to create a new one
# 2  
Old 05-28-2008
What did you try so far..??
# 3  
Old 05-28-2008
test -e fff.txt || touch fff.txt

It will create an empty file fff.txt if it doesn't exist.

Other thing when you use cat > <file> It also create the file if is not present and if it present it over writes the contents.
# 4  
Old 05-28-2008
This sounds like homework.

I would also like to know what you tried so far.

For what it's worth, the answer is in siba.s.nayak's post, although it is a lot less complicated than what siba indicated.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find if a User exist if not create user

What I'm trying to do is write a script in Perl to find a user and if that user exist it would print "User Exist, Pls Try Again". If The user doesn't exist I'm able to create a user with a password. Any suggestions? (3 Replies)
Discussion started by: GoBoyGo
3 Replies

2. Shell Programming and Scripting

Create user if UID not exist; else, exit the script

Hi, I want to write a script to check whether an user ID is used in my server and then create that user. If the user ID is not used, I will echo something like "OK, continue" and then continue to execute the script. Else, I will echo something like "Used, exit" and then exit the script. As... (4 Replies)
Discussion started by: dirkaulo
4 Replies

3. Linux

Create a dummy file even if the path is not exist

hi, i want to create a dummy file even if the path to that file is not exist as follows. suppose, in my working directory 2 files are there. and i create one more file which is exist as follows # pwd /home/satya # ls file1.txt file2.txt # echo dummy > /home/satya/file3.txt # ls... (3 Replies)
Discussion started by: snreddy_gopu
3 Replies

4. Shell Programming and Scripting

Grepping file and returning passed variable if the value does not exist in file at all.

I have a list of fields that I want to check a file for, returning that field if it not found at all in the file. Is there a way to do a grep -lc and return the passed variable too rather then just the count? I am doing some crappy work-around now but I was not sure how to regrep this for :0 so... (3 Replies)
Discussion started by: personalt
3 Replies

5. UNIX for Dummies Questions & Answers

Any options with "cp" to create a folder if it doesn't exist.

I've created a backup and restore script and it's working fine so it's all about making it more robust at the moment for me. Let's say the user has a folder in their home directory for word processing files called "wp". I want to copy the files I made a backup of from this directory back into it.... (2 Replies)
Discussion started by: EwanD
2 Replies

6. Shell Programming and Scripting

check if multiple directories exist else create missing directories

Hi , I 'm trying to check if multiple directories exist on a server, if not create the missing ones and print " creating missing directory. how to write this in a simple script, I have made my code complex if ; then taskStatus="Schema extract directory exists, checking if SQL,Count and... (7 Replies)
Discussion started by: ramky79
7 Replies

7. Shell Programming and Scripting

How to Check whether list file present in TXT file exist or not

Hi All, I have txt file which has list of files. I have to check whether these files exist or not. Thanks supriya (6 Replies)
Discussion started by: supriyabv
6 Replies

8. Shell Programming and Scripting

To check whether a directory is exist and if it is not, create it

Hi, I want to write a shell script to check whether a directory (say A) is existing in a given location and if it is not, create it. (3 Replies)
Discussion started by: sabya
3 Replies

9. Shell Programming and Scripting

Have a shell script check for a file to exist before processing another file

I have a shell script that runs all the time looking for a certain type of file and then it processes the file through a series of other scripts. The script is watching a directory that has files uploaded to it via SFTP. It already checks the size of the file to make sure that it is not still... (3 Replies)
Discussion started by: heprox
3 Replies

10. UNIX for Dummies Questions & Answers

how to check if the file exist or not?

say i would like to check if the file is existed before i use rm command. How can i do it? i know if i can use find, but i would like to have a good interface (in a shell script) thks (3 Replies)
Discussion started by: gusla
3 Replies
Login or Register to Ask a Question