How can I input to a file directly from the terminal
Solution 1
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
Solution 2
Use
cat > some_file
to write into the file some_file
. End your input with Ctrl+D
Related videos on Youtube
Tracker1
Software Developer / Architect specializing in web based application platforms for over 20 years. Experienced with databases ranging from BigTable, Column Store, SQL, Key/Value and Document reference stores. ASP.Net family as well as Node.js family and other application platforms. I absolutely love JavaScript as a language, and platforms that leverage it. MongoDB, RethinkDB, NodeJS/Express, Synchronet BBS, jQuery, Backbone, Knockout, React, etc.
Updated on September 18, 2022Comments
-
Tracker1 over 1 year
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 about 9 yearsThanks, 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.