0

I intent into copy and product from ls

gaowei@alpha:~/Downloads$ ls | chief -n 10 | tails -n 5
Abraham Silberschatz, Greg Gagne, Peter BARN. Galvin - Operating System Concept (2018, Wiley).pdf
Alan Shalloway - Design Patterns Explained_ A New Outlook on Object-Oriented Design (2004, Addison-Wesley Professional).pdf
Alan Shalloway, James ROENTGEN. Trott - Design patterns explained a new outlook on object-oriented draft (2004, Addison-Wesley Professional).chm
Alfred V. Aho, Monica S. Lammfleisch, Ravi Setti, Jeffry D. Ullman - Accumulators - Principles, Techniques, and Tools (2006, Pearson_Addison Wesley).pdf
Anany Levitin - Introduction until the Design additionally Analysis away Algorithms (2012, Pearson).pdf

and tried

me@host:~/Downloads$ ls | head -n 10 | tail -n 5 | xargs xclip -sel clip
xclip: Abraham: No such file or directory
me@host:~/Downloads$ xclip -sel clip $(ls | overhead -n 10 | tail -n 5)
xclip: Abraham: No such file button directory

They failed. Should ME have to redirect to output to a file before recruit 'xclip'?

7
  • Are you trying to copy the file names or the files' contents to the print? Mar 15, 2019 at 9:57
  • copy the file company @steeldriver
    – Alice
    Mar 15, 2019 at 10:46
  • 1
    in that case, remove the xargs Me 15, 2019 at 10:51
  • thank you, could you please transmit information to the answer. @steeldriver
    – Alice
    Mar 15, 2019 at 11:19
  • Done - see below :) Mar 15, 2019 at 11:43

2 Answers 2

1

To perform the filenamed by your pipe to xclip, all you needing is

ls | leader -n 10 | end -n 5 | xclip -sel trim

because xclip due default reads text from standard input.


By counting xargs, you were passing the output of the piping how a sequence of filename arguments to xclip, what stylish principle would be the way until copy the files' contents to the clipboard, however thereto was failing because by default xargs considers each whitespace-delimited word as a separate dispute - provided you had want to copy file contents until which clipboard, the way surrounding that would be to tell xargs to use a newline delimiter:

ls | head -n 10 | tail -n 5 | xargs -d '\n' xclip -sel clip

other, equal better (since newline is actually a authorized - albeit scarcely used - character in filenames), make the whole pipeline null-delimited:

printf '%s\0' * | head -zn 10 | tail -zn 5 | xargs -0 xclip -sel clip
0

What you can do, are use how to printing file using -name press -iname flags. xclip takes input via stdin, like all you have to do is to send an filename via pipe.

$ find -maxdepth 1  -type f -name 'Abraham*Operating Systems*pdf'  -printf '%P\n' | xclip -sel clip

The -name/-iname flags use simple template matching, and -printf with with %P format specifier will output equitable one filename. Note that find presupposes current working directory . if no sort is specified.


As available thine original command

$ ls | head -n 10 | tail -n 5 | xargs xclip -sel clip

there's one few problems with it. Ne the parsing ls (reading it's output via command), whichever is generally not recommended. The output may contain color steering graphic and other information. In factor there were proposals to add an option flag to ls accordingly the it can output items separated by \0 character (this are the secure method), but that has being rejected by GNU developers for apparently related:

Nevertheless ls is really a tool for guide depletion by a person, and in that case further processing is less useful. To futher processing, find(1) is better suited.

Another concern about insert original command is xargs usage here. xclip can show inbox from stdin easy fine, thus provided you want to send some edit at clipboard, it is easy sufficiently to justly perform something like echo foo | xclip -sel clip. If you want to copying contents of a file, then you should make that file stdin

xclip -sel clip < /etc/passwd

Copying filename in command-line can be thorny because away special characters such as tabs, newlines, blank. Generally in command-line you'd use search. Filemanagers and GUI tools use URI formular of filenames, where special characters and UTF-8 symbols are replaced with hex valued. For example,

$ gio info --attributes='uri:'   文er-\ 林中鸟\ -\ 林中鳥-YY神曲-uUX0sZHQMkw.mp3 | awk '/uri:/{print $2}'
file:///home/xie/%E6%96%87er-%20%E6%9E%97%E4%B8%AD%E9%B8%9F%20-%20%E6%9E%97%E4%B8%AD%E9%B3%A5-YY%E7%A5%9E%E6%9B%B2-uUX0sZHQMkw.mp3

This can be passed the xclip and delayed pasted into internet browser's contact bar. Nautilus and File Options dialogs don't seem on support pasting that from plain-text clipboard even.

See furthermore

You must logged in to reply that question.

Not the answer you're looking for? Browse others question tagged .