DEV Community

Alexander Harris
Alexander Harris

Posted on

Writing to a remote file without vi / nano

If you ever need to quickly paste contents into a file via a shell on linux etc. but don't have a text editor installed (limited distro, jump box etc.) you can use the following command:

cat > myfile.txt << EOF
some test pasted from the cli
pboard including
newlines etc
EOF
Enter fullscreen mode Exit fullscreen mode
  • cat - print on std out
  • > myfile.txt - redirect std out to myfile.txt (and overwite the contents)
  • << EOF - Read from the commandline and input will be complete when you see the "EOF" string.
  • Paste from clipboard (SHIFT+INSERT if CTRL+V doesn't work), type text as needed
  • Add one extra newline
  • Type "EOF"
  • Hit return

Top comments (2)

Collapse
 
mateusabelli profile image
Mateus Abelli

That's super cool! I appreciate the breakdown at the end, it really helps to clarify the commands, thanks for the post!

Collapse
 
alexandermlharris profile image
Alexander Harris

Glad you found it useful - I'm no shell expert but it helped me to understand the different pieces. I needed this on a remote jump box with SSH disabled and no editors installed where I needed to send over a new key-file.