Last active
November 23, 2020 16:22
-
-
Save lavoiesl/99289ed37e12923d9fc1efd1f396e51f to your computer and use it in GitHub Desktop.
Split paths into each components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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