While the general problem of identifying extensions is hard, you can clean up the script a bit:
- Tell
findto only consider files with an extension:-iname '*.*' - Use
awkinstead ofcutting yourself: - Use a script, and then tell
findto exec that script.
Thus: a script called, say, move.sh:
#! /bin/bash
for i
do
ext=/some/where/else/$(awk -F. '{print $NF}' <<<"$i")
mkdir -p "$ext"
mv "$i" "$ext"
done
Then run find thus:
find . -name '*.*' -type f -exec move.sh {} +
This has the problem that you can't rearrange within the folder, so you could use xargs:
find . -name '*.*' -type f -print0 > /tmp/temp
xargs -0 move.sh < /tmp/tmp