- Select/copy/paste in terminal using only the keyboard
- 5 Answers 5
- Landoflinux
- Paste Command Examples
- How to Copy and Paste Text in the Linux Terminal
- Copying and Pasting Text Using Keyboard Shortcuts
- Changing the Default Keyboard Shortcuts
- Copy and Paste Text Using Your Mouse
- Linux Is Different From Windows or macOS
- How to copy and paste a file?
- 4 Answers 4
Select/copy/paste in terminal using only the keyboard
I’m looking for a way to select, copy and paste the text in the terminal completely without the mouse. I’ve been using tmux until now, but I find its key combinations a bit complex for everyday use of copy & paste, and I’m now looking for alternatives. Do you guys have any suggestions? To be clear, this is not about piping to the clipboard but about selecting the text as it’s possible in e.g. tmux !
See my answer here: askubuntu.com/a/756348/295286. Ive made a function that will copy whatever text is in front to clipboard. That works for copying the commands. As for output, it has to be piped
Okay guys this has nothing to do with stdout- it’s about moving a cursor to some previous printed text Select it and Copy/paste it to the current line of input in the terminal:-D Sorry for not being more precise in description.
The best way to add additional information to your question is by editing it, with the edit button. It is better visible that way, and comments are mainly for secondary, temporary purposes. Comments are removed under a variety of circumstances. Anything important to your question should be in the question itself.
5 Answers 5
I always use Ctrl + Shift + C and Ctrl + Shift + V to copy and paste in my (non tmux) terminal.
You can change these keyboard shortcuts in the keyboard preferences of your (non-tmux) terminal.
If however you want to keep using tmux you can also change the keyboard shortcuts of tmux by adding commands to ~/.tmux.conf . simply add the following in that file:
bind-key -n [shortcut. for example Ctrl+v is C-v] [what you want to do. for example 'new-window' etc]
You don’t need the command prefix key to execute the commands in the ~/.tmux.conf file.
For more info about the things available for ~/.tmux.conf check this link
Very rudimentary copying and pasting can be done using this however for a bit more usefulness I recommend using a Vim-style copy/paste config.
Enabling a Vim-style of copy/paste can be done with this config file or another config file. These do however require the use of the prefix key.
Someone even made a tmux extension to simplify the copy/paste action to the system clipboard in tmux. It might be worth a look.
If you want an alternative for Tmux you might try dvtm ( sudo apt-get install dvtm dtach ). I haven’t used it myself but it looks like it has similar options.
Landoflinux
The cut command enables you to extract a column of columns of information from a file. To specify the column that is to be extracted, we use the -c parameter. This is then followed by the column number. To extract more than one column, a comma separated list can be passed. Fields may also be specified by using the -f. A delimiter may also be specified with the -d parameter. The default delimiter is the tab character unless specified.
$ cat cutfile1.txt harry,25,16200 gill,46,17500 bill,45,20000 john,43,100000 barry,27,42000 paul,18,26500 $ cut -d, -f 1,3 cutfile1.txt harry,16200 gill,17500 bill,20000 john,100000 barry,42000 paul,26500
In the above example we have specified a delimiter of «,». We are specifying fields 1 and 3 are to be cut in the file «cutfile1.txt».
$ cat cutfile1.txt harry,25,16200 gill,46,17500 bill,45,20000 john,43,100000 barry,27,42000 paul,18,26500 $ cut -c 1-4 cutfile1.txt harr gill bill john barr paul
The above is an example of the cut command in its simplest form. Here we are cutting the first 4 letters from the file «cutfile1.txt».
Paste Command Examples
The paste command is useful for merging files together. The first line of each file is joined separated by a Tab character. It is possible to specify a different delimiter with the -d parameter.
$ cat pastefile1.txt one two three four five $ cat pastefile2.txt six seven eight nine ten $ paste pastefile1.txt pastefile2.txt one six two seven three eight four nine five ten
The next example is the same, however, we have changed the default Tab delimiter to a «:»
$ cat pastefile1.txt one two three four five $ cat pastefile2.txt six seven eight nine ten $ paste -d: pastefile1.txt pastefile2.txt one:six two:seven three:eight four:nine five:ten
How to Copy and Paste Text in the Linux Terminal
You can’t use Ctrl + C and Ctrl + V inside the Linux terminal to copy and paste some text. These shortcuts are a bit different for Linux.
Readers like you help support MUO. When you make a purchase using links on our site, we may earn an affiliate commission. Read More.
You’re viewing a tutorial online and need to paste a command inside the Linux terminal. You copy the text from the browser window, switch to the terminal, and press Ctrl + V, only to find «^V» appear on-screen. What happened? Why can’t you paste the text inside the terminal?
Copying and pasting text to and from the Linux command line isn’t as intuitive as it should be. The keyboard shortcuts work, but there’s a catch. We’ll show you two ways to copy/paste text within the Linux terminal so you can finally paste that command sitting in your clipboard for hours.
Copying and Pasting Text Using Keyboard Shortcuts
The standard keyboard shortcut for copying text is Ctrl + C. This is a globally accepted convention and almost all operating systems have this combination dedicated to copying text. Except for Linux!
The correct keyboard shortcut to copy text within a Linux terminal is Ctrl + Shift + C, and Ctrl + Shift + X for cutting. Similarly, to paste a string of text, press Ctrl + Shift + V.
The underlying reason for this behavior lies in Linux’s Unix roots. Before the introduction of a system-wide clipboard, Ctrl + C was, and still is, the standard shortcut to terminate a running program on Unix. Similarly, Ctrl + V was used for a verbatim insert.
When the new shortcuts were introduced on Unix and Linux, Ctrl + X was changed to include the Shift key, to maintain consistency.
You can, however, change these keyboard shortcuts if you want.
Changing the Default Keyboard Shortcuts
Almost every Linux terminal emulator lets you modify the preassigned keyboard shortcuts. To change the shortcut for cut/copy/paste, open the terminal, go to the Preferences section, and find an option labeled Keyboard Shortcuts, Shortcuts, Keyboard, or the like.
On most terminals, you can find Preferences by right-clicking anywhere inside the window.
Find the shortcut to copy, paste, and cut text from the list, and then define the new key combinations to perform those operations, i.e. Ctrl + C, Ctrl + V, and Ctrl + X, respectively.
Apply the changes and test the functionality by copying and pasting text using the new shortcuts.
These steps are general but will work on the terminal emulator you’re using. Konsole has the Configure Shortcuts option, and on Terminator, you can access Preferences from the context menu.
Copy and Paste Text Using Your Mouse
When keyboard shortcuts don’t work, the first thing that comes to mind is using the mouse to copy and paste the text. Right-clicking brings up the context menu. This menu contains options labeled Cut, Copy, and Paste, or at least Copy and Paste.
All you have to do now is select the text, right-click inside the terminal, and select Cut or Copy, depending on your needs. This is a system-wide feature and you can use it to copy text from anywhere.
When you want to paste the text, right-click inside the terminal and select Paste from the context menu. Like earlier, this will work on all Linux apps.
If copying and pasting text is part of your job, having a clipboard manager like CopyQ on your computer can help you be more efficient.
Linux Is Different From Windows or macOS
Pressing Shift when copying or pasting text from the terminal can be cumbersome. It’s hard to remember to press Shift every time you copy/paste stuff, especially amidst a busy day. Why even go through this when you can easily return to using those standard and easy-to-remember shortcuts?
A lot of things are different on Linux when compared with Windows or macOS. Some are for the good and simplify system operations, while others compel the users to switch to their previous operating system. Nevertheless, it’s essential to know and understand these differences.
How to copy and paste a file?
I want copy and paste a file. The name of the file is mkoctfile.m .
The path of this file is: /usr/share/octave/3.2.4/m/miscellaneous/mkoctfile.m I want to paste it to the following path /usr/bin/mkoctfile-3.2.4 I have made the directory by using following commands: sudo su mkdir -p /usr/bin/mkoctfile-3.2.4 but I don’t know how to copy and paste mkoctfile.m in this path. Please tell me what command I have to use.
4 Answers 4
Use the cp command to copy a file, the syntax goes cp sourcefile destinationfile . Use the mv command to move the file, basically cut and paste it somewhere else.
The exact syntax you would use for your example is:
sudo cp /usr/bin/octave/3.2.4/m/miscellaneous/mkoctfile.m /usr/bin/mkoctfile-3.2.4
For more information on the cp or mv commands you can run:
To @BKSurgeon, I would suggest to use the tab key to see the paths/directories available, or type ls to see them all at once printed.
I think it is better to use cp -a than just cp , if you want to have the same affect as when copy-pasting in desktop GUI.
You can cut, copy, and paste in CLI intuitively like the way you usually did in the GUI, like so:
- cd to the folder containing files you want to copy or cut.
- copy file1 file2 folder1 folder2 or cut file1 folder1
- close the current terminal.
- open another terminal.
- cd to the folder where you want to paste them.
- paste
To be able to do so, make sure you have installed xclip and realpath . Then, append these functions to the end of your ~/.bashrc file:
copy() < # if the number of arguments equals 0 if [ $# -eq 0 ] then # if there are no arguments, save the folder you are currently in to the clipboard pwd | xclip else # save the number of argument/path to `~/.numToCopy` file. echo $# >~/.numToCopy # save all paths to clipboard # https://stackoverflow.com/q/5265702/9157799#comment128297633_5265775 realpath -s "$@" | xclip fi # mark that you want to do a copy operation echo "copy" > ~/.copyOrCut > cut() < # use the previous function to save the paths to clipboard copy "$@" # but mark it as a cut operation echo "cut" >~/.copyOrCut > paste() < # for every path for ((i=1; i
If you don't know what .bashrc file is and never modify it before, just open the file explorer, go to Home, press Ctrl+H (show hidden files), search for .bashrc and open it with a text editor like gedit.
By using the above script, you are overriding the default functionality of these commands:
If you use one of those commands default functionality, just modify the script function names accordingly. For example, use p instead of paste .