Categorize
Jump to navigation
Jump to search
== fix type 2 == find -type f |sed -rn 's#^(.*/|)([^/]*)\.([^\./]*[a-zA-Z]{2,}[^\./]*)[\.\-]([0-9TZtz_\.\-]{4,})$#\1;\2;\3;\4#p' |while IFS=';' read dirMy fileMy typeMy dateMy ;do mv -vn "${dirMy}${fileMy}.${typeMy}"?"${dateMy}" "${dirMy}${dateMy}-${fileMy}.${typeMy}" ;done #== Categorize types == nbTypes=32 optionsMy= #update find -empty -type d -delete #all dirs >/tmp/typeList$$ >/tmp/typeList$$.new ls -a1 |grep -vE "^\.{,2}$" |while read lineMy ;do if [ -d "${lineMy}" ] ;then # echo "${lineMy}" ;done |while read lineMy ;do #check if type dir MyPatern='^.*\.([a-z0-9A-Z_]+)$' typeName="$(find "${lineMy}" -type f |head -1 |sed -rn "s#$MyPatern#\1#p")" if [ "${typeName}" == "${lineMy}" ] ;then echo "${typeName}" >>/tmp/typeList$$ else echo "${lineMy}" fi else echo "${lineMy}" fi done >/tmp/categorize$$.statNewTypes [ "${optionsMy}" != "update" ] &&cat /tmp/categorize$$.statNewTypes |while read dirName2 ;do find "$dirName2" -type f |head -${nbTypes} done |head -1024 |while read MyFile ;do MyPatern='^.*[^/]+\.([a-z0-9A-Z]+)$' echo "$MyFile" |sed -rn "s#$MyPatern#\1#p" |head -1 # done |sort |uniq -c |sort -gr |head -${nbTypes} |awk '{if ( $1 > 4 ) {$1="" ;print }}' |cut -c-1 --complement >>/tmp/typeList$$.new done |sort |uniq -c |sort -gr |head -${nbTypes} |awk '{$1="" ;print }' |cut -c-1 --complement >>/tmp/typeList$$.new (cat /tmp/typeList$$ ;cat /tmp/typeList$$.new) |sort -u >/tmp/typeList$$2 mv -f /tmp/typeList$$2 /tmp/typeList$$ cat /tmp/typeList$$.new |while read MyType ;do mkdir "${MyType}" 2>/dev/null &&chown noname "${MyType}" done ls -a1 |grep -vE "^\.{,2}$" |grep -vw -f /tmp/typeList$$ >/tmp/dirList$$ cat /tmp/dirList$$ |while read lineMy ;do find "${lineMy}" -type f done |while read MyFile ;do typeName=$(echo "${MyFile}" |sed -rn 's#^(.*)\.([^\.]*)|([^\.]+)$#\2#p') echo "${typeName}" |grep -E ^- ||( if [ ! -z "$(grep -x "${typeName}" /tmp/typeList$$)" ] ;then dirName="$(dirname "${MyFile}" )" mkdir -p "${typeName}/${dirName}" ||echo "${typeName}/${dirName}" chown --reference="${dirName}" "${typeName}/${dirName}" chmod --reference="${dirName}" "${typeName}/${dirName}" mv -vn "${MyFile}" "${typeName}/${MyFile}" fi ) done find -type d -exec chown noname {} \; == dir fix duplicate words == #directories detox -r ./* ./\.[^\.]* ./\.\.?* ~/sh/caseFix.sh find -xdev -empty -type d -delete ~/sh/remove-duplicate-words-dir.sh #=== Rename orphans files === ~/sh/caseFix.sh find -xdev -type l -delete find -xdev -empty -delete ~/sh/rename-orphans-files.sh find -xdev -empty -delete find -xdev -type d -exec chown noname {} \; == metadata fix duplicate words == #directories detox -r ./* ./\.[^\.]* ./\.\.?* ~/sh/caseFix.sh find -xdev -empty -type d -delete ~/sh/remove-duplicate-words-dir.sh #files find ./* ./\.[^\.]* ./\.\.?* -xdev -type f |while read My ;do oldName=$(basename "${My}" |sed -rn 's#^(.*)\.([^\.]*)|([^\.]+)$#\1\3#p') typeName=$(basename "${My}" |sed -rn 's#^(.*)\.([^\.]*)|([^\.]+)$#\2#p') dirName="$(dirname "$My")" # remove word from dir #echo "${oldName}" |tr '_, ' '-' >/tmp/newName$$ echo "${oldName}" |tr '_, ' '-' >/tmp/newName$$ (echo "${dirName}" |sed -r "s#[^[:alnum:]]#\n#gI" ;echo "${typeName}" )|grep . |sort -u |while read My2 ;do cat /tmp/newName$$ |sed -r "s#\b${My2}\b[^[:alnum:]]*##gI" >/tmp/newName$$2 mv -f /tmp/newName$$2 /tmp/newName$$ done #reverse cat /tmp/newName$$ |rev >/tmp/newName$$2 mv -f /tmp/newName$$2 /tmp/newName$$ # remove duplicates countMy=32 while [ ! -z "$(cat /tmp/newName$$ |sed -r "s#[^[:alnum:]]#\n#gI" |tr '[:upper:]' '[:lower:]' |grep . |sort |uniq -c |awk '{if ($1>1) print $2}' |tee /tmp/duplicatesWords$$)" ] ;do cat /tmp/duplicatesWords$$ |while read My2 ;do cat /tmp/newName$$ |sed -r "s#[^[:alnum:]]*\b${My2}\b##I" >/tmp/newName$$2 mv -f /tmp/newName$$2 /tmp/newName$$ done countMy=$((countMy-1)) && [ $countMy -le 0 ] &&break done #newName=$(cat /tmp/newName$$ |rev |sed -r 's#\.+#\.#g' |sed -r 's#\-+#-#g' |sed -r 's#\.\-#-#g' |sed -r 's#\-\.#-#g' |sed -r 's#\-+$##' |sed -r 's#\.+$##' |sed -r 's#^\-+##' |sed -r 's#^\.+##') newName=$(cat /tmp/newName$$ |rev |sed -r 's#[-\.]+$##' |sed -r 's#^[-\.]+##' |sed -r 's#[-\.]{2,}#-#g') newType="${typeName}" if [ ! -z "${typeName}" ] ;then typeName=".${typeName}" newType="$(echo $typeName |tr '[:upper:]' '[:lower:]')" fi [ "${oldName}${typeName}" != "${newName}${newType}" ] &&mv -vn "${dirName}/${oldName}${typeName}" "${dirName}/${newName}${newType}" done == classificate by small word == word1=Luc [ ! -d "${word1}" ] &&mkdir "${word1}" &&chown noname "${word1}" find -type d -iname "*${word1}*" |grep -vE "^\.{,2}$" |grep -vE "^\./${word1}$" |grep -iE '\b'"${word1}"'\b' |while read lineMy ;do echo "== ${lineMy} ==" newPath="${word1}/$(echo ${lineMy} |sed -r 's#\b'"${word1}"'\b##gI')" newDir="$(dirname "${newPath}")" if [ -d "${newPath}" ] ;then mv -vn "${lineMy}"/* "${lineMy}"/\.[^\.]* "${lineMy}"/\.\.?* "${newPath}"/. rmdir "${lineMy}" else [ ! -d "${newDir}" ] &&mkdir -p "${newDir}" &&chown noname "${newDir}" mv -vn "${lineMy}" "${newPath}" fi done find -type f -iname "*${word1}*" |grep -vE "^\./${word1}/" |grep -iE '\b'"${word1}"'\b' |while read lineMy ;do echo "== ${lineMy} ==" newPath="${word1}/$(echo ${lineMy} |sed -r 's#\b'"${word1}"'\b##gI')" newDir="$(dirname "${newPath}")" if [ ! -f "${newPath}" ] ;then [ ! -d "${newDir}" ] &&mkdir -p "${newDir}" &&chown noname "${newDir}" mv -vn "${lineMy}" "${newPath}" fi done find -empty -type d -delete find "${word1}" -type d -exec chown noname {} \; == classificate by word (5 or more letters) == word1=archive [ ! -d "${word1}" ] &&mkdir "${word1}" &&chown noname "${word1}" find -xdev -type d -iname "*${word1}*" |grep -vE "^\.{,2}$" |grep -vE "^\./${word1}$" |while read lineMy ;do echo "== ${lineMy} ==" newPath="${word1}/$(echo ${lineMy} |sed 's#'"${word1}"'##gI')" newDir="$(dirname "${newPath}")" if [ -d "${newPath}" ] ;then mv -vn "${lineMy}"/* "${lineMy}"/\.[^\.]* "${lineMy}"/\.\.?* "${newPath}"/. rmdir "${lineMy}" else [ ! -d "${newDir}" ] &&mkdir -p "${newDir}" &&chown noname "${newDir}" mv -vn "${lineMy}" "${newPath}" fi done find -xdev -type f -iname "*${word1}*" |grep -vE "^\.{,2}$" |grep -vE "^\./${word1}/" |while read lineMy ;do echo "== ${lineMy} ==" newPath="${word1}/$(echo ${lineMy} |sed 's#'"${word1}"'##gI')" newDir="$(dirname "${newPath}")" if [ ! -f "${newPath}" ] ;then [ ! -d "${newDir}" ] &&mkdir -p "${newDir}" &&chown noname "${newDir}" mv -vn "${lineMy}" "${newPath}" fi done find -xdev -empty -type d -delete find "${word1}" -type d -exec chown noname {} \;