canhaz: recursive touch in shell
If you're like me, you use touch
to create new files often. Often, you end up trying to create a file in a directory that doesn't yet exist, so you end up getting an error message, creating the directory with mkdir -p
, and then running the touch
command a second time. Well, that's a waste of time!
Drop the following shell function in your .bashrc
or .zshrc
or whatever wacky thing you use, and have a handy shortcut for the future.
#
# recursively touch, e.g. touch + mkdir -p
# so files can easily be created at depth
#
canhaz () {
mkdir -p -- "${1%/*}" && touch -- "$1"
}
Written by Matthew Rothenberg
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#