Sample Header Ad - 728x90

What can I use to get the paths of all parent directories for a given path

7 votes
6 answers
3452 views
I'm looking for a tool that I can use from a bash script that can give me the list of parent directories for a given path. e.g. given the input foo/bar/moocow I would like to get out:
foo
foo/bar
foo/bar/moocow
It would also be great if I could pipe in multiple paths, and get unique results back, e.g.:
toolimlookingfor << EOF
dir1/file1
dir1/file2
foo/bar/moocow
EOF
Output:
dir1
dir1/file1
dir1/file2
foo
foo/bar
foo/bar/moocow
dirname is close to what I'm looking for, but it only gives the immediate parent. I'm looking for the path it's self and all parents.
Asked by Gary van der Merwe (1830 rep)
Aug 1, 2020, 09:09 AM
Last activity: Feb 12, 2022, 03:55 PM