I open a file in Ubuntu nano editor from the comand line and I want to copy all the contents of the file so I can paste it in an another application outside the shell.

So far I can only copy using shift on the screen that is visible but not on all content.

  • Are you in a command line only environment? If not, why don't you open the file in something like gedit?
    – MBraedley
    Commented Oct 6, 2010 at 10:50
  • 5
    I don't have gedit on that machine and I want to learn to do it in nano. Commented Oct 6, 2010 at 14:09
  • 6
    Btw this is why I hate linux and the command-line: In theory a wonderful thing, but in reality extremely unuintutive, even the most simple and common things don't work like expected. Usability Super-Fail.
    – Sliq
    Commented Sep 16, 2013 at 21:08
  • 3
    nano is not powerful. just to edit some config files it is pretty ok, but as an code editor it sucks! Commented Jan 17, 2014 at 16:32
  • 1
    Question is too vague and the answers are all over the map as a result, leading to confusion. Typically you use nano on a remote server, not your desktop computer. This sounds more like a question about your terminal emulator, which is how you access nano. I really think the question should be changed or flagged for removal.
    – Jay Brunet
    Commented Dec 14, 2016 at 19:13

14 Answers 14


You can't use the buffer of nano to use it elsewhere, you need to use the buffer of X or Gnome.

xclip is the solution.

A command line interface to the X11 clipboard. It can also be used for copying files, as an alternative to sftp/scp, avoiding password prompts when X11 forwarding has already been setup.


There is a possible way:

  • Cursor at the beginning of a file

  • Ctrl6 to set a mark

  • AltShiftT (or try AltT) to cut to the end of the file

  • If AltT doesn't work, try CtrlK

  • to just copy the file content do CtrlU to uncut the text again
  • 1
    nice trick, but I wanted a copy not a cut. Commented Jan 18, 2011 at 19:41
  • 18
    this works only inside nano - after you'll close it you can not uncut it in another app as OP wanted.
    – A.D.
    Commented Mar 29, 2015 at 13:28
  • 9
    how do you get text OUT of nano? that's what I need to figure out Commented Sep 24, 2015 at 18:04
  • I needed to press Alt-A to mark on a MAC
    – MasterMind
    Commented Sep 6, 2018 at 6:06

you can use cat and then copy it from the console:

cat path/to/file.yml

Select the output printed in the console.

  • 16
    This is simple and efficient Commented May 15, 2020 at 23:02
  • 1
    Simplest one, no complicated step.
    – panoet
    Commented Feb 22, 2022 at 17:28

Alternatively you can zoom out using Ctrl+- to fit all the file contents on 'one screen page' and select everything using the mouse. After you zoom back with Ctrl+0 or zoom in progressively with Ctrl++.

I don't like the mouse part, but this is a fast way to copy bulk text in nano.

  • 2
    Easy and interesting. It works even on very large files. Commented Oct 18, 2018 at 23:37
  • 3
    It's incredible how simple and creative ideas can solve hard problems. Commented Oct 18, 2018 at 23:38
  • I think so, that was very funny, this guy is amazing lol, Why didn't I think about it earlier? Commented Jul 9, 2020 at 12:01
  • 1
    Thats badasssss.....
    – DropHit
    Commented Jan 15, 2021 at 2:39
  • Amazing, thank you! Of note: it only works with the +/- keys on the main part of the keyboard, not the num pad (even when num lock is ON). Commented Jul 28, 2022 at 8:47

Actually, this answer might be a bit late but I was looking for an answer for the same question and I just figured it out. when you have the file you want to copy to open in nano. you can hit ctl-R and enter the file you want copied from. this will bring in the whole file.

In my case I was just copying my old fstab so it wasn't a big deal. but could get ridiculous with huge files.


You can cut from the current cursor position to the end of the file with meta key plus T. Meta key is either alt or escape, depending on your keyboard. For me, accessing Ubuntu via ssh from my OSX it was escape.


Here's another solution. One that I personally prefer. It uses Xsel. It's very similar to Xclip but with a key difference.

$ cat my_funky_file | xsel

While Xclip puts everything in the main clipboard, Xsel manipulates the selection buffer letting you paste the selection with a middle-click. This is great for one-offs! So if you have something in your clipboard that you haven't pasted yet, that would stay unaffected!

And if you want to paste the content, xsel -o will spit it right out.

You can install it on a debian based system using

$ apt-get install xsel

The source is available here otherwise! Hope this helps someone.

  • 1
    xsel: Can't open display: (null) : Inappropriate ioctl for device
    – andilabs
    Commented Sep 20, 2018 at 18:09

Simplest way:

  • Alt\ to go to the top of the file.
  • Ctrl6 to set a mark.
  • Alt/ to go to the bottom of the file (i.e. marking all the text).
  • Alt6 to copy the selected text.

(Not part of the question but for the record, CtrlU can be used to paste copied text.)


use micro instead of nano in these cases

To install:

sudo su
cd /opt/
apt-get install curl
curl https://getmic.ro | bash
ln -s /opt/micro /usr/bin/micro
ln -s /opt/micro /usr/bin/nani

so you can open a file with:

micro Readme.txt
nani Readme.txt

I use both, nano is quick and handy, micro is fully featured.

You can use:

  • Ctrl-A to select all.
  • Ctrl-C, Ctrl-V
  • Place multiple cursors if you use Ctrl and left click
  • Ctrl-Q to exit and press y or n
  • etc..
  • Micro Gihub page

As other replies have pointed out, it is actually not possible to copy from nano to the Ubuntu clipboard and use it in other software, unless you use your mouse and copy with the right click.

however it is possible to open both files in nano and copy from one to another: (Meta is Alt or Esc based on your default Meta key)

  1. First you need to activate multiple buffers

    • if you have the nano open Metaf

    • or open nano with -F flag: nano -F

    • or put set multibuffer into your ~/.nanorc file

  2. Then you can open files in new buffer with Ctrlr

  3. switch between buffers with Meta, to left and Meta. to right
  4. go to the beginning of the file Meta\ and then you have two options:

    a. mark the text by CtrlShift6, then take the cursor to the end Meta/, then cut the text Ctrlk

    b. cut the text to the end of file by Metat

  5. switch to the other file opened in the other buffer and past by Ctrlu


From my understanding it is not possible to select an entire file in nano if it scrolls more then your window. If you are using a GUI and have nano open from a terminal and the file is not longer than your window you can use mouse and select all the text than cnt+shift+c will copy it to clipboard.

Although not in nano, there is a way in vim. See here.

Specifically, select text (visual mode) section.


So this works in putty.
1. right click title bar 2. change settings 3. Appearance 4. change - font 5. change the font to 1

This will put a lot of code on a single screen. It was enough for me to copy a large config file.

  • 1
    That doesn't answer the question.
    – Toto
    Commented Jun 30, 2018 at 15:18

I dont know why everyone decided to make this so hard.

cat /path/to/file.cfg

it'll output all text in the terminal that can be selected with standard commands.

Paste where you want it.

  • 1
    The question was how to do this from within the nano editor, which may or may not be possible.
    – ckujau
    Commented May 21, 2020 at 1:51
  • 2
    Reason I mentioned this, was I was trying to do the same thing. Then you just right click in nano window and it pasts the text. Downvoting isnt convenient.
    – Narcarsiss
    Commented May 22, 2020 at 3:32
  • this is a valid answer even when this solution was already in place superuser.com/a/1231864/752096 Commented Nov 13, 2020 at 16:52
  • I was about to put this answer. Even though the question was how to do it in nano, it's still valid because the desired outcome was to copy ALL text and paste it outside the shell. This is the easiest way I can think of without needing to download any extra tools. We don't need to be so complicated all the time, lol. Commented Jun 29, 2023 at 17:18

I know that a lot of people already answered this question, but I can't see anyone mentioned this one, it is easy to remember, fast and efficient:

Hold down Ctrl + Shift + A all together

now select your text with

Arrow Down

and if you want to cut the selected text:

Ctrl + K

  • I have no clue why should my answer get thumbs down but it is the same as superuser.com/a/234836/714723 this answer, I just found another way to cut the text if you want to copy it, as it has been asked in the question! Commented May 24 at 20:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .