bash - Linux find files with similar name and move to new directory -
say have unorganized directory thousands of files have prefix in names abc-tab, abc-vib, h12-123, h12-498.... how move files same prefix own directory?
i thinking using like
find . -path '*/support/*abc*' -exec mv "{}" /new/abc\;
but means have retype command every prefix.
grab prefixes ls
, uniq
single list, move files using loop.
for f in $(ls | cut -d- -f1 | uniq); mkdir "${f}" && mv "${f}"-* "${f}" done
many people learn shell scripting advanced bash scripting guide. check out cut
, uniq
man pages details on programs.
Comments
Post a Comment