Bash command to create a new file and its parent directories if necessary

bash, shell

Solution

install is your friend:

install -Dv /dev/null some/new/path/base-filename

Problem

With the `-p` (`--parents`) option, `mkdir` creates parent directories if necessary. `touch`, `vim` or `>` can create new files in bash, but only when the parent directories exist. How to create a new file and its parent directories if necessary, in one command? Just like what the `-p` does for `mkdir`

Original source