Easy way to create a file nested in inaccessible directories
I know what I can do
mdkir -p a/b/c/d
However time and again I need to put the file in a new directory. So this is what i do
mkdir -p a/b/c
touch a/b/c/foo.txt
I was wondering if there is an easy way to combine these two operations.
+2
Roger
source
to share
2 answers
In Bash shell, create a function in your .bashrc file.
function mktouch {
mkdir -p $( dirname $1 )
touch $1
}
Then just call mktouch a / b / c / foo.txt
+4
Steve k
source
to share
In bash, you can do:
mkdir -p a/b/c && touch !#:2/foo.txt
But that's not exactly how I think you want it.
+1
seth
source
to share