Last Updated: February 25, 2016
·
279
· padawin

Script to create a file in a non-existing folder

Copy this script in a mtouch file and add the execution bit:

#!/bin/sh

[ ! -z $1 ] && (mkdir -p `dirname $1`; touch $1)

Then run it as follow:

/patch/to/mtouch /some/folder/which/does/not/exist/for/the/file/F

This will create the folder /some/folder/which/does/not/exist/for/the/file and then touch the file F in this folder.