Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've been asked to run a command and copy and paste the output but I have no idea where to start.

What do I do?

share|improve this question
    
add comment

1 Answer

up vote 8 down vote accepted

Hopefully you will have access to a graphical desktop. That's what the first part of this answer deals with. If you do not, skip the first three steps and read the bottom of the answer.

Step 1: Load a terminal...

The first step is opening a terminal. There are a multitude of different terminal options out there but most Ubuntu users will have gnome-terminal, KDE users tend to have konsole, and XFCE users should have xfce4-terminal.

Once you have identified which command you want to run, it's just a case of running it.

  • Press Ctrl+Alt+T.
  • Unity and Gnome Shell users can search for Terminal.
  • KDE users can find Konsole under Applications → System.
  • All desktops can press Alt+F2 and type in the terminal binary name (as above) manually.

Step 2: Running your command

This is the simple bit. You should be looking at something like the following:

enter image description here

You can either type the command, or you can copy it (select the text, right click, "Copy", then right click the terminal, "Paste"). Copy & Paste is recommended for long commands. We want to avoid errors in transcription!

When you have typed or pasted the command into this window, press Return. Output should now appear on the screen as below:

enter image description here

Step 3: Copying the content

Copying is similar to most other applications apart from most consoles only know how to copy "blocks". To copy, simply use your mouse to drag around the output until it is highlighted, like so:

enter image description here

Right click on the terminal (to go to the Edit menu) and select "Copy". Then you can go back to your browser or editor and paste. We're done.

Step 3.5: Alternative for copying:

Seeing as you're getting the hang of the command line now, you can also use a command called xclip to directly insert things into X's clipboard. This will only work if a GUI is running.

lspci -nnk | grep VGA -A1 | xclip -selection clip

Note: you can omit -selection clip but the data will be in your middle-click clipboard - yes, there are two clipboards... A story for another day, perhaps :)


Addendum: Extracting command line data without Copy & Paste

If you need to get the output from a computer that, for example, the display settings are so broken you can't get into a usable desktop, we have to find another method for extracting the output. You could do it by hand but often (in case of logs) this is impractical.

At the very least we need to get into a terminal which you can do by pressing: Control+Alt+F1.

You may need to log in.

From here we can run our command but the output will only show on the display. Now we have two options:

I have an internet connection

If you have access to the internet, you can simply "pipe" the output into a command called pastebinit. This uploads the content to http://paste.ubuntu.com and returns a short, easy to transcribe URL that you can access from another computer or just give to people.

pastebinit is not installed by default so the first thing we run is:

sudo apt-get install pastebinit

Then we run our command, followed by | pastebinit:

lspci -nnk | grep VGA -A1 | pastebinit

And you'll see something like the following (though obviously not in a window):

enter image description here

Write down the URL and you can share that with whomever you like.

I don't have an internet connection

This is more problematic but not unsurpassable. We will need some form of external storage. A USB stick is a popular example. Plug it in. In a non-graphical setting, USB drives are not automatically mounted. As I said, problematic.

Run sudo fdisk -l and you should see something like this:

Disk /dev/sda: 60.0 GB, 60022480896 bytes
255 heads, 63 sectors/track, 7297 cylinders, total 117231408 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00028b58

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048   109260799    54629376   83  Linux
/dev/sda2       109262846   117229567     3983361    5  Extended
/dev/sda5       109262848   117229567     3983360   82  Linux swap / Solaris

Disk /dev/sdb: 1967 MB, 1967128576 bytes
255 heads, 63 sectors/track, 239 cylinders, total 3842048 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000004f5

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *          63     3839534     1919736    b  W95 FAT32

In my case, the new disk I've plugged in is that second one (sdb) and it has one partition (sdb1). We need to mount this so we can write to it. Simply:

sudo mount -o umask=0000 /dev/sdb1 /mnt

Then we can funnel our commands into new files on the external disk:

lspci -nnk | grep VGA -A1 > /mnt/lspci
cat /var/log/Xorg.0.log >/mnt/xorg.log

That will create two new files on the external drive. You can also copy things to it with cp. When you're done you want to unmount the drive:

cd /  # just in case you cd'd into /mnt
sudo umount /mnt

Then you can unplug your drive and take it to another computer and upload the information as requested.

share|improve this answer
2  
Finally some good news for today. I didn't knew about pastebinit. It should be added to Ubuntu by default. –  Radu Rădeanu Aug 22 '13 at 11:33
    
@RaduRădeanu Agreed. A very useful tool when everything (apart from the internet) is broken. –  Oli Aug 22 '13 at 11:37
    
How about xclip -i which accepts stdin as input to put on your clipboard? –  gertvdijk Aug 22 '13 at 11:48
    
@gertvdijk That's certainly an option I toyed with but I don't think it's any easier (given that it's more to write) for a novice user than just selecting and copying normally. I'll add it as an option. –  Oli Aug 22 '13 at 11:52
add comment

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.