close

最近為了工作上的需要,對一整個系統做類似 CRC checksum 的東西。

常用的 md5sum 就派上用場了,但是需要對系統中每一個檔案都做 md5sum 出來,做成一個列表。
之前看到的做法如下:(系統 mount 在 /mnt)

find /mnt -type f -print0 | xargs -0 md5sum > <path/to/file>


其實平常用 find,都只是找找檔案而已。今天看到了 -print0 這個參數,看了 man page 才知道,
它會將列出來的字串以 null character 做該行字串的結尾(預設是 -print,以 new line character 做結尾)

而 xargs 中的 -0 參數則是跟 find -print0 互相配合,它將 stdin 的 item 以 null character 做分隔依據,
也就是說,如果字串中間有空白,換行,都還是視為同一個 item。

之前都沒用過這兩個參數,還蠻不錯用的!


補充:

其實要算 md5sum 可以用 md5deep 這個工具,很快就得到同樣的列表:

md5deep -o f -r /mnt > <path/to/file>



p.s. 有沒有人覺得改版後的 pixnet 的進階編輯器,那個表格很難控制啊~


arrow
arrow
    全站熱搜

    zxlin 發表在 痞客邦 留言(0) 人氣()