Created
February 5, 2026 19:07
-
-
Save guilsa/e38a31857edc629852fe7ae05b416fb3 to your computer and use it in GitHub Desktop.
Find user symlinks on macOS (~/bin, ~/dev, ~) without permission prompts
This file contains hidden or 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 | |
| # Features: | |
| # - Uses allow-list approach to avoid macOS permission prompts | |
| # - By default searches: ~/bin, ~/dev, and root of ~ only | |
| # - Only shows symlinks owned by you (filters by current user) | |
| # Usage: | |
| # # Search default locations (~/bin, ~/dev, root of ~) | |
| # find-symlinks | |
| # # Search a specific directory | |
| # find-symlinks /path/to/directory | |
| # # Search current directory | |
| # find-symlinks . | |
| # The script shows each symlink and what it points to in the format: | |
| # /path/to/symlink -> /path/to/target | |
| set -euo pipefail | |
| # Get current user | |
| CURRENT_USER=$(whoami) | |
| # If argument provided, search that directory | |
| if [[ $# -gt 0 ]]; then | |
| SEARCH_DIR="$1" | |
| if [[ ! -d "$SEARCH_DIR" ]]; then | |
| echo "Error: Directory '$SEARCH_DIR' does not exist" >&2 | |
| exit 1 | |
| fi | |
| echo "Searching for symlinks created by $CURRENT_USER in: $SEARCH_DIR" | |
| echo "---" | |
| find "$SEARCH_DIR" \ | |
| \( -name .git -o -name node_modules -o -name .Trash \) -prune -o \ | |
| -type l -user "$CURRENT_USER" \ | |
| -exec sh -c 'printf "%s -> %s\n" "$1" "$(readlink "$1")"' _ {} \; \ | |
| 2>/dev/null | sort | |
| else | |
| # Default: search specific allow-listed locations | |
| echo "Searching for symlinks created by $CURRENT_USER in default locations:" | |
| echo " - $HOME (root only, not recursive)" | |
| echo " - $HOME/bin" | |
| echo " - $HOME/dev" | |
| echo "---" | |
| # Search root of home (max depth 1) | |
| [[ -d "$HOME" ]] && find "$HOME" -maxdepth 1 -type l -user "$CURRENT_USER" \ | |
| -exec sh -c 'printf "%s -> %s\n" "$1" "$(readlink "$1")"' _ {} \; \ | |
| 2>/dev/null | |
| # Search ~/bin recursively (excluding common directories) | |
| [[ -d "$HOME/bin" ]] && find "$HOME/bin" \ | |
| \( -name .git -o -name node_modules -o -name .Trash \) -prune -o \ | |
| -type l -user "$CURRENT_USER" \ | |
| -exec sh -c 'printf "%s -> %s\n" "$1" "$(readlink "$1")"' _ {} \; \ | |
| 2>/dev/null | |
| # Search ~/dev recursively (excluding common directories) | |
| [[ -d "$HOME/dev" ]] && find "$HOME/dev" \ | |
| \( -name .git -o -name node_modules -o -name .Trash \) -prune -o \ | |
| -type l -user "$CURRENT_USER" \ | |
| -exec sh -c 'printf "%s -> %s\n" "$1" "$(readlink "$1")"' _ {} \; \ | |
| 2>/dev/null | |
| fi | sort | |
| echo "---" | |
| echo "Done." |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use this with https://github.com/guilsa/dotfiles/.