Say I have a long path such as:
/a/b/c/d/e/f
I would like to run a command only on each of the subpaths of the path:
e.g. If my command is cmd
, I am looking for a one-liner that can do (perhaps using a one-line loop)
cmd /a
cmd /a/b
cmd /a/b/c
cmd /a/b/c/d
cmd /a/b/c/d/e
cmd /a/b/c/d/e/f
One of the reasons why I need this (I need it for other things as well), is because I would like to give somebody from my unix group the ability to cd
incrementally her way to /a/b/c/d/e/f
. To do this, I think I need to run chmod g+x
on each of these subpaths (not sure if there is an alternative). Note that I want to avoid chmod -R g+x /a
.
I work primarily on zsh so I wonder if there is anything that takes advantage of specific zsh features.
dirname
could be used recursively from the commandline, but I don't see that happen. +1 for cleanest script. – Bernhard Apr 20 '12 at 21:14