views:

38

answers:

2

I know I can do

mdkir -p a/b/c/d

However time and again I need to put a 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 those two operations.

+2  A: 

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

Steve K
A: 

In bash you could do:

 mkdir -p a/b/c && touch !#:2/foo.txt

But that's not exactly as terse as I think you want.

seth