Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

up vote 3 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

 
discard

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.