Skip to main content

Command Palette

Search for a command to run...

How to Copy from Linux Terminal

Updated
6 min read

Copying text from the Linux terminal might seem tricky if you’re new to the command line. But once you know the right methods, it becomes quick and simple. Whether you want to copy command output, error messages, or any text displayed in the terminal, there are several ways to do it.

In this article, I’ll guide you through the best ways to copy from the Linux terminal. You’ll learn keyboard shortcuts, command-line tools, and clipboard utilities that work across different Linux environments. By the end, you’ll be confident copying text efficiently in your terminal sessions.

Understanding Copying in the Linux Terminal

Copying text in Linux terminals is different from copying in graphical applications. The terminal often runs in a text-based environment where mouse and keyboard shortcuts vary depending on the terminal emulator you use.

Here are some basics to keep in mind:

  • Terminal Emulator Matters: Popular terminals like GNOME Terminal, Konsole, and xterm have different ways to handle copying.
  • Clipboard Types: Linux uses different clipboards such as the primary selection and the clipboard buffer.
  • Mouse vs Keyboard: You can copy text using the mouse or keyboard shortcuts, depending on your setup.

Knowing these basics helps you choose the best method for your needs.

Using Mouse to Copy Text in Linux Terminal

The simplest way to copy text from the terminal is by using your mouse. Most Linux terminals support this method by default.

Here’s how:

  • Select Text: Click and drag your mouse over the text you want to copy.
  • Copy: In many terminals, selecting text automatically copies it to the primary selection buffer.
  • Paste: To paste, middle-click your mouse or press Shift + Insert.

This method is fast and works well for quick copying. However, it uses the primary selection clipboard, which is different from the standard clipboard used by Ctrl + C and Ctrl + V in graphical apps.

Tips for Mouse Copying

  • If your terminal supports right-click menus, you can right-click the selected text and choose “Copy.”
  • Some terminals require you to press Ctrl + Shift + C to copy after selecting text.
  • Middle-click pasting works only if your mouse has a middle button or scroll wheel.

Keyboard Shortcuts for Copying in Terminal

Using keyboard shortcuts is often faster than the mouse, especially if you prefer to keep your hands on the keyboard.

Here are common shortcuts for popular terminal emulators:

Terminal EmulatorCopy ShortcutPaste Shortcut
GNOME TerminalCtrl + Shift + CCtrl + Shift + V
KonsoleCtrl + Shift + CCtrl + Shift + V
xtermNo default shortcut*No default shortcut*
TerminatorCtrl + Shift + CCtrl + Shift + V

*Note: xterm usually requires mouse selection and middle-click for copy-paste.

How to Use Keyboard Copy

  1. Highlight the text using your mouse or keyboard (Shift + Arrow keys).
  2. Press the copy shortcut (e.g., Ctrl + Shift + C).
  3. Paste it where you want using the paste shortcut or middle-click.

If you want to select text without a mouse, some terminals support keyboard selection modes. For example, in GNOME Terminal, you can hold Shift and use arrow keys to select text.

Copying Command Output Directly to Clipboard

Sometimes, you want to copy the output of a command without manually selecting it. Linux offers command-line tools to do this efficiently.

Using xclip

xclip is a popular utility that interfaces with the X11 clipboard.

  • Install xclip:
    sudo apt install xclip
    
  • Copy command output:
    ls -l | xclip -selection clipboard
    
  • This copies the output of ls -l to the clipboard.

Using xsel

xsel is another tool similar to xclip.

  • Install xsel:
    sudo apt install xsel
    
  • Copy output:
    ls -l | xsel --clipboard
    

Using wl-copy for Wayland

If you use Wayland instead of X11, wl-copy is the tool to use.

  • Install wl-clipboard:
    sudo apt install wl-clipboard
    
  • Copy output:
    ls -l | wl-copy
    

These tools let you copy command output directly to your system clipboard, making it easy to paste into other apps.

Copying Text in Tmux or Screen Sessions

If you use terminal multiplexers like tmux or screen, copying text requires special steps because they manage their own buffers.

Copying in Tmux

  1. Enter copy mode:
    Ctrl + b, then [
    
  2. Use arrow keys to move the cursor and select text by pressing Space.
  3. After selecting, press Enter to copy.
  4. Paste with:
    Ctrl + b, then ]
    

You can also configure tmux to copy directly to the system clipboard using plugins or scripts.

Copying in Screen

  1. Enter copy mode:
    Ctrl + a, then [
    
  2. Move the cursor to start selection, press Space.
  3. Move to end of selection, press Space again.
  4. Paste with:
    Ctrl + a, then ]
    

These methods let you copy text inside multiplexers without leaving the terminal.

Tips for Efficient Copying in Linux Terminal

To make copying easier, keep these tips in mind:

  • Use Shift with Ctrl: Many terminals require Ctrl + Shift + C instead of just Ctrl + C to avoid conflicts with command interrupts.
  • Configure Your Terminal: Check your terminal’s preferences to customize shortcuts.
  • Use Clipboard Tools: Install xclip, xsel, or wl-copy for direct clipboard access.
  • Learn Multiplexer Copying: If you use tmux or screen, practice their copy modes.
  • Use Mouse Selection Wisely: Remember that mouse selection copies to the primary clipboard, which may behave differently.

Troubleshooting Common Copy Issues

Sometimes copying doesn’t work as expected. Here’s how to fix common problems:

  • Ctrl + C doesn’t copy: This shortcut sends an interrupt signal in the terminal. Use Ctrl + Shift + C instead.
  • No paste with middle-click: Your mouse might not have a middle button. Try Shift + Insert or right-click paste.
  • Clipboard tools not installed: Install xclip, xsel, or wl-clipboard depending on your system.
  • Using Wayland: Clipboard tools differ; use wl-copy instead of xclip.
  • Tmux copy not working: Make sure you’re in copy mode and follow the correct key sequences.

Conclusion

Copying text from the Linux terminal is easier than it looks once you know the right methods. You can use your mouse for quick selections or keyboard shortcuts like Ctrl + Shift + C for faster copying. For copying command output directly, tools like xclip, xsel, and wl-copy come in handy.

If you use terminal multiplexers like tmux or screen, learning their copy modes will boost your productivity. Remember to adjust your terminal settings and install clipboard utilities to make copying smooth and efficient. With these tips, you’ll be copying from your Linux terminal like a pro in no time.

FAQs

How do I copy text using keyboard only in Linux terminal?

You can use Shift + Arrow keys to select text, then press Ctrl + Shift + C to copy. This works in terminals like GNOME Terminal and Konsole.

What is the difference between primary selection and clipboard in Linux?

Primary selection copies text when you select it with the mouse and pastes with middle-click. Clipboard requires explicit copy commands like Ctrl + Shift + C and pastes with Ctrl + Shift + V.

How can I copy command output directly to clipboard?

Use tools like xclip, xsel, or wl-copy. For example, ls | xclip -selection clipboard copies the output of ls to the clipboard.

How do I copy text inside tmux?

Enter copy mode with Ctrl + b then [, select text with arrow keys and Space, press Enter to copy, and paste with Ctrl + b then ].

Why doesn’t Ctrl + C copy text in my terminal?

Ctrl + C sends an interrupt signal to stop commands. Use Ctrl + Shift + C to copy text instead.

More from this blog

L

LinuxBloke | Linux Tips, Tricks & Troubleshooting

672 posts

How to Copy from Linux Terminal