added support for fd when available
This commit is contained in:
@@ -637,7 +637,25 @@ findbig()
|
|||||||
find_args+=(-type f)
|
find_args+=(-type f)
|
||||||
|
|
||||||
# Logic: find files, print size and path, sort numeric reverse, take N
|
# Logic: find files, print size and path, sort numeric reverse, take N
|
||||||
|
local _fd
|
||||||
|
_fd=$(command -v fd 2>/dev/null || command -v fdfind 2>/dev/null)
|
||||||
|
|
||||||
|
if [[ -n "$_fd" ]]; then
|
||||||
|
local _fd_args=(--follow --no-ignore --hidden --absolute-path -t f)
|
||||||
|
(( one_fs )) && _fd_args+=(--one-file-system)
|
||||||
|
_fd_args+=(. "$dir")
|
||||||
if (( details )); then
|
if (( details )); then
|
||||||
|
"$_fd" "${_fd_args[@]}" --exec stat --printf="%s %n\n" 2>/dev/null \
|
||||||
|
| sort -rn | head -n "$limit" \
|
||||||
|
| while IFS= read -r line; do
|
||||||
|
local path="${line#* }"
|
||||||
|
ls -ld -- "$path"
|
||||||
|
done
|
||||||
|
else
|
||||||
|
"$_fd" "${_fd_args[@]}" --exec stat --printf="%s %n\n" 2>/dev/null \
|
||||||
|
| sort -rn | head -n "$limit"
|
||||||
|
fi
|
||||||
|
elif (( details )); then
|
||||||
find "${find_args[@]}" -printf "%s %p\n" 2>/dev/null | sort -rn | head -n "$limit" |
|
find "${find_args[@]}" -printf "%s %p\n" 2>/dev/null | sort -rn | head -n "$limit" |
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
local path="${line#* }"
|
local path="${line#* }"
|
||||||
@@ -713,7 +731,27 @@ findzero()
|
|||||||
(( one_fs )) && find_args+=("-xdev")
|
(( one_fs )) && find_args+=("-xdev")
|
||||||
|
|
||||||
# Execution logic
|
# Execution logic
|
||||||
|
local _fd
|
||||||
|
_fd=$(command -v fd 2>/dev/null || command -v fdfind 2>/dev/null)
|
||||||
|
|
||||||
|
if [[ -n "$_fd" ]]; then
|
||||||
|
local _fd_args=(--follow --no-ignore --hidden --absolute-path -t f --size -1b)
|
||||||
|
(( one_fs )) && _fd_args+=(--one-file-system)
|
||||||
|
_fd_args+=(. "$dir")
|
||||||
if (( delete )); then
|
if (( delete )); then
|
||||||
|
disp W "Deleting empty files in $dir..."
|
||||||
|
"$_fd" "${_fd_args[@]}" 2>/dev/null | while IFS= read -r f; do
|
||||||
|
printf "%s\n" "$f"
|
||||||
|
rm -f -- "$f"
|
||||||
|
done
|
||||||
|
elif (( details )); then
|
||||||
|
"$_fd" "${_fd_args[@]}" 2>/dev/null | while IFS= read -r f; do
|
||||||
|
ls -ls -- "$f"
|
||||||
|
done
|
||||||
|
else
|
||||||
|
"$_fd" "${_fd_args[@]}" 2>/dev/null
|
||||||
|
fi
|
||||||
|
elif (( delete )); then
|
||||||
disp W "Deleting empty files in $dir..."
|
disp W "Deleting empty files in $dir..."
|
||||||
find "${find_args[@]}" -delete -print
|
find "${find_args[@]}" -delete -print
|
||||||
elif (( details )); then
|
elif (( details )); then
|
||||||
@@ -787,7 +825,29 @@ finddead()
|
|||||||
(( one_fs )) && find_args+=("-xdev")
|
(( one_fs )) && find_args+=("-xdev")
|
||||||
|
|
||||||
# Execution logic
|
# Execution logic
|
||||||
|
local _fd
|
||||||
|
_fd=$(command -v fd 2>/dev/null || command -v fdfind 2>/dev/null)
|
||||||
|
|
||||||
|
if [[ -n "$_fd" ]]; then
|
||||||
|
# fd -t l lists all symlinks; post-filter broken ones (target unreachable via -e)
|
||||||
|
local _fd_args=(--no-ignore --hidden --absolute-path -t l)
|
||||||
|
(( one_fs )) && _fd_args+=(--one-file-system)
|
||||||
|
_fd_args+=(. "$dir")
|
||||||
if (( delete )); then
|
if (( delete )); then
|
||||||
|
disp W "Deleting dead symlinks in $dir..."
|
||||||
|
"$_fd" "${_fd_args[@]}" 2>/dev/null | while IFS= read -r f; do
|
||||||
|
[[ -e "$f" ]] || { printf "%s\n" "$f"; rm -f -- "$f"; }
|
||||||
|
done
|
||||||
|
elif (( details )); then
|
||||||
|
"$_fd" "${_fd_args[@]}" 2>/dev/null | while IFS= read -r f; do
|
||||||
|
[[ -e "$f" ]] || ls -ls -- "$f"
|
||||||
|
done
|
||||||
|
else
|
||||||
|
"$_fd" "${_fd_args[@]}" 2>/dev/null | while IFS= read -r f; do
|
||||||
|
[[ -e "$f" ]] || printf "%s\n" "$f"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
elif (( delete )); then
|
||||||
disp W "Deleting dead symlinks in $dir..."
|
disp W "Deleting dead symlinks in $dir..."
|
||||||
find "${find_args[@]}" -delete -print
|
find "${find_args[@]}" -delete -print
|
||||||
elif (( details )); then
|
elif (( details )); then
|
||||||
|
|||||||
Reference in New Issue
Block a user