ollie/tools/file_glob

15 lines
453 B
Bash
Executable File

#!/usr/bin/env bash
# description: Find files by name/path pattern, sorted by modification time (newest first)
# Args: <pattern> [path]
pattern="$1"
search_path="${2:-$PWD}"
[ -z "$pattern" ] && echo "usage: file_glob <pattern> [path]" && exit 1
# collect matches and sort by mtime descending
rg --no-config --files -g "$pattern" "$search_path" 2>/dev/null \
| xargs -d '\n' stat --printf '%Y\t%n\n' 2>/dev/null \
| sort -rn \
| cut -f2-