How To Copy And Paste In Linux – Terminal Text Selection Methods

When working in a Linux environment, the standard keyboard shortcuts you know may not apply the same way. Understanding how to copy and paste in Linux is essential for anyone transitioning from Windows or macOS, as the system uses different conventions for text and file operations. This guide covers terminal commands, GUI methods, and clipboard tools to make you efficient in Linux.

How To Copy And Paste In Linux

Copying and pasting in Linux can be done through both the command line and graphical interfaces. The methods vary depending on whether you are in a terminal, a text editor, or a file manager. Below, we break down each approach step by step.

Copy And Paste In The Linux Terminal

The terminal is where most Linux users spend their time. Here, the standard Ctrl+C and Ctrl+V shortcuts do not work as expected because they are reserved for sending signals or pasting text in some contexts.

Using Keyboard Shortcuts In Terminal

  • Copy text: Select text with your mouse, then press Ctrl+Shift+C.
  • Paste text: Place the cursor where needed, then press Ctrl+Shift+V.
  • Alternative: Use Ctrl+Insert to copy and Shift+Insert to paste.

These shortcuts work in most terminal emulators like GNOME Terminal, Konsole, and xterm. If you are using a terminal inside a virtual machine, you may need to adjust settings.

Using Mouse Actions In Terminal

  • Copy: Highlight text with the left mouse button. It is automatically copied to the primary selection buffer.
  • Paste: Click the middle mouse button (or scroll wheel) to paste the selected text.

This method is fast and does not require keyboard shortcuts. It works across most Linux desktop environments.

Copy And Paste In GUI Applications

In graphical applications like text editors, web browsers, or file managers, the shortcuts are more familiar but still have nuances.

Standard GUI Shortcuts

  • Copy: Ctrl+C or right-click and select “Copy”.
  • Paste: Ctrl+V or right-click and select “Paste”.
  • Cut: Ctrl+X or right-click and select “Cut”.

These work in most applications, but some older programs may require the use of Ctrl+Shift+C and Ctrl+Shift+V even in GUI mode.

Copying Files In File Managers

  1. Open your file manager (e.g., Nautilus, Dolphin, Thunar).
  2. Select the file or folder you want to copy.
  3. Press Ctrl+C or right-click and choose “Copy”.
  4. Navigate to the destination folder.
  5. Press Ctrl+V or right-click and choose “Paste”.

You can also drag and drop files while holding the Ctrl key to copy them instead of moving.

Copy And Paste Between Terminal And GUI

Transferring text between the terminal and GUI applications requires understanding the clipboard system.

Using The Primary Selection

  • Highlight text in the terminal with the mouse. It is stored in the primary selection.
  • Switch to a GUI application and click the middle mouse button to paste.
  • This works both ways: from GUI to terminal as well.

Using The Clipboard Selection

  • Use Ctrl+Shift+C in the terminal to copy to the clipboard.
  • Then use Ctrl+V in a GUI application to paste.
  • To copy from GUI to terminal, use Ctrl+C in the GUI, then Ctrl+Shift+V in the terminal.

Some terminal emulators allow you to configure which selection is used. Check your terminal’s preferences for options.

Command-Line Tools For Copy And Paste

For advanced users, command-line tools can handle copying and pasting without a mouse.

Using xclip

  1. Install xclip if not present: sudo apt install xclip (Debian/Ubuntu) or sudo dnf install xclip (Fedora).
  2. To copy a file’s content: cat file.txt | xclip -selection clipboard
  3. To paste: xclip -selection clipboard -o

Using xsel

  1. Install xsel: sudo apt install xsel
  2. Copy: cat file.txt | xsel --clipboard
  3. Paste: xsel --clipboard

These tools are usefull for scripting or when working in a headless environment.

Copy And Paste In Different Desktop Environments

Linux has many desktop environments, each with slight variations.

GNOME

  • Uses the standard shortcuts mentioned above.
  • Has a clipboard manager extension available in GNOME Extensions.

KDE Plasma

  • Similar shortcuts, but Klipper is a built-in clipboard manager.
  • You can access clipboard history by pressing Ctrl+Alt+V.

XFCE

  • Works with standard shortcuts.
  • Clipboard manager can be added via plugin.

Most environments support both primary selection and clipboard selection, so you can choose what works best.

Common Issues And Fixes

Users often encounter problems when copying and pasting in Linux. Here are solutions.

Ctrl+C Not Working In Terminal

If Ctrl+C does not copy, it might be sending the SIGINT signal instead. Use Ctrl+Shift+C or check your terminal emulator’s settings.

Middle Mouse Paste Not Working

This can happen if your mouse driver is misconfigured. Try using the keyboard shortcuts instead, or check your mouse settings in the system preferences.

Clipboard Not Syncing Between Applications

Some applications use their own clipboard. Use the primary selection for quick transfers, or install a clipboard manager like CopyQ or Diodon.

Advanced Copy And Paste Techniques

For power users, there are more efficient ways to handle text.

Using tmux Or screen

  • In tmux, you can enter copy mode with Ctrl+B [.
  • Navigate with arrow keys, select text with space, and copy with Enter.
  • Paste with Ctrl+B ].

Using vim Or nano

  • In vim, use visual mode to select text, then y to yank (copy) and p to paste.
  • In nano, use Alt+6 to copy and Ctrl+U to paste.

These methods are essential for terminal-based editing.

Copy And Paste In Remote Sessions

When using SSH or remote desktop, copying and pasting can be tricky.

SSH With X11 Forwarding

  • Use ssh -X user@host to enable X11 forwarding.
  • Then you can use GUI applications remotely with standard copy-paste.

Using ssh With Clipboard Integration

  • Install xclip on the remote machine.
  • Use commands like echo "text" | ssh user@host "xclip -selection clipboard"

For headless servers, consider using tmux with clipboard integration.

Customizing Copy And Paste Shortcuts

You can change keyboard shortcuts in most Linux environments.

In Terminal Emulators

  1. Open terminal preferences.
  2. Go to the “Shortcuts” or “Keyboard” tab.
  3. Find the copy and paste actions and assign new keys.

In Desktop Environment

  1. Open System Settings.
  2. Navigate to “Keyboard” or “Shortcuts”.
  3. Modify the copy and paste shortcuts as desired.

This is usefull if you prefer the Windows-style shortcuts everywhere.

Clipboard Managers For Linux

Clipboard managers store history and provide advanced features.

  • CopyQ: Powerful, supports multiple items and editing.
  • Diodon: Lightweight, integrates with Unity and GNOME.
  • Parcellite: Simple, runs in the system tray.
  • Klipper: Built into KDE, offers history and actions.

Install via your package manager: sudo apt install copyq.

Copy And Paste In WSL (Windows Subsystem For Linux)

If you are using Linux inside Windows, the shortcuts may differ.

  • In WSL terminal, use Ctrl+Shift+C and Ctrl+Shift+V.
  • You can also enable “Use Ctrl+Shift+C/V as Copy/Paste” in the terminal settings.

This makes the experience similar to native Linux.

Frequently Asked Questions

Why doesn’t Ctrl+C work in Linux terminal?

In the terminal, Ctrl+C sends the interrupt signal to stop a running process. Use Ctrl+Shift+C to copy text instead.

How do I copy and paste in Linux without a mouse?

Use keyboard shortcuts: Ctrl+Shift+C to copy and Ctrl+Shift+V to paste in the terminal. In GUI apps, Ctrl+C and Ctrl+V work.

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

Primary selection is temporary and pasted with the middle mouse button. The clipboard is more permanent and used with Ctrl+V.

Can I copy and paste between different Linux terminals?

Yes, use the primary selection (highlight with mouse, then middle-click in another terminal) or clipboard shortcuts.

How do I copy a file path in Linux terminal?

Use readlink -f file.txt to get the full path, then copy it with Ctrl+Shift+C.

Conclusion

Mastering how to copy and paste in Linux is a fundamental skill that improves your workflow. Whether you are in the terminal, GUI, or remote session, the methods outlined here will help you work efficiently. Experiment with different shortcuts and tools to find what suits you best. With practice, these actions will become second nature.