Bulk Replace Netatalk character set file name with shell script

Source: Internet
Author: User
Tags character set chmod hex code

A period of time before a batch to modify the file name, is a Debian file server, for the Mac to provide file sharing services, the Chinese part of the Use of encoding (check the data, should be, not to actually verify), the specific coding principles are as follows:

A character name stored on a Linux server is PRODUCT_LIST:B2:FA:C6:B7:C4:BF:C2:BC, encoded in CP936, but no Chinese is available. The encoding is converted by: The following two-bit character is corresponding to the CP936 character set of a character (half Chinese characters) of the hex code, such as the above file name conversion should be: Product_list product catalog, see the conversion mode below.

Inner Code GB2312

00000000 B2 FA C6 B7 C4 BF C2 BC Product Catalog
00000008 00 00 00 00 00 00 00 00 ...

In this case, because of changes in the storage structure that need to be collated, and how long the original Mac platform and Debian platform have been scrapped (this part of the data is archived data), there is a need for a means to convert the file name to a normal character set.

My idea is: First use Find all contain ":" The file or directory name, and then use MV will be in the filename of ":" Batch replaced with "%", and finally through the CONVMV character to normal CP936 encoded words.

As a result of the recent collation of information found this case, very depressed, the final program has been deleted by me, can not recover from the (loss of my data Recovery Expert's name, hehe). Just find a draft, write it down first, and then encounter a similar situation in the future. If you have any better suggestions or comments, leave a message for me.

Suppose the resulting SH file name is t.sh, which is roughly as follows:

echo >/testsh/t1.sh
echo >/testsh/t2.sh
find $1 -depth -type $2 -name "*\:*" -exec $3 {} \;|while read -r linet
do
line="`echo "$linet"|sed -e 's#)#\\\\)#g' -e 's/(/\\\\(/g' -e 's/&/\\\\&/g' -e 's/:/\\\\:/g' -e "s/'/\\\\\'/g"`"
echo "mv "$line" "`echo "$line"|sed -e 's/\:/%/g' -e 's/\^M//g'`" ;" >>/testsh/t1.sh
echo "convmv --notest --unescape "`echo "$line"|sed 's/\:/%/g'`" ;" >>/testsh/t2.sh
done
chmod +x /testsh/t1.sh
/testsh/t1.sh
chmod +x /testsh/t2.sh
/testsh/t2.sh

/testsh/t2.sh

After performing the above sh, will generate t1.sh and t2.sh, the first continuous execution of "T.sh/data_dir D echo", and so on completion of all execution, then execute "T.sh/data_dir f echo".

Remember straight is solving problems, fixed a lot of problems, now also think not too much, but the idea is still feasible. Let's keep it that way for the time being.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.