我试图产生这种行为:
grep 192.168.1 *.txt
Run Code Online (Sandbox Code Playgroud)
通过 Xargs 将字符串传递到 grep 中,但它会在最后而不是作为第一个参数。
echo 192.168.1 | xargs grep *.txt
Run Code Online (Sandbox Code Playgroud)
我需要告诉 xargs(或类似的东西)将传入的字符串放在 'grep' 和 '*' 之间,而不是放在最后。
我该怎么做呢?
我有一个名为的文件夹/home/user/temps
,其中包含 487 个文件夹。在每个文件夹中,我都有一个名为 thumb.png 的文件。
我想将所有名为 thumb.png 的文件复制到一个单独的文件夹中,并根据它们来自的文件夹重命名它们。
当 xargs 将第一个命令输出重定向到第二个命令的参数并且无法选择输出的哪个元素的哪个参数时,那么只有一种方法,例如:
ls | xargs file # there are as many arguments as files in the listing,
# but the user does not have too choose himself
Run Code Online (Sandbox Code Playgroud)
现在如果需要选择:
ls | xargs file | grep image | xargs mv..... # here the user has to
# deal with two arguments of mv, first for source second for destination, suppose your destination argument is set already by yourself and you have to put the output into the source argument.
Run Code Online (Sandbox Code Playgroud)
您如何告诉 xargs …
我想从大型日志文件和备份中清理我的服务器。
我想出了这个:
find ./ -size +1M | xargs rm
Run Code Online (Sandbox Code Playgroud)
但我不想包括 mp3 和 mp4。我只想对日志和存档文件(zip、tar 等)执行此操作
命令会是什么样子?
我想知道是否有人知道如何找到一个模式,然后将其移动到不同的位置。
例如,我有很多文件名为:
odbc.ini_20110630
odbc.ini_20110639
odbc.ini_20110643
etc...
Run Code Online (Sandbox Code Playgroud)
我想搜索 just 的模式odbc.ini
并将它们全部移动到不同的文件夹。
我不太熟悉如何一次执行两个命令(管道)。