how to automatically create a file?


 
Thread Tools Search this Thread
Operating Systems Linux how to automatically create a file?
# 1  
Old 03-12-2011
how to automatically create a file?

how can i automatically create a file on Linux? like a process that searches for the file and if the file does not exist, it automatically makes the file

Last edited by roozis; 03-12-2011 at 10:42 PM.. Reason: forgot a word
# 2  
Old 03-13-2011
In shell:
Code:
touch /path/to/file/filename

This creates an empty file if the file does not already exist. It also updates the file time to the time the command was executed.

This just creates the file but does not change file times on an existing file
Code:
[ -f  /path/to/file/filename ]  || >  /path/to/file/filename

This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 03-13-2011
what i dont understand is the second, how come is there 2 lines between the code?
# 4  
Old 03-13-2011
|| means OR that mean : if the left statement has a return code that differs from 0 then execute the statement that is on the right.

---------- Post updated at 05:32 PM ---------- Previous update was at 05:29 PM ----------

-f test the existence of the file : if false (return code differs from 0) then creates the file
This User Gave Thanks to ctsgnb For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Automatically correct a File Name

Hi All Need a help to understand how one can automatically correct a file name using a shell script even if it is in a completely different format... Ex : adv_OK_0215_mem_rules_firing.txt / advex_0215_OK_me_rule_fire.txt (or in any other format as above) to :... (13 Replies)
Discussion started by: chatwithsaurav
13 Replies

2. Shell Programming and Scripting

Opening a file in vi and automatically save and quit this file using shell script

Hi friends, In my shell script, I want to open a file using vi editor. After opening the file in vi, I want to save and quit this file automatically.... all through shell script. the code segment is: ------------------------------------------------------------ cd ~/netfpga/projects/scone/sw/... (2 Replies)
Discussion started by: sachinteotia
2 Replies

3. Shell Programming and Scripting

Retrieve multiple rows from mysql and automatically create a table

Hi, i want to create a table automatically based on another table (sms_key). For example; If user create a new row with sms_keyword field: IRC then a table created automatically (with some field on it, like: name, ph_number, messages). select * from sms_key; +-------------+ |... (1 Reply)
Discussion started by: jazzyzha
1 Replies

4. Shell Programming and Scripting

How to automatically create variables from user input in ksh?

I need some help to write a ksh script. My code so far (pretty bad, sorry): #! /bin/ksh echo "Calculate average" UserDecision=y while test $UserDecision = y do echo "Enter a number: " read Number1 echo "Enter a number: " read Number2 echo "Do you want to enter another number?... (2 Replies)
Discussion started by: johnagar
2 Replies

5. Shell Programming and Scripting

script file which will automatically create accounts

How tocreate a script file which will automatically create accounts from a csv file (2 Replies)
Discussion started by: donegal92
2 Replies

6. Solaris

Requesting help to automatically create home dir on login

I know we would not normally do this. However, I would like to have user's home directory created when they log in the first time. I have searched the forums and have not found any help yet. Scenario - environment uses NIS for auth and usually NFS mount HOME. However, I have a pilot environment... (4 Replies)
Discussion started by: 22blaze
4 Replies

7. Shell Programming and Scripting

automatically create password and expand it to other servers

I´m a new system administrator. I have to create a script to put in crontab to change periodically root password and didtribute it to other servers. I searched the posted threads but I didn't find my answer. I would like to do this using ssh and trusted keys. Can anyone help me? Thanks. Aldina (0 Replies)
Discussion started by: Alrica
0 Replies

8. Shell Programming and Scripting

automatically removing a file

Hello, Is there a script that i could write to automatically delete a file everytime that it is created (ex. i have an append file that is created everytime I run a program but I need it to get deleted automatically because everytime I run the program it add the original number of files... (3 Replies)
Discussion started by: TDS
3 Replies

9. Shell Programming and Scripting

Change file privileges automatically

Hi, Is it possible to write and run a shell script for specific directory( Apache/htdocs) that changes root privilege read/write to chmod 755 when a program uploads a file (word,PPT,XSL,..) to that directory Thanks, Mk (3 Replies)
Discussion started by: mkohan
3 Replies

10. Shell Programming and Scripting

How to create cron job automatically?

How do I write a perl script to get the cron jobs? I could do a perl -e ' system "crontab -l > jobs.txt " '; Is there a better way? Then I can use perl to make changes to jobs.txt. How can I submit the changes. I suppose I could use system "crontab jobs.txt", is there a better way? ... (0 Replies)
Discussion started by: siegfried
0 Replies
Login or Register to Ask a Question