I\'m trying to write a script that will display the name of oldest file within the directory that the script is executed from.
This is what I have so far:
You can use this function to find oldest file/directory in any directory:
oldest() {
oldf=
for f in *; do
# not a file, ignore
[[ ! -f "$f" ]] && continue
# find oldest entry
[[ -z "$oldf" ]] && oldf="$f" || [[ "$f" -ot "$oldf" ]] && oldf="$f"
done
printf '%s\n' "$oldf"
}
And call it in any directory as:
oldest