Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to paste some text into a terminal and save it to a file without using an editor, but just 'cat'.
But too long lines or tabs in text make it impossible to do so with a simple command like "cat >test.txt" or "cat <<'EOF' >test.txt" ("here document").

In bash in "here document" mode if pasted text data contains tabs, they cause autocomplete.
If I start bash with '--noediting', on some systems the length of pasted line is limited to 256 chars, the rest of pasted text is discarded.
If instead I paste directly to cat's input (without <<'EOF'), the max line is also 256.

If I do:

stty raw; cat >test.txt; stty sane

, the line length is no longer limited, but there's no way to send EOF to cat's input.
If I enable eof char:

stty raw icanon eof '^d'; cat >test.txt; stty sane

long lines are lost.

Also, if I don't disable echo with:

stty -echo

, the combination of Solaris 10 and Putty cause large blocks of text ~1500chars to be lost, sometimes resulting an empty file.

The closest I got to what I want is to kill cat with timeout:

( sleep 15; pkill cat ) & stty raw -echo; cat >test.txt; stty sane; echo done

or to use bash --noediting with raw:

bash --noediting
stty raw -echo icrnl
cat <<'EOF' >test.txt; stty sane
share|improve this question
Can you please say your question more clearly and what are you going to do? – Sepahrad Salour Aug 28 '13 at 6:53
Please don't downvote. If you don't understand the question, it means you're not a specialist. Your negative vote repels people who could answer. – basin Aug 28 '13 at 9:22
I don't downvote you can see my reputation, BUT please say your question clearly and edit your post, Thanks – Sepahrad Salour Aug 28 '13 at 9:25
I am still not sure what you are trying to do. I would guess you are trying to paste from your X clipboard into a file without opening an editor. Also I am not sure if you are looking for a scriptable or interactive solution. Such unclear things are probably the the reason for your downvotes. Googling what I think is your question brought me to this question. Maybe xclip -o > test.txt does the trick for you. – Tim Aug 28 '13 at 13:48
@Tim I'm connecting to Solaris with Putty from a Windows session on a Citrix XenApp server, to which I'm connecting from Windows 7 with a XenApp client. I can't copy files, all I have is clipboard. – basin Aug 28 '13 at 18:28

If you're using bash, you can disable tab-completion before you paste then reenable it afterwards by using the bind command:

bind '\C-i:self-insert'
# paste away
bind '\C-i:complete'

This is unwieldy, but it works.

When manually typing on the bash command-line you can enter a literal tab by first pressing CTRL-V then tab. Obviously you can't do this when pasting and I was annoyed enough by this that I patched my favorite terminal program iTerm2 with a "Paste Special" command that sends literal tabs via a CTRL-V,tab sequence.

I only tonight wrote and submitted this patch, so if you want a version of iTerm2 that does this you'll have to compile your own from my fork at GitHub using Xcode. Hopefully it will get merged into the main application, if it does I'll update this answer. EDIT: The changes I made are now in the main branch of iTerm2. Use the Edit -> Paste with Literal Tabs command.

If you're using a different OS or terminal program sorry, I can't help with that.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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