Check for a file and touch if not exist

Hi,

I've a situation where i need to check for the file existence and create a zero byte file based on the parameter,in some cases i need to touch and in some case i dont need to touch with zero byte file please help me on parameterizing this touch command??

Regards.
San

1 Like

Just

touch filename

.
If filename exists, only its modification and access times will be changed. Data will remain the same.
If filename does not exist, a zero-byte file will be created with the current time as the access and modification time.

And if you don't want to modify the access and modification times when the file (a regular file) exists, try:

[[ -f filename ]] || touch filename

.

1 Like

i need to have a touch file based on the argument i dont need it all the time only when needed..