How to Copy and Paste Text at Linux’s Bash Shell

Share
  • September 23, 2019

Fatmawati Achmad Zaenuri/Shutterstock.com

Want to copy and paste at the command line of the Bash shell? We’ll show you multiple techniques whether you favor the keyboard or the mouse. These work whether you’re at a graphical desktop or at a traditional text-based TTY.

The Usual Keyboard Shortcuts Won’t Work

Copying and pasting text is a staple part of using a computer. When people use a Linux computer for the first few times, whether they come from the Windows or the macOS worlds, they are often confounded when trying to copy and paste within a terminal window.

In Windows, you use Ctrl+C to copy a section of highlighted text and Ctrl+V to paste it. In macOS, you use Command+C to copy it and Command+V to paste it. They follow the same convention of C to copy and V to insert.

Those very same keystrokes work in most Linux graphical applications, such as the editor gedit or the LibreOffice office suite.Ctrl+C copies highlighted text and Ctrl+V pastes it at the cursor. Our newcomer to Linux probably doesn’t even think about the fact that these conventions have been carried through to these applications. They use the keystrokes from muscle memory and get on with their work.

Once our newcomer opens a terminal window and tries to copy and paste at the Bash shell command prompt, that all changes. Ctrl+C and Ctrl+V were allocated functions long before copying and pasting were ever thought of.  In fact, those keystrokes were recruited a long time before graphical shells were invented, back when a teletype (TTY) was a physical thing.

Ctrl+C and Ctrl+V in TTYs

When a TTY was a physical device, Ctrl+C was chosen as a handy key combination to generate a signal. That signal is SIGINT, which tells the current process to terminate. Because a terminal window is an emulated TTY, that keystroke combination (and many others) have been preserved and replicated in the emulation. Note that it is the terminal window that is the emulation. The Bash shell is a program running in that emulated TTY.

We can easily see the functions that have been allocated to Ctrl+C and Ctrl+V. Suppose you type the following command and press “Enter.”

ls -R /

ls -R / in a terminal window

Because we’re using the -R (recursive) option the ls command will start to list every file and directory, starting from the root directory. After a couple of moments, you realize this is not what you wanted, so you terminate the process by hitting Ctrl+C.

Ctrl+C

Read the remaining 60 paragraphs

Source : How to Copy and Paste Text at Linux’s Bash Shell