What is the command line equivalent of copying a file to clipboard?

Strapakowsky

What is the command line equivalent to pressing CTRL+C over a file in the file manager so that the file (not the filename) is copied to the clipboard?

A situation where this can be useful and fast, for example, is when you want to copy to the clipboard a file from the directory you are in the terminal to quickly paste the file in the directory you are in the file manager. There are others.

Sergey

When you press Ctrl-C over a file in the file manager, the file's contents IS NOT copied to the clipboard. A simple test: select a file in file manager, press Ctrl-C, open a text editor, press Ctrl-V. The result is not file's contents but its full path.

In reality the situation is a bit more complicated because you can't do the opposite - copy a list of filenames from a text editor and paste them into file manager.

To copy some data from command line to X11 clipboard you can use xclip command, which can be installed with

sudo apt-get install xclip

to copy contents of a file or output of some command to clipboard use

cat ./myfile.txt|xclip -i

the text can be then pasted somewhere using middle mouse button (this is called "primary selection buffer").

If you want to copy data to the "clipboard" selection, so it can be pasted into an application with Ctrl-V, you can do

cat ./myfile.txt|xclip -i -selection clipboard

To be able to copy files from the command line and paste them in a file manager, you need to specify a correct "target atom" so the file manager recognizes the data in the clipboard, and also provide the data in correct format - luckily, in case of copying files in a file manager it's just a list of absolute filenames, each on a new line, something which is easy to generate using find command:

find ${PWD} -name "*.pdf"| xclip -i -selection clipboard -t text/uri-list

(at least this works for me in KDE). Now you can wrap into a small script which you can call, say, cb:

#!/bin/sh
xclip -i -selection clipboard -t text/uri-list

then you put it in ~/bin, set executable bit on it and use it like this:

find ${PWD} -name "*.txt"| cb

Nice, isn't it?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Copying files from command line to clipboard

From Dev

Copying files from command line to clipboard

From Dev

Clipboard for copying and pasting files in command line?

From Dev

Using command line to copy html file to clipboard

From Dev

Copying file path from GUI to the command line

From Dev

copying last bash command into clipboard

From Dev

What is the Command Line Equivalent of "Safely Remove Drive"?

From Dev

Command-line utility to copy file to clipboard from file path

From Dev

Command Line Clipboard Access

From Dev

How to copy an image to the clipboard from a file using command line?

From Dev

How to copy an image to the clipboard from a file using command line?

From Dev

Windows utility/tool command line to move clipboard to file

From Dev

Copying WindowsImageBackup in command line

From Dev

What is the equivalent to the Linux File command for windows?

From Dev

Copying to the clipboard in PowerShell without a new line

From Dev

Batch File - Copying contents of text file to clipboard

From Dev

copying binary file(.jpg) works from command line but not from script

From Dev

What is the command line equivalent for the update manager (Software Updater)?

From Dev

What is a neat command line equivalent to RStudio's Knit HTML?

From Dev

What is the command line in Puppy Linux that is equivalent to apt-get commands?

From Dev

What is the command-line equivalent to 'mintupdate' for Linux Mint?

From Dev

What is the command line in Puppy Linux that is equivalent to apt-get commands?

From Dev

What is the command line equivalent for the update manager (Software Updater)?

From Dev

what is the command line equivalent to using nautilus to connect to a samba drive?

From Dev

What is the Unix (QNX) equivalent of Windows command line "dir /s /b"

From Dev

What's the equivalent of bash parentheses at the command line in powershell?

From Dev

Command line equivalent of `getrusage()`

From Dev

Command line equivalent of `getrusage()`

From Dev

What is the function of @ at the command line after a file name

Related Related

  1. 1

    Copying files from command line to clipboard

  2. 2

    Copying files from command line to clipboard

  3. 3

    Clipboard for copying and pasting files in command line?

  4. 4

    Using command line to copy html file to clipboard

  5. 5

    Copying file path from GUI to the command line

  6. 6

    copying last bash command into clipboard

  7. 7

    What is the Command Line Equivalent of "Safely Remove Drive"?

  8. 8

    Command-line utility to copy file to clipboard from file path

  9. 9

    Command Line Clipboard Access

  10. 10

    How to copy an image to the clipboard from a file using command line?

  11. 11

    How to copy an image to the clipboard from a file using command line?

  12. 12

    Windows utility/tool command line to move clipboard to file

  13. 13

    Copying WindowsImageBackup in command line

  14. 14

    What is the equivalent to the Linux File command for windows?

  15. 15

    Copying to the clipboard in PowerShell without a new line

  16. 16

    Batch File - Copying contents of text file to clipboard

  17. 17

    copying binary file(.jpg) works from command line but not from script

  18. 18

    What is the command line equivalent for the update manager (Software Updater)?

  19. 19

    What is a neat command line equivalent to RStudio's Knit HTML?

  20. 20

    What is the command line in Puppy Linux that is equivalent to apt-get commands?

  21. 21

    What is the command-line equivalent to 'mintupdate' for Linux Mint?

  22. 22

    What is the command line in Puppy Linux that is equivalent to apt-get commands?

  23. 23

    What is the command line equivalent for the update manager (Software Updater)?

  24. 24

    what is the command line equivalent to using nautilus to connect to a samba drive?

  25. 25

    What is the Unix (QNX) equivalent of Windows command line "dir /s /b"

  26. 26

    What's the equivalent of bash parentheses at the command line in powershell?

  27. 27

    Command line equivalent of `getrusage()`

  28. 28

    Command line equivalent of `getrusage()`

  29. 29

    What is the function of @ at the command line after a file name

HotTag

Archive