- 浏览: 597114 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
月光杯:
问题解决了吗?
Exceptions in HDFS -
iostreamin:
神,好厉害,这是我找到的唯一可以ac的Java代码,厉害。
[leetcode] word ladder II -
standalone:
One answer I agree with:引用Whene ...
How many string objects are created? -
DiaoCow:
不错!,一开始对这些确实容易犯迷糊
erlang中的冒号 分号 和 句号 -
standalone:
Exception in thread "main& ...
one java interview question
am trying to use xargs command using
shell pipes and not able to understand how to control and use command
line arguments. For example I'd like to find out all *.c file located
in 100s of sub-directories and move them to another directory called
~/old.src. How do I use command line args with xargs to achieve the
same?
xargs command is designed to construct argument lists and invoke other
utility. xargs reads items from the standard input or pipes, delimited
by blanks or newlines, and executes the command one or more times with
any initial-arguments followed by items read from standard input. Blank
lines on the standard input are ignored.
xargs is more safer and easy to use
xargs functionality can be achived using the backquote feature of shell. But, it offers more options. It can deal with blanks or special characters in file names easily. It is often used with find, grep and other commands.
xargs examples
For example following example will print 1 2 3 4 using xargs (echo command is default)$ echo 1 2 3 4 | xargs echo
OR$ echo 1 2 3 4 | xargs
You can force xargs to use at most max-args arguments per command line.
For example following will use first two argument per command:$ echo 1 2 3 4 | xargs -n 2
Find all .bak files in or below the current directory and delete them.$ find . -name "*.bak" -type f -print | xargs /bin/rm -f
{} as the argument list marker
{} is the default argument list marker. You need to use {} this with
various command which take more than two arguments at a time. For
example mv command need to know the file name. The following will find
all .bak files in or below the current directory and move them to
~/.old.files directory:$ find . -name "*.bak" -print0 | xargs -0 -I mv {} ~/old.files
You can rename {} to something else. In the following example {} is
renamed as file. This is more readable as compare to previous example:$ find . -name "*.bak" -print0 | xargs -0 -I file mv file ~/old.files
Where,
- -0 If there are blank spaces or characters (including newlines) many commands will not work. This option take cares of file names with blank space.
- -I Replace occurrences of replace-str in the initial-arguments with names read from standard input. Also, unquoted blanks do not terminate input items; instead the separator is the newline character.
Dealing file names with blank spaces and newline
The following will work incorrectly if there are any filenames
containing newlines or spaces (it will find out all .mp3 file located
in current directory and play them using mplayer):$ find . -iname "*.mp3" -print | xargs mplayer
To get rid of this problem use -0 option:$ find . -iname "*.mp3" -print0 | xargs -0 -I mp3file mplayer mp3file
To find out all *.c file located in 100s of subdirectories and move them to another directory called ~/old.src, use:$ find /path/to/dir -iname "*.c" -print0 | xargs -0 -I file mv file ~/old.src
Avoiding errors and resource hungry problems with xargs and find combo
To copy all media files to another location called /bakup/iscsi, you can use cp as follows:$ cp -r -v -p /share/media/mp3/ /backup/iscsi/mp3
However, cp command may fail if an error occurs such as if the number
of files is too large for the cp command to handle. xargs in
combination with find can handle such operation nicely. xargs is more
resource efficient and will not halt with an error:
$ find /share/media/mp3/ -type f -name "*.mp3" -print0 | xargs -0 -r -I file cp -v -p file --target-directory=/bakup/iscsi/mp3
Please note that all of the above commands are tested with GNU/xargs
version. BSD and UNIX xargs command may not have options such as -r.
Please refer to your local xargs man page for further info:man xargs
发表评论
-
shell字符串截取
2013-07-19 15:09 853${string#substring} 从string左边去掉 ... -
一个命令创建多个目录
2013-06-13 12:36 893可能我太土了,才发现下面这个命令! mkdir -p src ... -
use "--links" option of rsync
2013-05-23 10:45 725Today I used rsync to copy some ... -
Date/Time处理函数总结 [To Do]
2013-04-12 10:46 649几种我所用到的用来处理日期,时间的函数总结。 Perl 1 ... -
Makefile tutorial
2013-01-07 14:30 892Old but good. http://www.codep ... -
crontab定期执行命令详解,以及实例
2012-12-18 17:29 919使用时可以参考这个博客: http://blog.51yip ... -
vim tips
2012-07-04 13:59 944I read some articles about vim ... -
cvs不能更新文件的权限
2012-06-28 13:07 1073一个project用到了古老的cvs管理源代码。 一个文件我c ... -
GNU Make Variables: simple and recursive
2012-04-19 14:17 1027今天有时间看了一下teammate写的makefile,学习了 ... -
How do I find the largest top 10 files in linux?
2012-04-06 15:24 1108http://www.cyberciti.biz/faq/ho ... -
xargs usage with multi arguments
2011-11-30 12:24 606http://offbytwo.com/2011/06/26/ ... -
how to explain free buffers and cached memory usage
2011-07-18 11:57 1252free -m tota ... -
Pro Git Tips
2011-07-14 17:53 10381. git init Create a new repo ... -
"error in locking authority file .Xauthority
2011-01-11 11:34 2824今天在windows上vncviewer连linux机器的时候 ... -
raid 0 vs. raid1
2010-12-30 10:20 1346RAID 0 (block-level striping ... -
hwo to configure linux vncserver
2010-12-24 14:10 842http://bobpeers.com/linux/vnc -
set cpu performance mode
2010-11-15 14:38 1851A cheap/dirty little hack to in ... -
Ten Amazing Linux Commands
2010-11-08 22:42 889sudo !! 以 root 帐户执行上一条命令。 ... -
awk code
2010-10-26 17:53 918netstat -n | awk '/^tcp/ {++S ... -
Queue sysfs files
2010-07-28 13:50 1040Based on kernel version 2.6.34. ...
相关推荐
git-xargs是一个命令行工具 (CLI),用于使用单个命令跨多个 Github 存储库进行更新。 你给git-xargs : 要运行的脚本或命令 回购清单 和git-xargs将: 克隆每个 repo 针对它运行您指定的脚本或命令 提交任何更改...
mesos-xargs 有一个Mesos集群,您只想在上面运行东西吗? 曾经希望您可以只使用xargs吗? 不? 好的。 您是个理智的人,应该像普通人一样使用Hadoop。安装Mesos python绑定有点混乱。 主mesos绑定需要与主Mesos...
这是“xargs”unix 命令的流媒体版本。安装npm install --save xargs用法该模块导出的函数返回一个双工流,该流将写入其中的所有字符串块收集到一个数组中,该数组用作指定命令的参数向量: var streamify = ...
xargs命令有两个要点。第一,你必须列出目标文件。第二,你必须指定对每个文件需要执行的命令或脚本。 xargs命令被用来处理分布在不同目录下的文件: 计算所有文件的行数 打印指定文件的第一行 对每个文件执行一...
Hands-on activities and exercises will cement your newfound knowledge and give you the confidence to use the CLI to its fullest potential. And if you're worried you'll wreck your system, this book ...
windows dos下xargs使用
xargs_for_window
Fast command-line navigation using pushd and popd 126 Counting number of lines, words, and characters in a file 128 Printing directory tree 129 Chapter 4: Texting and Driving 131 Introduction 132 ...
git-xargs是一个命令行工具...您给git-xargs:运行回购清单的脚本或命令,而git-xargs将:克隆每个回购对您的脚本或命令运行指定的回购提交任何更改打开拉取请求可提供发生的一切的详细报告例如,您是否需要添加特定的
只要介绍XARGS的应用
可在windows使用的类linux工具xargs,可以配合类liunx工具find进行文件处理。xargs的使用帮助为 xargs --help,实例可以上网查询。也可另外下载我的dos工具。
xargs
find命令和xargs命令配合使用,自己总结的,觉得还好
编译VoodooI2C必用的,经过VoodooI2C作者改动的clodoc. 这是可执行文件,放到/usr/local/bin中就行了,防止编译出现错误:xargs: cldoc: No such file or directory
If you use constants in your value, and these constants belong to a ; dynamically loaded extension (either a PHP extension or a Zend extension), ; you may only use these constants *after* the line ...
文章主要对Linux文件查找命令find和xargs进行详细描述,感性趣的朋友可以参考下。
Use 'apt-get autoremove' to remove them. 将会安装下列额外的软件包: libencode-locale-perl libfile-listing-perl libfont-afm-perl libhtml-form-perl libhtml-format-perl libhtml-parser-perl libhtml-tag...
Linux xargs 命令 xargs 是给命令传递参数的一个过滤器,也是组合多个命令的一个工具。 xargs 可以将管道或标准输入(stdin)数据转换成命令行参数,也能够从文件的输出中读取数据。 xargs 也可以将单行或多行文本...
xargs 是给命令传递参数的一个过滤器,可以将管道或标准输入的数据转换成参数,默认的命令是 echo,这意味着通过管道传递给 xargs 的输入将会包含换行,不过通过 xargs 的处理,换行将被空格取代。