views:

61

answers:

2

I want to add backspace character literally in my file named junk. So I did following
$ ed
a
my name is happy\b (here b means I typed backspace so \ gets disapperaed and cursor sits sfter y)
.
w junk
q

But when I do
$ od -cb junk
it doesn't show backspace.

+3  A: 

Hit Ctrl+V before hitting backspace. That tells the shell to treat the following keystroke literally, rather than interpreting its meaning.

Depending on how your terminal is set up, the backspace key might be interpreted as delete, so you might need to hit Ctrl+H instead of backspace to get a backspace character in your file.

RichieHindle
It doesn't work. When I hit ctrl-V, it shows an underscore and thenpressing backspace deletes that underscore and / remains as it is.By the way, I am using cygwin software. Does that create problem?
Happy Mittal
Ah, OK. I don't know why Cygwin doesn't work, sorry.
RichieHindle
+2  A: 

Type ctrl-v, ctrl-h.

ctrl-v says 'insert the next control character literally'. The cursor should change to a highlighted caret.

ctrl-h is the backspace character. It looks like in ed, typing ctrl-h without ctrl-v also inserts a literal backspace, but in other contexts, crtl-h may have some other meaning, and you will need to press ctrl-v first.

EDIT: With the above steps, od -cb gave me:

$ od -cb file
0000000   h   e   l   l   o  \b  \n
        150 145 154 154 157 010 012
0000007

which looks correct.

When I tried it again with ctrl-v, Backspace (as opposed to ctrl-h), it instead gave

$ od -cb file
0000000   h   e   l   l   o 177  \n
        150 145 154 154 157 177 012
0000007

177 is the ascii octal code for DEL, not Backspace. This may vary by system, though.

Personman