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 as a point of note, i think this makes much more sense to be written as

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

(a) in "$@" is extraneous
(b) so is touch. unless of course you are actually using touch for touching instead of just making files, but seeing as it's most likely a fresh directory, that's unlikely

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!