Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I can do:

mkdir messages

and then:

touch messages/hello.txt

Is there a command that will do both - create the directory if it doesn't exist, and then the empty file? Something like:

touch -p messages/hello.txt
share|improve this question
up vote 4 down vote accepted

Not with anything in coreutils, but here's a bash function for that:

mktouch() {
  mkdir -p "$(dirname "$1")"
  touch "$1"
share|improve this answer
thank you for your answer – deb May 10 '10 at 13:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.