Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
Are you in a command line only environment? If not, why don't you open the file in something like gedit? –  MBraedley Oct 6 '10 at 10:50
1  
I don't have gedit on that machine and I want to learn to do it in nano. –  Elzo Valugi Oct 6 '10 at 14:09
2  
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 Sep 16 '13 at 21:08
    
nano is not powerful. just to edit some config files it is pretty ok, but as an code editor it sucks! –  B4NZ41 Jan 17 at 16:32

8 Answers 8

up vote 5 down vote accepted

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.

share|improve this answer
    
how did this get the check when i clearly submitted the same solution earlier? –  hbdgaf Oct 20 '10 at 3:12
    
I think it is more about the story of the buffered that i get the check. I say why it is impossible. But i was spoke about xclip i should have say do what aking1012 suggest sorry. –  Louis Oct 22 '10 at 10:50

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
share|improve this answer
1  
nice trick, but I wanted a copy not a cut. –  Elzo Valugi Jan 18 '11 at 19:41
1  
+1, will save me a lot of time –  ianaz Nov 27 '12 at 13:01

Have you tried this: http://www.cyberciti.biz/faq/xclip-linux-insert-files-command-output-intoclipboard/

It isn't within nano, but you could cat the file into xclip with: cat test.txt | xclip

share|improve this answer
    
I think this should be the correct answer! It's exactly what OP wants, even if it isn't using nano. This is what I'll use from now on. –  Starkers Nov 12 '13 at 5:41

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.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

In vi we can easily do this.

suppose if you want to copy entire file content to some other file then try this

open your original file then in the command line write this

:w file1

here your entire file content will be copied to file1

suppose if you want to copy only part of the file then try this

first enable line numbering using this command

:setnu

After that if you want to copy from line number 10 to 23 then write this command in the command line

:10,23w file2

This will copy the content from line number 10 to 23 to file2

share|improve this answer
2  
This needs a downvote. vi is not always the answer my friend and certainly does nothing to address the question. Leave the fanboi stuff elsewhere –  cmroanirgo Jul 26 at 3:52
    
@cmroanirgo Then Downvote. –  max Aug 3 at 13:44
    
I have not enough rep to do this, otherwise I would have :D –  cmroanirgo Aug 9 at 8:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.