I am using Mac OS and emacs -nw
(the terminal mode).
I don\'t know how can I paste things (having been implemented by M-w in emacs -nw) outside the emacs.
If you are using Ubuntu 12.04 or Fedora 21, there are a couple of options to make this work.
First you need to install xclip
sudo apt-get install xclip
First Option: For Emacs 24
If you are using emacs24 you can install from the list of packages
M-x package-list-packages
Select
xclip //mine was version 1.3
In your .emacs add:
(xclip-mode 1)
Second Option. For emacs before version 24
Install xclip.el: Integrating Emacs with the X11 Clipboard in Linux
Third Option. Using @Nicholas Riley code shown in the answer
To use the code in the answer you need pbcopy / pbpaste in Ubuntu (command line clipboard)