I love "mkdir -p", it is one of my favorite linux commands but, one thing that I wish, was there was a "-p" equivalent for "touch"

@mcc This inspired me to write and test a somewhat robust shellscript function for inclusion in ~/.shrc or ~/.bashrc:

touchp() { for file in "$@"; do mkdir -p "$( dirname "$file" )" && touch "$file"; done; }

@arielmt @mcc Nitpicking, but dirname is non posix. ${file%/*} accomplishes the same though.

Follow

@nico @mcc I relied on pubs.opengroup.org/onlinepubs/ for availability.

That noted, "${file%/*}" is both faster and more elegant. I like it. (It does fail silently and probably bad if a pathname ends with a slash, though.)

@arielmt @mcc OMG. I have to retract my previous statement and call myself old. It wasn't there last time I checked, I swear!

Sign in to participate in the conversation
Computer Fairies

Computer Fairies is a Mastodon instance that aims to be as queer, friendly and furry as possible. We welcome all kinds of computer fairies!