One LINUX command a day - md5

I believe everyone is familiar with md5. It is often used in the development process. A common scenario is to prevent tampering during information transmission. For example, a file F is transferred from A to B, and an md5 is generated at point A. When reaching point B, generate an md5 and compare whether the two md5 values ​​are consistent. If they are consistent, it means that the file has not been tampered with during transmission.

Another example is to use md5 to achieve idempotence, what is idempotence, one or more requests initiated by the user, the results obtained are consistent. For example, in the case of not modifying the data, every time select * from test where id = 1 is executed; the result is the same every time. Query operations have no effect, but for new additions, duplicate data will be generated. When adding, we keep the md5 value of the request. When the next request comes, compare their md5. If they are consistent, it is considered a duplicate.

Let's talk about several ways to get md5 under Linux

  1. Single file is easier, cd to the file directory and execute md5sum test_bak.tar, you will get the md5 corresponding to the test_bak.tar file.

  1. If you can obtain the md5 of multiple files in multiple folders, you can use the following methods, you can first look at the file directory, there are folders and test files in the opt directory. There are also test files under the folder. We want to get the md5 of all files in the opt directory.

sudo find ./ -type f -print0 | xargs -0 md5sum

or

sudo find -type f -exec md5sum {} \;

In the next article, let's briefly talk about the above commands

Guess you like

Origin blog.csdn.net/qq_20714801/article/details/129123452