I'm sure find
can do the whole job, I couldn't quite get the last step so resorted to using some bash
foo:
#/bin/bash
find . -maxdepth 1 -type f -regextype posix-extended -regex ".{255,}" |
while read filename
do
mv -n "$filename" "${filename:0:50}"
done
Using find
to get all the files with filename greater than or equal to 255 characters:
find . -maxdepth 1 -type f -regextype posix-extended -regex ".{255,}"
Truncate those filenames to 50 characters, -n
do not overwrite an existing file.
mv -n "$filename" "${filename:0:50}"
Note: Can this be with the -exec
option anyone?