通过输出作为在bash CP参数 [英] pass output as an argument for cp in bash
问题描述
我正在在Unix / Linux类,我们还没有学会变量或函数。我们刚刚学会像国旗和管道,输出一些基本的实用程序和附加到文件。在实验室的任务,他希望我们找到最大的文件,并将它们复制到一个目录。
我可以得到5个最大的文件,但我不知道如何将它们传递到CP在一个命令
LS -SF | grep的-v / |头-5 | CP?目录
这将是:
CP`LS -SF | grep的-v / |头-5`目录
假设管道是正确的。反引号中的行替换里面的命令的输出。
您也可以让你的测试:
CP`回声A B C`目录
将复制 A
, B
和 C
到目录
。
I'm taking a unix/linux class and we have yet to learn variables or functions. We just learned some basic utilities like the flag and pipeline, output and append to file. On the lab assignment he wants us to find the largest files and copy them to a directory.
I can get the 5 largest files but I don't know how to pass them into cp in one command
ls -SF | grep -v / | head -5 | cp ? Directory
It would be:
cp `ls -SF | grep -v / | head -5` Directory
assuming that the pipeline is correct. The backticks substitute in the line the output of the commands inside it.
You can also make your tests:
cp `echo a b c` Directory
will copy all a
, b
, and c
into Directory
.
这篇关于通过输出作为在bash CP参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!