xargs

linux commands - 一次性解压多个tar.gz文件

扶醉桌前 提交于 2019-12-01 10:28:24
1 echo *.tar.gz | xargs -n 1 tar -zxvf list所有tar.gz文件,然后利用xargs将其作为参数传给tar命令。-n 1表示每次传一个参数。 xargs: https://www.cnblogs.com/wangqiguo/p/6464234.html 阅读目录 为什么要用xargs,问题的来源 xargs是什么,与管道有什么不同 xargs的一些有用的选项 回到顶部 为什么要用xargs,问题的来源 在工作中经常会接触到xargs命令,特别是在别人写的脚本里面也经常会遇到,但是却很容易与管道搞混淆,本篇会详细讲解到底什么是xargs命令,为什么要用xargs命令以及与管道的区别。为什么要用xargs呢,我们知道,linux命令可以从两个地方读取要处理的内容,一个是通过命令行参数,一个是标准输入。例如cat、grep就是这样的命令,举个例子: 1 echo 'main' | cat test .cpp 这种情况下cat会输出test.cpp的内容,而不是'main'字符串,如果test.cpp不存在则cat命令报告该文件不存在,并不会尝试从标准输入中读取。echo 'main' | 会通过管道将 echo 的标准输出(也就是字符串'main')导入到 cat 的标准输入,也就是说此时cat的标准输入中是有内容的,其内容就是字符串'main

linux - 卸载python

六眼飞鱼酱① 提交于 2019-12-01 09:53:10
2019年10月15日12:05:42[root@spider1 bin]# rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps ##强制删除已安装程序及其关联 [root@spider1 bin]# whereis python |xargs rm -frv ##删除所有残余文件 ##xargs,允许你对输出执行其他某些命令 [root@spider1 bin]# whereis python ##验证删除,返回无结果 来源: https://www.cnblogs.com/tnsay/p/11676895.html

部分工具与基础

情到浓时终转凉″ 提交于 2019-12-01 08:49:19
A long lists Shell hello File pro Toos Toos and sed Rpm and yum shell hello 格式 变量 运算 条件 登录方式与配置文件读取 环境 格式 行首:#!/bin/shells 注释:"#" 开头 运行:bash script 、chmod +x script ; 路径 / script 建议:添加脚本的作用,使用方法,参数、变量说明。 变量 Type :string number 命名 :- 关键字、-数字字母下划线、驼峰命名 种类 : 局部变量:当前shell内有效 环境变量:当前shell、子shell 本地变量: funtion 位置变量: 参数:123 10 所有,数组 特殊变量: $?:cmd retrun 、也可在script中设置 exit[value] 来控制retrun $0:script name $$:当前进程pid 只读变量:readonly 变量、declare 变量 运算 算数符 + - * / % let 随机函数 $RANDOM 0-32767 增强算数符 += -= *= /= %= 自增减 ++ -- 逻辑运算 true false 0 1 & | ! ^ && || 条件 test 判断 [ 判断 ] [[ 判断 ]] 测试变量是否创建 [ -v 变量 ] number [

xargs respect wildcards in searches

杀马特。学长 韩版系。学妹 提交于 2019-12-01 08:37:12
I have a file called file1.txt: dir1 dir2 dir3 ... I wanted to use xargs to check if some files exist farther into the file system like this: cat file1.txt | xargs -i ls /projects/analysis7/{}/meta_bwa/hg19a/*varFilter 2>/dev/null But xargs never seems smart enough to expand the *. ie, it never finds the files even when they would match the pattern (if the * was expanded). Any ideas? You just need to add sh -c : cat file1.txt | xargs -i sh -c 'ls /projects/analysis7/{}/meta_bwa/hg19a/*varFilter' 2>/dev/null 来源: https://stackoverflow.com/questions/11087407/xargs-respect-wildcards-in-searches

Got exit code 123 in find + xargs grep

烂漫一生 提交于 2019-12-01 07:29:50
问题 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

xargs respect wildcards in searches

点点圈 提交于 2019-12-01 06:25:35
问题 I have a file called file1.txt: dir1 dir2 dir3 ... I wanted to use xargs to check if some files exist farther into the file system like this: cat file1.txt | xargs -i ls /projects/analysis7/{}/meta_bwa/hg19a/*varFilter 2>/dev/null But xargs never seems smart enough to expand the *. ie, it never finds the files even when they would match the pattern (if the * was expanded). Any ideas? 回答1: You just need to add sh -c : cat file1.txt | xargs -i sh -c 'ls /projects/analysis7/{}/meta_bwa/hg19a/

linux xargs 不同命令中传递参数

爷,独闯天下 提交于 2019-12-01 06:18:16
find . -amin -40 | grep -v "^./\." | grep -v ^.$ | xargs -I {} sudo mv {} ./test/ -a file 从文件中读入作为sdtin -e flag ,注意有的时候可能会是-E,flag必须是一个以空格分隔的标志,当xargs分析到含有flag这个标志的时候就停止。 -p 当每次执行一个argument的时候询问一次用户。 -n num 后面加次数,表示命令在执行的时候一次用的argument的个数,默认是用所有的。 -t 表示先打印命令,然后再执行。 -i 或者是-I,这得看linux支持了,将xargs的每项名称,一般是一行一行赋值给 {},可以用 {} 代替。 -r no-run-if-empty 当xargs的输入为空的时候则停止xargs,不用再去执行了。 -s num 命令行的最大字符数,指的是 xargs 后面那个命令的最大命令行字符数。 -L num 从标准输入一次读取 num 行送给 command 命令。 -l 同 -L。 -d delim 分隔符,默认的xargs分隔符是回车,argument的分隔符是空格,这里修改的是xargs的分隔符。 -x exit的意思,主要是配合-s使用。。 -P 修改最大的进程数,默认是1,为0时候为as many as it can ,这个例子我没有想到

搜索某个目录下所有jar包中的mapper目录下的xml文件

让人想犯罪 __ 提交于 2019-12-01 05:39:56
rm -rf /mapper/* find /data/app/app-*/lib ! -path "*xnpush*" ! -path "*portal*" ! -path "*defendcheck*" ! -path "*bak*" ! -path "*canal*" ! -path "*es*" ! -path "*task*" ! -path "*gold*" ! -path "*deposit*" ! -path "*security*" -name "*-app-*" -print |xargs cp -t /mapper for i in `find /mapper -name "*.jar" | awk -F'/' '{print $NF}' | awk -F '.jar' '{print $(NF-1)}'`;do unzip -o /mapper/$i.jar -d /mapper/$i; done find /mapper -type d \( -name "com" -o -name "cn" -o -name "META-INF" -o -name "remote" \) | xargs rm -rf rm -rf /mapper/*.jar find /mapper -type f -name "*" -print | grep -vE "sqlmap

7-2 文件查找和压缩归档

限于喜欢 提交于 2019-12-01 02:26:52
文件查找和压缩归档 文件查找 locate命令 介绍 查询系统上预建的文件索引数据库 /var/lib/mlocate/mlocate.db 依赖于事先构建的索引 索引的构建是在系统较为空闲时自动进行(周期性任务),管理员手动更新数据库(updatedb) 索引构建过程需要遍历整个根文件系统,极消耗资源 工作特点: 查找速度快 模糊查找 非实时查找 搜索的是文件的全路径,不仅仅是文件名 可能只搜索用户具备读取和执行权限的目录 语法 locate KEYWORD 常用选项 -i 不区分大小写的搜索 -n N 只列举前N个匹配项目 -r 使用基本正则表达式 示例 搜索名称或路径中带有“conf”的文件 locate conf 使用Regex来搜索以“.conf”结尾的文件 locate -r ‘\.conf$’ find命令 介绍 实时查找工具,通过遍历指定路径完成文件查找 工作特点: 查找速度略慢 精确查找 实时查找 可能只搜索用户具备读取和执行权限的目录 语法 find [OPTION]... [查找路径] [查找条件] [处理动作] 查找路径:指定具体目标路径;默认为当前目录 查找条件:指定的查找标准,可以文件名、大小、类型、权限等标准进行; 默认为找出指定路径下的所有文件 处理动作:对符合条件的文件做操作,默认输出至屏幕 查找条件 指定搜索层级: -maxdepth level

Linux Shell 基础知识(二)

落花浮王杯 提交于 2019-12-01 02:21:23
1.本文知识结构 2.文件的查询与检索 2.1. cd 目录切换 找到文件/目录位置:cd 切换到上一个工作目录: cd - 切换到home目录: cd or cd ~ 显示当前路径: pwd 更改当前工作路径为path: $cd path 2.2. locate 查找目录及文件 find 实时查找 locate 为文件系统建立索引数据库,如果有文件更新,需要定期执行更新命令来更新索引库,在查找文件之前要先更新数据库 # 搜寻文件或目录: $find ./ -name "core*" | xargs file # 查找目标文件夹中是否有obj文件: $find ./ -name '*.o' # 递归当前目录及子目录删除所有.o文件 $find ./ -name "*.o" -exec rm {} \; # 寻找包含有string的路径 $updatedb $locate string 2.3. chown 文件与目录权限修改 改变文件的拥有者 chown 改变文件读、写、执行等属性 chmod 递归子目录修改: chown -R tuxapp source/ 增加脚本可执行权限: chmod a+x myscript 2.4. 管道和重定向 批处理命令连接执行,使用 | 串联: 使用分号 ; 前面成功,则执行后面一条,否则,不执行:&& 前面失败,则后一条执行: || 重定向: >