Obtain the MD5 value of a string in shell.

Source: Internet
Author: User

Today's group asked a question:

Echo 123 | md5sum
Ba1f2511fc30423bdbb183fe33f3dd0f-

Php-R "Echo MD5 ('20140901 ');"
202cb962ac59075b964b07152d234b70

The MD5 values of the two are inconsistent, so there are many interesting solutions:

1 MySQL solution:

Mysql> select MD5 ('20140901 ');
+ ---------------------------------- +
| MD5 ('20140901') |
+ ---------------------------------- +
| 202cb962ac59075b964b07152d234b70 |
+ ---------------------------------- +



2. Modify the linefeed Method

[Root @ fetion ~] # Printf 123 | md5sum
202cb962ac59075b964b07152d234b70-
[Root @ fetion ~] # Echo-n123 | md5sum
202cb962ac59075b964b07152d234b70-
[Root @ fetion ~] # Echo 123 | tr-d' \ n' | md5sum
202cb962ac59075b964b07152d234b70-



Summary:

1 echo ends with line breaks by default
2 echo-N can remove line breaks
3. printf does not end with a line break.
4 Tr can delete a character, such as tr-d' \ n'
5. execute a program in the php Command Line: PHP-R "code"

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.