Skip to content

Instantly share code, notes, and snippets.

@hotta
Last active February 28, 2024 05:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hotta/2158a727c55435172924dc27caad6f9d to your computer and use it in GitHub Desktop.
Save hotta/2158a727c55435172924dc27caad6f9d to your computer and use it in GitHub Desktop.
Scans the directories immediate under /home and find the last updated files (excluding dot files).
#!/bin/bash
#
# /home/直下のディレクトリをスキャンし、ユーザーごとに最終更新ファイルを表示する(ドットファイルは除く)。
# 該当ファイルがない場合はディレクトリ名(ユーザー名)を表示する。
#
TMP_OUTPUT=/tmp/a.txt
if [ "$#" -eq 1 ]; then
TARGET="$1"
fi
cd /home
for dir in * ; do
if [[ -n "$TARGET" ]] && [[ "$dir" != "$TARGET" ]]; then
continue
fi
sudo find "$dir" -f -printf '%T+ %p\n' |\
grep -vE '(\.bash|\.ansible|\.cache|\.local|\.ssh|\.viminfo|\.vault_password|\.mozilla|\.zshrc|\.config|\.lesshst|\.snmp|\.recv)' |\
sort -r > "$TMP_OUTPUT"
if [ "$(wc -l "$TMP_OUTPUT" | awk '{ print $1 }')" -eq 0 ] ; then
echo "$dir"
else
CPATH="$(head -1 "$TMP_OUTPUT" | awk '{ print $2 }')"
if [ "$CPATH" = "$dir" ] ; then
head -2 "$TMP_OUTPUT" | tail -1
else
head -1 "$TMP_OUTPUT"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment