How to copy/paste text in the UNIX terminal

From NMR Wiki

Jump to: navigation, search

To copy - select range of text with the mouse (on some systems you may have to hit Ctrl-C or Apple-C to copy; on Linux selected text is automatically placed onto the system clipboard).

To paste into a file in the Unix command line there are three steps:

  • type either "cat > file_name" or "cat >> file_name". In the first case file will be overwritten, in the second case pasted text will be appended to the file.
  • actually paste - the action depends on the type of your terminal. In most cases clicking middle mouse button over the terminal screen will work. In Windows-based PUTTY ssh terminal it's right-click
  • type in "end of file" command - usually Ctrl-D

Unix pipes give you extra flexibility.

For example you can append sorted copied contents to the file this way:

cat | sort >> file

or even just unique lines from the copied content:

cat | sort | uniq >> file

The pipeline can be built to your specific needs.

Personal tools