- 浏览: 611102 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
月光杯:
问题解决了吗?
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 887${string#substring} 从string左边去掉 ... -
一个命令创建多个目录
2013-06-13 12:36 919可能我太土了,才发现下面这个命令! mkdir -p src ... -
use "--links" option of rsync
2013-05-23 10:45 758Today I used rsync to copy some ... -
Date/Time处理函数总结 [To Do]
2013-04-12 10:46 706几种我所用到的用来处理日期,时间的函数总结。 Perl 1 ... -
Makefile tutorial
2013-01-07 14:30 921Old but good. http://www.codep ... -
crontab定期执行命令详解,以及实例
2012-12-18 17:29 953使用时可以参考这个博客: http://blog.51yip ... -
vim tips
2012-07-04 13:59 976I read some articles about vim ... -
cvs不能更新文件的权限
2012-06-28 13:07 1104一个project用到了古老的cvs管理源代码。 一个文件我c ... -
GNU Make Variables: simple and recursive
2012-04-19 14:17 1060今天有时间看了一下teammate写的makefile,学习了 ... -
How do I find the largest top 10 files in linux?
2012-04-06 15:24 1144http://www.cyberciti.biz/faq/ho ... -
xargs usage with multi arguments
2011-11-30 12:24 636http://offbytwo.com/2011/06/26/ ... -
how to explain free buffers and cached memory usage
2011-07-18 11:57 1288free -m tota ... -
Pro Git Tips
2011-07-14 17:53 10721. git init Create a new repo ... -
"error in locking authority file .Xauthority
2011-01-11 11:34 2893今天在windows上vncviewer连linux机器的时候 ... -
raid 0 vs. raid1
2010-12-30 10:20 1381RAID 0 (block-level striping ... -
hwo to configure linux vncserver
2010-12-24 14:10 861http://bobpeers.com/linux/vnc -
set cpu performance mode
2010-11-15 14:38 1892A cheap/dirty little hack to in ... -
Ten Amazing Linux Commands
2010-11-08 22:42 914sudo !! 以 root 帐户执行上一条命令。 ... -
awk code
2010-10-26 17:53 946netstat -n | awk '/^tcp/ {++S ... -
Queue sysfs files
2010-07-28 13:50 1072Based on kernel version 2.6.34. ...
相关推荐
git-xargs是一个命令行工具 (CLI),用于使用单个命令跨多个 Github 存储库进行更新。 你给git-xargs : 要运行的脚本或命令 回购清单 和git-xargs将: 克隆每个 repo 针对它运行您指定的脚本或命令 提交任何更改...
### Linux Command Line 知识点详解 #### 一、引言 在《Linux Command Line》这本书中,作者为我们提供了一系列关于Linux命令行的基础知识与实用技巧。这些内容不仅适合Linux初学者快速上手,同时也为有经验的用户...
mesos-xargs 有一个Mesos集群,您只想在上面运行东西吗? 曾经希望您可以只使用xargs吗? 不? 好的。 您是个理智的人,应该像普通人一样使用Hadoop。安装Mesos python绑定有点混乱。 主mesos绑定需要与主Mesos...
这是“xargs”unix 命令的流媒体版本。安装npm install --save xargs用法该模块导出的函数返回一个双工流,该流将写入其中的所有字符串块收集到一个数组中,该数组用作指定命令的参数向量: var streamify = ...
在Windows DOS环境下,xargs命令通常不是内置的,但可以通过安装一些开源工具,如Cygwin,来获得这个功能。Cygwin是一个提供Linux环境下的命令行工具在Windows上运行的开源软件。在这个环境中,我们可以找到`xargs....
在IT领域,尤其是在Linux和Unix系统中,`xargs`是一个非常实用的命令行工具,用于从标准输入中读取数据并将其作为参数传递给其他命令。然而,标题中的"xargs_for_window"表明我们将讨论如何在Windows环境中实现类似...
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 ...
xargs [OPTIONS] [COMMAND [initial-arguments]] ``` 3. **实例** - **创建文件**:创建三个文件`file1`, `file2`, `file3`,使用`echo`和`xargs`结合`touch`命令。 ``` [root@localhost ~]# echo "file1 file...
然而,有一款名为`xargs`的工具,它为Windows用户提供了类Linux的体验,使得在Windows上进行文件处理变得更加方便。`xargs`是Linux系统中一个非常强大的命令,它能将`find`命令或者其他命令的输出作为参数传递给其他...
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将:克隆每个回购对您的脚本或命令运行指定的回购提交任何更改打开拉取请求可提供发生的一切的详细报告例如,您是否需要添加特定的
Linux文件查找命令`find`和`xargs`是Linux系统中非常重要的工具,它们帮助用户在文件系统中高效地定位和处理文件。本文将详细解释这两个命令的基本使用和相关选项。 `find`命令是一个功能强大的命令,用于在指定...
Linux xargs 命令 xargs 是给命令传递参数的一个过滤器,也是组合多个命令的一个工具。 xargs 可以将管道或标准输入(stdin)数据转换成命令行参数,也能够从文件的输出中读取数据。 xargs 也可以将单行或多行文本...
| === Welcome to Tunoff services === | +--------------------------------------------------------------+ EOF 说明:该命令可以在 SHELL 中显示多个信息,cat 选项可以显示文件,EOF 选项指定结束符。 10. for...
**xargs:** 相比之下,`xargs`不仅能够传递数据,还能够根据需要构建复杂的命令。它从标准输入中读取数据,并将这些数据作为参数传递给指定的命令,从而可以执行更复杂的操作,比如删除或移动文件。 例如,使用`...
-type f -name 'pattern' | xargs command`,其中find命令用于查找符合特定条件的文件,然后通过管道(|)传递给xargs,最后由xargs调用command执行操作。 接着,我们转向Linux的文件系统挂载和卸载。在Linux中,...
只要介绍XARGS的应用
### Linux的find与xargs命令详解 在Linux系统中,`find`与`xargs`是两个非常强大的命令行工具,它们分别用于查找文件和执行命令。本文将深入解析这两个命令的功能、用法以及如何结合使用,以实现高效的数据处理。 ...