Rename-orphans-files.sh: Difference between revisions
Jump to navigation
Jump to search
(Created page with "<pre> #!/bin/sh find ./* ./\.[^\.]* ./\.\.?* -type d |while read MyPath ;do MyCount=$(ls -a1 "$MyPath" |grep -vE "^\.{,2}$" |wc -l) if [ "${MyCount}" -lt "4" ] ;then...") |
(No difference)
|
Latest revision as of 11:55, 29 October 2019
#!/bin/sh
find ./* ./\.[^\.]* ./\.\.?* -type d |while read MyPath ;do
MyCount=$(ls -a1 "$MyPath" |grep -vE "^\.{,2}$" |wc -l)
if [ "${MyCount}" -lt "4" ] ;then
ls -a1 "$MyPath" |grep -vE "^\.{,2}$" |while read MyFile ;do
filterMy=$(
MyPatern='^(.*)/[^/]*$'
echo "$MyPath" |\
sed -rn "s#$MyPatern#\1#p" |head -1
)
MyNewPath="$filterMy"
filterMy=$(
MyPatern='^.*/([^/]*)$'
echo "$MyPath" |\
sed -rn "s#$MyPatern#\1#p" |head -1
)
MyDirName="$filterMy"
mv -vn "${MyPath}/${MyFile}" "${MyNewPath}/${MyDirName}-${MyFile}"
done
fi
done
find . -xdev -empty -delete