There are many Unix commands that will fail unless some subdirectory already exists, even though it would be a trivial matter for such commands to go ahead and create the missing subdirectory before proceeding.For example, for touch:% touch /tmp/foo/bar/baz/frobozztouch: cannot touch `/tmp/foo/bar/baz': No such file or directory% mkdir -p /tmp/foo/bar/baz% touch /tmp/foo/bar/baz/frobozz # succeedsSimilarly, for mv:% mv --target-directory=/tmp/foo/frotz/quux /tmp/foo/bar/frobozz% mv: failed to access `/tmp/foo/frotz/quux': No such file or directory% mkdir -p /tmp/foo/frotz/quux% mv --target-directory=/tmp/foo/frotz/quux /tmp/foo/bar/frobozz # succeedsOne notable exception to this behavior is mkdir itself, whose -p flag tells it to create subdirectories as needed.I am a bit puzzled by the fact that touch, mv, et al. won't do the obvious thing, either by default, or upon request via some flag (such as mkdir's -p).I figure there must be a very good reason for this, but it's not obvious to me.  Insights welcome.(The motivation for asking this is that I'd like to implement a utility that is pretty much like the (nonstandard) mmv utility, except that, contrary to the real mmv, it would create subdirectories as needed, and I'm wondering if this new feature would be A Really Bad Idea.For example, with the utility I'm thinking of—let me call it mmmv— one would be able to simultaneously move and rename the files1caf73ee55b4e11d6e3b12ccbf8c477c2839bfae1f37fd8ce865f98579d10d8045ac1e88c671721573f2af84ba8ed27fa332d52745274377aa67cda5a257a7c7cac26c391e8636193ff47b45c5e587ecto1c/af73ee55b4e11d6e3b12ccbf8c477c2839bfae1f/37fd8ce865f98579d10d8045ac1e88c6717215a2/57a7c7cac26c391e8636193ff47b45c5e587ec73/f2af84ba8ed27fa332d52745274377aa67cda5with a single command, like this:% mmmv '??*' '#1#2/#3'For this to be possible mmmv needs to be able to create the two-letter-named subdirectories as needed.)
On why touch, mv, etc., won't create subdirectories as needed
directory;utilities