xargs

Calling multiple commands with xargs

99封情书 提交于 2019-11-26 06:10:08
问题 cat a.txt | xargs -I % echo % In the example above, xargs takes echo % as the command argument. But in some cases, I need multiple commands to process the argument instead of one. For example: cat a.txt | xargs -I % {command1; command2; ... } But xargs doesn\'t accept this form. One solution I know is that I can define a function to wrap the commands, but it\'s not a pipeline, I don\'t prefer it. Is there another solution? 回答1: cat a.txt | xargs -d $'\n' sh -c 'for arg do command1 "$arg";

批量替换文件内容

泪湿孤枕 提交于 2019-11-26 00:46:48
1:查找 find . -type f -name "*.html"|xargs grep ‘yourstring’ 2:查找并替换 find -name '要查找的文件名' | xargs perl -pi -e 's|被替换的字符串|替换后的字符串|g' perl -pi -e 在Perl 命令中加上-e 选项,后跟一行代码,那它就会像运行一个普通的Perl 脚本那样运行该代码. 从命令行中使用Perl 能够帮助实现一些强大的、实时的转换。认真研究正则表达式,并正确地使用,将会为您省去大量的手工编辑工作。 3:批量修改文件夹权限 find . -type -d -name *.html|xargs chmod 755 4:批量修改文件权限 find . -type -f -name *.html|xargs chmod 644 查找和替换是很常用的操作。 这里介绍的小小技巧可以使你很轻松地完成大量重复、繁琐的工作。 以例子进行说明 在当前目录下的.c文件中查找字符串"password" grep "password" *.c 在当前目录及其多个子目录中查找文件test.c find . -name "test.c" -print 在当前目录及其多个子目录中查找.vbs文件并删除之 find . -name "*.vbs" -exec rm {} \;

Linux必会的命令:find

拜拜、爱过 提交于 2019-11-25 18:53:32
接上一条命令继续linux命令的学习: 命令:find 1.在当前目录,所有的普通文件中搜索xiaohan这个词 find ./ -type f -print |xargs grep "xiaohan" 2.在当前目录,删除1天以内的所有东西 find ./ -mtime -1 -print |xargs grep rm -rf 3.在当前目录,删除10天以前的所有东西 find ./ -mtime +10 -print |xargs grep rm -rf 4.删除文件大小为0的文件 find ./ -size 0|xargs rm -rf 来源: https://blog.csdn.net/Lemonhlj/article/details/98723553