md5sum on a file with backslash in its name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting md5sum on a file with backslash in its name
# 1  
Old 04-30-2012
Error md5sum on a file with backslash in its name

Hi there,

I found something very weird!
Should I report that as a bug or is it me misusing the command?

I've got a file with a backslash in its name.
I know it's a horrible policy but it's not me.
The file came from a mac computer because this is a backup server.

Anyway, when using md5sum on the file, I get a very weird output.
Check it out :
Code:
ks354286:~# ls -l /tmp/file*
-rw-r--r-- 1 root root 2 2012-04-30 17:05 /tmp/file1
-rw-r--r-- 1 root root 2 2012-04-30 17:05 /tmp/file\2
ks354286:~# md5sum /tmp/file*
60b725f10c9c85c70d97880dfe8191b3  /tmp/file1
\3b5d5c3712955042212316173ccf37be  /tmp/file\\2

Do you have an explanation? a solution?

Thanks
Santiago
# 2  
Old 04-30-2012
Weird, but the odd thing is it seems to work correctly
Code:
$ touch bad\\filename
$ md5sum bad\\filename
\d41d8cd98f00b204e9800998ecf8427e  bad\\filename
$ md5sum bad\\filename >bad_sums
$ md5sum -c bad_sums
bad\filename: OK

# 3  
Old 04-30-2012
You have to prevent the shell from expanding the file name. Try not globbing the names, "*", rather put the name inside single quotes '/tmp/file\2'

We have C code to handle file names from a SAN directory of wierd PC shares (opendir, readdir) that encapsulates all of the filenames with single tics to be able to work with files on those directories. Assuming you do not want to rename the file.
# 4  
Old 04-30-2012
@Skrynesaver
I see but I also use it that way:
Code:
$ mymd5sum=$(md5sum bad\\filename | cut -b-32)
$ echo "$mymd5sum"
\3b5d5c3712955042212316173ccf37b

The only way I found to circumvent the issue is to do the following:
Code:
$ mymd5sum=$(cat bad\\filename | md5sum | cut -b-32)
$ echo "$mymd5sum"
3b5d5c3712955042212316173ccf37be

@jim_mcnamara
The problem is not about globbing:
Code:
ks354286:~# md5sum '/tmp/file\2'
\3b5d5c3712955042212316173ccf37be  /tmp/file\\2

# 5  
Old 04-30-2012
That why you should use -c option with file.

It's meant for your to avoid excessive coding and make a 3 shell line compare, use it Smilie
# 6  
Old 04-30-2012
Hi Peasant,

I know the -c option quite well.
I use it in many different situations.
But I don't see how it can serve my current needs.

Does it create a correct output?
Does it allow me to save the md5sum in a variable?

Thanks for your help.
Santiago
# 7  
Old 04-30-2012
md5sum is apparently attempting to warn you that the filename contains a backslash, by making the first character in the line be a backslash.

If the first character in a line is a backslash, thus, remove it, and carry on...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[md5sum] script

I am getting No such file or directory if my variable contains white spaces... Is there a way to fix this? This works x="1.md5" md5sum -c "$x" This, does not x="23\ 5\ 6\ 7\ 8\ 9\ 10.md5" md5sum -c "$x" md5sum: '23\ 5\ 6\ 7\ 8\ 9\ 10.md5': No such file or directory How do I fix... (1 Reply)
Discussion started by: soichiro
1 Replies

2. Shell Programming and Scripting

Removing md5sum lines stored in text file

Hello. I'm writing a script where every file you create will generate a md5sum and store it into a text file. Say I create 2 files, it'll look like this in the text file: d41d8cd98f00b204e9800998ecf8427e /helloworld/saystheman d41d8cd98f00b204e9800998ecf8427e /helloworld/test I... (3 Replies)
Discussion started by: batarangs_
3 Replies

3. Shell Programming and Scripting

Using md5sum to name file based on URL

I am trying to download a file and make the filename of the file be the md5sum of the URL. I know to use wgets to download the file but I do not know how to do the rest...any help would be appreciated. (2 Replies)
Discussion started by: The undertaker
2 Replies

4. Shell Programming and Scripting

Copy a file with backslash in the filename

Hi, I'm trying to make a script that copy a file that has a backslash in the filename. What I'm doing wrong? The flename is: 1300212744.H786972P30819.ns1.cybernet.com.br,S\=6313:2, My script ParteA="1300212970.H27173P31627.ns1.cybernet.com.br,S" ParteB=\\ ParteC="=" ParteZ=":2,"... (15 Replies)
Discussion started by: Ronaldo
15 Replies

5. Shell Programming and Scripting

Script to check MD5SUM on file

Hi, I currently have a shell script that takes an RPM and scp's it to a set of remote servers and installs it. What I would like to be able to do is make the script get the md5sum of the RPM locally (so get the md5sum of the rpm from where im running the script) and then scp the rpm to the... (0 Replies)
Discussion started by: tb1986
0 Replies

6. Shell Programming and Scripting

How to retain backslash in a line while reading a data file?

Hello Firends I have a file that contains data within single quotes, which has meaning of its own. When I am trying to parse through the file for a different functionality I noticed that I was loosing the backslash when occurrences in the file look like ('\0'). I would want to retain the... (3 Replies)
Discussion started by: easwam
3 Replies

7. Shell Programming and Scripting

Duplicate file remover using md5sum--good enough?

This is not a typical question. I have a fully working script but I'm interested in optimizing it. I frequently back up photos and movies from my digital camera and cell phone to both my home/work desktops, laptops, wife's netbook, and my home NAS and often end up with multiple versions of the... (2 Replies)
Discussion started by: Michael Stora
2 Replies

8. Shell Programming and Scripting

remove backslash character from file

How do I remove a backslash character \ from a file? I have used sed -e "s|\||g" filename > newfile I have done several permutations on this to no avail such as: sed -e "s|`\`||g" filename > newfile sed -e "s|""\""||g" filename > newfile What am I doing wrong?:confused: ... (2 Replies)
Discussion started by: MissI
2 Replies

9. UNIX for Dummies Questions & Answers

the file: MD5SUM

i downloaded a Linux distribution from a FTP site today, and i found there is a file named MD5SUM in the same directory, with the following contents: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 c9a4d963a49e384e10dec9c2bd49ad73 valhalla-SRPMS-disc1.iso 41b03d068e84d2a17147aa27e704f79b ... (1 Reply)
Discussion started by: samprax
1 Replies

10. UNIX for Dummies Questions & Answers

What is md5sum???

Hi all, I am kinda puzzled. When and Why do we use md5sum? I've read man pages for mp5sum, but didn't get anything out of it. Please, can someone explain this to me in couple of words. Thank you all. (1 Reply)
Discussion started by: solvman
1 Replies
Login or Register to Ask a Question