xargs

Redis批量删除缓存数据

一个人想着一个人 提交于 2020-03-02 20:13:00
背景: 在使用redis中,经常会遇到批量删除缓存的情况,但是对于在客户端中,如果一个一个的删除key,则需要较长时间及相对麻烦,可以使用以下命令,批量删除缓存. 本地批量删除KEY: ./redis-cli keys "被删除的KEY的前缀*" | xargs ./redis-cli del 示例代码: 批量删除KEY: 批量删除: ./redis-cli keys a2* | xargs ./redis-cli del 删除之后,只剩下a1的key,所有a2的数据都已经删除了. 远程删除KEY: 先登录其他缓存服务器: ./redis-cli -h 10.27.207.40 -p 6379 设置测试数据的缓存: 批量远程删除: ./redis-cli -h redis所在服务器ip -p 端口 keys "course-*" |xargs ./redis-cli -h redis所在服务器ip -p 端口 del 删除操作:删除成功,删除了9个数据 ./redis-cli -h 10.27.207.40 -p 6379 keys "test10*" |xargs ./redis-cli -h redis-cli -h 10.27.207.40 -p 6379 del 来源: https://www.cnblogs.com/lewisat/p/11155610.html

命令全局删除所有npm模块?

删除回忆录丶 提交于 2020-03-02 18:30:24
是否有删除所有全局npm模块的命令? 如果没有,你有什么建议? #1楼 对于那些使用 Windows的人来说 ,删除所有全局安装的npm包的最简单方法是删除以下内容: C:\\Users\\username\\AppData\\Roaming\\npm 您可以通过键入 %appdata% (在资源管理器,运行提示或开始菜单中)快速到达此处。 #2楼 使用此代码卸载任何包: npm rm -g <package_name> #3楼 我试过 凯斯特纳德 的解决方案, 但对我来说似乎并不完美。 在deps树本身的最后一个 awk 之后留下了很多特殊符号。 所以,我想出了自己对 Kai Sternad 解决方案的修改(从 羊绒的想法中 得到一点帮助): npm ls -gp --depth=0 | awk -F/node_modules/ '{print $2}' | grep -vE '^(npm|)$' | xargs -r npm -g rm npm ls -gp --depth=0 以 可分析的 格式列出所有全局安装的npm模块: /home/leonid/local/lib /home/leonid/local/lib/node_modules/bower /home/leonid/local/lib/node_modules/coffee-script ... awk -F

[100]第三波常用命令

梦想的初衷 提交于 2020-03-02 08:19:29
用到的时候措手不及,不用的时候一大坨. 基于这个原因,打算重整旗鼓,经常用到的命令和栗子整理如下 像是割草一样,我不信搞不彻底.搞不顺手. find+xargs/sed&sed后向引用+awk多匹配符+过滤行绝招总结&&产生随机数 sort-uniq awk运算-解决企业统计pv/ip问题 1.mkdir 2.ls -l -d 显示目录 -F 给文件夹结尾加/标识 -a 以.开头的都是隐藏文件 -rt 按照修改时间倒序排列(最新修改的在最下) ls -lrth 3.cd 4.pwd 5.touch 6.vi 7.vim 8.echo 配合 > >> -n 不换行 -e 内容携带转义(\n回车 \t tab) - 不换行 [root@n6 ~]# echo -n '123' 123[root@n6 ~]# - 让\n等转义 默认是: [root@n6 ~]# echo 'mao\ntai' mao\ntai 加-e后 [root@n6 ~]# echo -e 'mao\ntai' mao tai 9.cat -n 显示行号 10.xargs: http://man.linuxde.net/xargs -n max-args 多少个一组,默认是1 -i [replace-str] 后向引用 - 用法展示 echo stu{1..20}|xargs -n 2 > 2.md - 单行输出

linux基础命令二

爱⌒轻易说出口 提交于 2020-03-02 06:44:15
一、grep grep:过滤 参数-v 排除 grep -v old aaa.txt 在aaa.txt中排除old字符串所在的行 grep old aaa.txt 只显示包含old的行 -E 参数,可过滤多个字符串,用""括起来,用|分隔开 。等同于egrep grep -E "d|e" 1.txt 将文件中的d和e所在的行显示出来,等同于egrep "d|e" 1.txt grep -Ev "d|e" 1.txt 将文件中的d和e所在的行不显示,-v过滤掉 二、head、tail head -n 文件 :显示文件的前n行 tail -n 文件 : 显示文件的后n行 head和tail两个命令,如果不加-n参数则默认显示前10行或后10行 三、三剑客sed\awk\grep sed:取各种内容、按行处理 sed /old/p aaa.txt 将包含old的内容打印出来,同时整个文件的内容打印一遍。其中p表示打印 sed -n /old/p aaa.txt 将包含old的行打印出来,同时过滤掉原始内容,即只打印要查询的,等同与grep old aaa.txt sed /old/d aaa.txt 将包含old的行删除(假删除),其他内容打印。d参数时删除的意思,等同于grep -v old aaa.txt 总结:-n表示取消默认输出 p打印 d删除 sed -n 20,30p aaa

xargs rm -rf 与 -exec rm

 ̄綄美尐妖づ 提交于 2020-03-01 13:34:17
# find ./ -exec rm {} \; # find ./ | xargs rm -rf 两者都可以把find命令查找到的结果删除,其区别简单的说是前者是把find发现的结果一次性传给exec选项,这样当文件数量较多的时候,就可能会出现“参数太多”之类的错误,相比较而言,后者就可以避免这个错误,因为xargs命令会分批次的处理结果。这样看来,“find ./| xargs rm -rf”是更通用的方法,推荐使用! rm不接受标准输入,所以不能用find / -name "*.txt" |rm -exec 必须由一个 ; 结束,而因为通常 shell 都会对 ; 进行处理,所以用 \; 防止这种情况。 {} 可能需要写做 '{}',也是为了避免被 shell 过滤 find ./ -type f -exec grep txt {} /dev/null \; ./表示从当前目录找 -type f,表示只找file,文件类型的,目录和其他字节啥的不要 -exec 把find到的文件名作为参数传递给后面的命令行,代替{}的部分 -exec后便跟的命令行,必须用“ \;”结束 # find ./ -type f -name "*.txt"|xargs grep "test" -n # find . -name "*.txt" -exec grep "test" {} \;

Linux常用命令--xargs

耗尽温柔 提交于 2020-02-29 02:13:22
我们可以用管道将一个命令的stdout(标准输出)重定向到另一个命令的stdin(标准输入),如: $ cat foo.txt | grep "test" 解析:查看foo.txt文件并打印出含有test的行。 但是有些命令只能以命令行参数的形式接受数据,而无法通过stdin接受数据流。在这种情况下,我们没法用管道来提供哪些只有通过命令行参数才能提供的数据。 那现在就该xargs上场了,它擅长将标准输入数据转换成命令行参数。 预备知识: xargs命令应该紧跟在管道操作符之后,以标准输入作为主要的源数据流,它使用stdin并通过提供命令行参数来执行其他命令。xargs命令把从stdin接收到的数据重新格式化,再将其作为参数提供给其他命令。 一、将多行输入转换成单行输出 $ cat foo.txt # 样例文件 1 2 3 3 4 5 7 8 9 10 11 12 $ cat foo.txt | xargs 1 2 3 4 5 6 7 8 9 10 11 12 二、 将单行输入转换为多行输出 $ cat foo.txt | xargs -n 3 1 2 3 4 5 6 7 8 9 10 11 12 解析:指定每行最大的参数数量n,将任何来自stdin的文本划分成多行,每行n个参数。 xargs默认的定界符是空格,我们自己可以来设置定界符,用-d选项为输入指定一个定制的定界符。 $

xargs -i参数详解

眉间皱痕 提交于 2020-02-28 17:26:41
学习所需,文章转载过来! xargs与find经常结合来进行文件操作,平时删日志的时候只是习惯的去删除,比如 # find . -type f -name "*.log" | xargs rm -rf * 就将以log结尾的文件删除了,如果我想去移动或者复制就需要使用参数来代替了。 xargs -i 参数或者-I参数配合{}即可进行文件的操作。 -I replace-str 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. Implies -x and -L 1. --replace[=replace-str], -i[replace-str] This option is a synonym for -Ireplace-str if replace-str is specified, and for -I{} otherwise. This option is deprecated; use -I instead. man了一下看的还是不太懂

Get argument from pipe

假如想象 提交于 2020-02-27 05:30:51
问题 Consider having the results from the pipe: find . Now I would like to access in the second command behind the pipe what is actually piped (inputed) and then for example to print it twice. find . | printf $arg$arg\n #each filename would be printed twice per line Please note that the question is not asking about printing whatever once gets from pipe twice, I know how to use bash for loop or write a script that could accomplish the mentioned. How I can get $arg to use it quickly in inline

Get argument from pipe

不打扰是莪最后的温柔 提交于 2020-02-27 05:30:47
问题 Consider having the results from the pipe: find . Now I would like to access in the second command behind the pipe what is actually piped (inputed) and then for example to print it twice. find . | printf $arg$arg\n #each filename would be printed twice per line Please note that the question is not asking about printing whatever once gets from pipe twice, I know how to use bash for loop or write a script that could accomplish the mentioned. How I can get $arg to use it quickly in inline

linux中xargs命令的使用方式

回眸只為那壹抹淺笑 提交于 2020-02-27 01:58:55
xargs 是给 命令 传递参数的一个过滤器,可以将管道或标准输入的数据转换成参数,默认的 命令 是 echo,这意味着通过管道传递给 xargs 的输入将会包含换行,不过通过 xargs 的处理,换行将被空格取代。 如何使用xargs命令 语法: xargs [OPTIONS] [COMMAND [initial-arguments]] 举一个例子:我们用管道符传输到xargs,并为每个参数运行touch命令, -t 表示在执行之前先打印,创建三个文件: [root@localhost ~]# echo "file1 file2 file3"|xargs -t touch touch file1 file2 file3 如何限制参数的数量 默认情况下,传递给命令的参数数量由系统限制决定。 -n 选项指定要传递给命令的参数个数。xargs根据需要多次运行指定的命令,直到所有参数都用完为止。 下面例子指定每次传递一个参数: [root@localhost ~]# echo "file1 file2 file3"|xargs -n1 -t touch touch file1 touch file2 touch file3 如何运行多个命令 要使用xargs运行多个命令,请使用 -i 或者 -I 选项。在 -i 或者 -I 后面自定义一个传递参数符号