Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Suppose you have different files in a directory: one.txt, two.jpg, three.pdf, four.jpg etc. You want to copy them all to clipboard from the command line. Something like copyclipboard *. How do you do it?

Based on this answer, which solves for a particular case, but has the filetype hardcoded in the script. I wonder if there is a more general solution.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Is this to speed up some workflow you have or for some script?

What I usually do is that when I enter the folder with the files I want to copy I run nautilus . to get the file browser. The workflow problem I see with copying straight from terminal is that you still need to browse to the folder where you want to paste the files later on.

Please comment if I'm missing something here.

share|improve this answer
add comment

In fact, the command I posted in the original question was applicable to a wide range of situations:

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

the only requirement is for the first command (find in this case) to generate a list of absolute filenames to files which need to be copied. If you check man find, you'll see that you can modify the command to find files created later than particular date, larger than particular size, having particular permissions, matching a particular regexp etc.

If you want to have a short-cut command for a particular use case - e.q. copying files from the current directory and below matching a particular mask, you can write a short script:

#!/bin/sh
find "$PWD" -name "$1" | xclip -i -selection clipboard -t text/uri-list

and call it with

cb "*.txt"

(where cb is the name of the script)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.