Skip to content

Instantly share code, notes, and snippets.

@lavoiesl
Last active November 23, 2020 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lavoiesl/99289ed37e12923d9fc1efd1f396e51f to your computer and use it in GitHub Desktop.
Save lavoiesl/99289ed37e12923d9fc1efd1f396e51f to your computer and use it in GitHub Desktop.
Split paths into each components
#!/bin/bash
# Example:
# $ explode-path ~
# /
# /Users
# /Users/seb
# Great for recursively checking permissions
# One-liner:
# ls -1d ~ | while read p; do d="$p"; while true; do echo $d; [[ "$d" = "/" ]] && break; d="$(dirname "$d")"; done; done | sort | uniq | xargs ls -ld
# drwxr-xr-x 33 root wheel 1056 Jan 30 15:27 /
# drwxr-xr-x 5 root admin 160 Sep 25 17:38 /Users
# drwxr-xr-x+ 100 seb staff 3200 Feb 1 09:01 /Users/seb
ls -1d "$@" \
| while read p; do
d="$p"
while true; do
echo "$d"
[[ "$d" = "/" ]] && break
d="$(dirname "$d")"
done
done \
| sort | uniq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment