From 1288b47c344f52fa38209e88e7016979f773953f Mon Sep 17 00:00:00 2001 From: fatalerrors Date: Tue, 2 Jun 2026 13:54:01 +0200 Subject: [PATCH] added support for fd when available --- profile.d/filefct.sh | 66 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/profile.d/filefct.sh b/profile.d/filefct.sh index e5fe4e1..355dd0b 100644 --- a/profile.d/filefct.sh +++ b/profile.d/filefct.sh @@ -637,7 +637,25 @@ findbig() find_args+=(-type f) # Logic: find files, print size and path, sort numeric reverse, take N - if (( details )); then + 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 + "$_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" | while IFS= read -r line; do local path="${line#* }" @@ -713,7 +731,27 @@ findzero() (( one_fs )) && find_args+=("-xdev") # Execution logic - if (( delete )); then + 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 + 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..." find "${find_args[@]}" -delete -print elif (( details )); then @@ -787,7 +825,29 @@ finddead() (( one_fs )) && find_args+=("-xdev") # Execution logic - if (( delete )); then + 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 + 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..." find "${find_args[@]}" -delete -print elif (( details )); then