3

What is going on here? A backslash in a directory name and/or file name seems to cause various checksum utilities to report the hash preceded with a backslash slash.

Note that the coreutil wc does not behave this way.

Behavior as expected:

#ppd# ls -1a
.
..
#ppd# mkdir a\\b
#ppd# ls -1
a\b
#ppd# for i in 1 2 3; do echo $i > a\\b/c$i; done

#ppd# ls -1 a\\b/c*
a\b/c1
a\b/c2
a\b/c3

#ppd# cat a\\b/c*
1
2
3

#ppd# wc --version
wc (GNU coreutils) 8.13
#pre# wc a\\b/c*
1 1 2 a\b/c1
1 1 2 a\b/c2
1 1 2 a\b/c3

#ppd# cd a\\b/

#ppd# md5sum --version
md5sum (GNU coreutils) 8.13

#ppd# md5sum c*
b026324c6904b2a9cb4b88d6d61c81d1  c1
26ab0db90d72e28ad0ba1e22ee510510  c2
6d7fce9fee471194aa8b5b6e47267f03  c3

Now for the odd behavior:

#ppd# pwd
/home/abe/tdir/a\b

#ppd# md5sum ../a\\b/c*
\b026324c6904b2a9cb4b88d6d61c81d1  ../a\\b/c1
\26ab0db90d72e28ad0ba1e22ee510510  ../a\\b/c2
\6d7fce9fee471194aa8b5b6e47267f03  ../a\\b/c3

#ppd# cd ..

#ppd# md5sum a\\b/c*
\b026324c6904b2a9cb4b88d6d61c81d1  a\\b/c1
\26ab0db90d72e28ad0ba1e22ee510510  a\\b/c2
\6d7fce9fee471194aa8b5b6e47267f03  a\\b/c3

#ppd# sha1sum a\\b/c*
\e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e  a\\b/c1
\7448d8798a4380162d4b56f9b452e2f6f9e24e7a  a\\b/c2
\a3db5c13ff90a36963278c6a39e4ee3c22e2a436  a\\b/c3

#ppd# sha256sum a\\b/c*
\4355a46b19d348dc2f57c046f8ef63d4538ebb936000f3c9ee954a27460dd865  a\\b/c1
\53c234e5e8472b6ac51c1ae1cab3fe06fad053beb8ebfd8977b010655bfdd3c3  a\\b/c2
\1121cfccd5913f0a63fec40a6ffd44ea64f9dc135c66634ba001d10bcf4302a2  a\\b/c3

Backslash in filename:

#ppd# echo "4" > a\\b/c\\4
#ppd# ls -1 a\\b/*
a\b/c1
a\b/c2
a\b/c3
a\b/c\4

#ppd# md5sum a\\b/*
\b026324c6904b2a9cb4b88d6d61c81d1  a\\b/c1
\26ab0db90d72e28ad0ba1e22ee510510  a\\b/c2
\6d7fce9fee471194aa8b5b6e47267f03  a\\b/c3
\48a24b70a0b376535542b996af517398  a\\b/c\\4

#ppd# cd a\\b/
#ppd# md5sum *
b026324c6904b2a9cb4b88d6d61c81d1  c1
26ab0db90d72e28ad0ba1e22ee510510  c2
6d7fce9fee471194aa8b5b6e47267f03  c3
\48a24b70a0b376535542b996af517398  c\\4

I discovered the above when storing the hashes in xattrs as ss=md5sum <filename>; setfattr -n user.cksm -v ${ss:0:32}. Here are some of the characters as reported by getfattr -n user.cksm.md5 (the first line is just to aid in counting the characters, which ought to number 32 for an md5 hash:

#              123456789 123456789 123456789 12
user.cksm.md5="be28d5286d9c719a904550f41593d"
user.cksm.md5="a4e9e6958c9d5762dcf090871e44bf"
user.cksm.md5="#f39b8c4dc110178505c089cba7986"
user.cksm.md5="\\ebf1b8f8054d21c78f2a699776f84a0"
user.cksm.md5="+c2769ebdd2ce3a8355395d2129051"
user.cksm.md5="/9ac5b68efea0e9f02c917503cbb3e"
2

(Moved self-answer out of the question)

According to this answer to another question, the answer is to the present question is rtfm:

NOTE: The GNU sha digests documentation reference the md5sum digest documentation

For each file, ‘md5sum’ outputs by default, the MD5 checksum, a space, a flag indicating binary or text input mode, and the file name. Binary mode is indicated with ‘*’, text mode with ‘ ’ (space). Binary mode is the default on systems where it’s significant, otherwise text mode is the default. If file contains a backslash or newline, the line is started with a backslash, and each problematic character in the file name is escaped with a backslash, making the output unambiguous even in the presence of arbitrary file names. If file is omitted or specified as ‘-’, standard input is read.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.