Last active
February 28, 2024 05:50
-
-
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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