Make parent directories while creating a new file
AFAIK, there is nothing standard like that, but you can do it your self:
ptouch() {
for p do
_dir="$(dirname -- "$p")"
mkdir -p -- "$_dir" &&
touch -- "$p"
done
}
Then you can do:
ptouch /path/to/directory/file1 /path/to/directory/fil2 ...
Some systems have a install
command that can be told to create missing path components.
With the GNU implementation of install
,
install -DTm644 /dev/null foo/bar/baz
Would create an empty baz
regular file with permission 0644 and would create the foo
and foo/bar
directories if missing (with permission 0755 regardless of the umask).