xargs

Linux控制删除深度!除find ./ -maxdepth 1 -name "*.c" | xargs rm -rf

柔情痞子 提交于 2019-12-02 08:33:45
find ./ -maxdepth 1 -name “*.c” | xargs rm -rf 也就是说-maxdepth 参数要写在其他参数的前面,同时在路径的后面 xargs命令 xargs命令通俗来讲就是将标准输入转成各种格式化的参数,所以命令[command 1] | xargs [command 2]就是 将command 1的标准输出结果,通过管道|变成xargs的标准输入 ,然后xargs再将此标准输入变成参数,传给[command 2]。这样一来,通过xargs命令,我们便可以在管道后面使用那些不接收标准输入的命令了。例如[command 1]|xargs ls,是不是很熟悉? 这个命令只会删除当前目录下的文件! 删除两层深度! 来源: CSDN 作者: dream_网络安全 链接: https://blog.csdn.net/weixin_42859280/article/details/83377904

Using xargs with Special characters

时间秒杀一切 提交于 2019-12-02 07:42:32
问题 I have the following problem. Got a file which includes certain paths/files of a FS. These for some reason do include the whole range of special characters, like space, single/double quotes, even sometimes the Copyright ASCII. I need to run each line of the file and pass it to another command. What I tried so far is: <input_file xargs -I % command % Which was working until I got this message from xargs xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0

centos7.4.1708 重装yum和python和wxpy的一次旅行

人盡茶涼 提交于 2019-12-02 07:18:34
在linux下折腾wxpy,想着尝试给小聪子发送信息,一直失败,后来误删了pyhon特定文件,无奈,只有重投开始搞 1、yum是用python写的 2、删除pyhon rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps ##强制删除已安装程序及其关联 whereis python |xargs rm -frv ##删除所有残余文件 ##xargs,允许你对输出执行其他某些命令 whereis python ##验证删除,返回无结果 3、删除yum rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps whereis yum |xargs rm -frv 4、在/usr/local/src下创建yum和python用于存放python包 cd /usr/local/src/python wget http://vault.centos.org/7.4.1708/os/x86_64/Packages/python-2.7.5-58.el7.x86_64.rpm wget http://vault.centos.org/7.4.1708/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm wget http:/

To understand recursive grep in xargs

浪子不回头ぞ 提交于 2019-12-02 07:18:16
What is the practical difference between the following two commands? Command A find . -type f -print0 | xargs -0 grep -r masi Command B find . -type f -print0 | xargs -0 grep masi In short, what is the practical benefit of Command A? None .. -r is for recursively searching directories, but the -type f will prevent find from returning directory names. I think none The A will try to recurse over file names (as the find is only searching for files) so it will not recurse into anything... 来源: https://stackoverflow.com/questions/1121807/to-understand-recursive-grep-in-xargs

Using xargs with Special characters

隐身守侯 提交于 2019-12-02 02:46:33
I have the following problem. Got a file which includes certain paths/files of a FS. These for some reason do include the whole range of special characters, like space, single/double quotes, even sometimes the Copyright ASCII. I need to run each line of the file and pass it to another command. What I tried so far is: <input_file xargs -I % command % Which was working until I got this message from xargs xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option But usinf this option did not work at all for me xargs: argument line too long Does anybody

To understand xargs better

自作多情 提交于 2019-12-01 20:57:13
I want to understand the use of xargs man in Rampion's code : screen -t man /bin/sh -c 'xargs man || read' Thanks to Rampion: we do not need cat! Why do we need xargs in the command? I understand the xargs -part as follows cat nothing to xargs xargs makes a list of man -commands I have had an idea that xargs makes a list of commands. For instance, find . -type f -print0 | xargs -0 grep masi is the same as a list of commands: find fileA AND grep masi in it find fileB AND grep masi in it and so on for fileC, fileD, ... No, I don't cat nothing. I cat whatever input I get after I run the command.

为了系统安全,会做哪些努力?

帅比萌擦擦* 提交于 2019-12-01 20:11:22
上周去面试,被问了个问题,如果保障你服务器的安全?事情太过杂碎我一时间想不起来很多,被问了个措手不及.痛定思痛后决定来总结一番. 有参考众网友的意见,有总结过去的经验,也有包含书籍中介绍的。安全运维技能是每个运维人士必备的,毕竟自己的地盘哪容得旁人撒野。众多检查选项会写成定时任务,在凌晨2-5点之间分批执行,并记录下检查结果。关于定时任务脚本,另有篇幅会总结出来。 一、检查文件权限 不正确的权限设置直接威胁着系统的安全,因此运维人员应该能及时发现并立刻修正,防患于未然。 find / -type f -perm -2 -o -perm -20 |xargs ls -al //查找任何用户都有写权限的文件或目录 find / -type f -perm -4000 -o -perm -2000 -print | xargs ls –al //防止提权 find / -user root -perm -4000 -print -exec md5sum {} ; //检查系统中所有suid及sgid文件 二、查看 passwd 文件中有哪些特权用户,删除特殊的账户和账户组,最近24小时添加了哪些用户 # awk -F: '$3==0 {print $1}' /etc/passwd 可删除的用户adm,lp,sync,shutdown,halt,news,uucp,operator

linux批量替换文件内容3种方法(perl,sed,shell)

梦想与她 提交于 2019-12-01 16:22:22
方法1: 这两天在构建一个应用的使用用到了maven,由于project很大,足足有700多个 pom.xml文件,更郁闷的是在很多pom.xml文件里都单独指定了资源库的url,我需要把这些资源库的url统一指定到nexus本地中央库. 手 工一个个改文件配置有点不太实际,所以google了一下,找到批量替换文件内容的好方法,命令结构如下: find -name '要查找的文件名' | xargs perl -pi -e 's|被替换的字符串|替换后的字符串|g'下面这个例子就是将当前目录及所有子目录下的所有pom.xml文件中的”http://repo1.maven.org/maven2“ 替换为”http://localhost:8081/nexus/content/groups/public“. find -name 'pom.xml' | xargs perl -pi -e 's|http://repo1.maven.org/maven2|http://localhost:8081/nexus/content /groups/public|g'这里用到了Perl语言, perl -pi -e 在Perl 命令中加上-e 选项,后跟一行代码,那它就会像运行一个普通的 Perl 脚本 那样运行该代码. 从命令行中使用Perl 能够帮助实现一些强大的、实时的转换。

Linux——xargs命令学习

隐身守侯 提交于 2019-12-01 15:38:06
有时候我们会遇到需要将指定命令返回结果进行处理的情况 这种情况下,可能就需要写for循环之类的脚本进行处理了(目前我只能想到这种方法) 但是想起来还有一个xargs命令,组合这个命令就比较省事了。 场景如下: 安装Redis执行make test时,报Redis已在运行导致冲突。ps -ef查看Redis,发现还真的有十来个redis进程再跑。那就只能把其全部关闭了。一个一个kill不现实,于是研究了一下xargs命令来实现。以下是我的做法 1.首先我们需要获取到所有redis进程信息 ps -ef|grep redis |grep -v grep>/root/redispid.txt [root@bogon ~]# cat redispid.txt root 69984 1 0 23:09 pts/1 00:00:00 src/redis-server 127.0.0.1:21242 root 69992 1 0 23:09 pts/1 00:00:00 src/redis-server 127.0.0.1:21272 root 69994 1 0 23:09 pts/1 00:00:00 src/redis-server 127.0.0.1:21222 root 69998 1 0 23:09 pts/1 00:00:00 src/redis-server 127.0.0.1

Got exit code 123 in find + xargs grep

送分小仙女□ 提交于 2019-12-01 10:43:42
Here is my script eval "find \\( -type f -a \\( -name '*.h' \\) \\) -print0" | xargs -0 -n100 grep -f <(echo "stdio") echo $? Nothing is found and the exit code is 123. If I modify it a little as follows echo "stdio" >.P eval "find \\( -type f -a \\( -name '*.h' \\) \\) -print0" | xargs -0 -n100 grep <.P echo $? Something is found but the exit code is still 123. So what is wrong? ====================================================================== Actually I just want to write a small script to make find+xargs+grep easier. For exmaple, xgrep -e PATTERN1 -e PATTERN2 ... *.c *.h is to execute