There is no command available for creating a file and the parent directories in one step. Nevertheless you can help yourself with a simple bash script. Just add the following snippet to your ~/.bashrc.

mktouch() { mkdir -p $(dirname $1) && touch $1; }

Afterwards you can run this command like this: mktouch /home/demo/newdirectory/newfile1.txt

Source: https://unix.stackexchange.com/a/305850 -> Comments

revision: Wed Jan 10 10:55:47 2024 +0100 | fee8554 - history: /2020/09/17/2/post.md

Add your reply here with Webmention (you must link to this page in its canonical form)
Webmentions are approved manually. Will take some time until they show up.