Created
December 7, 2011 00:54
-
-
Save c00kiemon5ter/1440866 to your computer and use it in GitHub Desktop.
find no symlinked 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/sh | |
localdir="/tmp/test" # which directory to check | |
filelist="/tmp/filelist" # where to store regular file names | |
symlist="/tmp/symlist" # where to store symlinks file names | |
results="/tmp/results" # where to store file names that have no symlink pointed to them | |
cd "$localdir" | |
# seperate files and symlinks | |
for file in *; do | |
[ -L "$file" ] && echo "$file" >> "$symlist" \ | |
|| echo "$file" >> "$filelist"; | |
done | |
# check if each file is referenced by any symlink | |
while read -r file; do | |
while read -r smlnk; do | |
match=0 | |
[ "$(readlink "$smlnk")" = "$file" ] && match=1 && break; | |
done <"$symlist" | |
[ "$match" = 0 ] && echo "$file" >> "$results" | |
done <"$filelist" | |
# display results | |
cat "$results" | |
# cleanup | |
rm -f "$filelist" "$symlist" "$results" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
a test case:
one can extend the script to read the
localdir
as an argumentor even use
fd
s to eliminate the fileshave fun o/