8

Other than bringing up a text editor, is there a way I can input text in a linux terminal directly to a file? (then enter a control code such as ctrl-c, to end the input)

I'm pretty sure there's a way to do this... I am SSH'd to a server with Docker, and running bash inside a container, so that I can test some stuff, I just want to be able to paste a small script in my terminal window, and have that output to a file inside the container's shell.

Thanks.

Tracker1
  • 325
  • 2
  • 4
  • 13

3 Answers3

13

a useful use of cat: provide input on stdin

cat > filename
enter text
hit Ctrl-D to stop

or use a heredoc

cat > filename << END
enter text
provide the terminating word to stop
END
glenn jackman
  • 17,625
  • 2
  • 37
  • 60
  • Thanks, I knew there was something like this, couldn't for the life of me remember, and searching google was just about impossible to find this. – Tracker1 Feb 06 '15 at 23:41
1

Use

cat > some_file

to write into the file some_file. End your input with Ctrl+D

Florian Diesch
  • 86,013
  • 17
  • 224
  • 214
0

echo "Hello" > test.txt

This will OVERWRITE "hello" in to the test file. If the file did not exist it will create it

echo "Hello2" >> test.txt

This will add a NEW line in the file with hello2

wlraider70
  • 1,663
  • 13
  • 26
  • I actually needed to paste more than would fit on a line to the text... I wanted to paste a file into my terminal window, and have it save to a file where the terminal was connected. – Tracker1 Feb 06 '15 at 23:42