xargs

Linux学习之路-locate、find、xargs、压缩工具、tar【4】---20171203

拟墨画扇 提交于 2020-04-02 11:21:11
locate 非实时查找,效率非常高 查询系统上预建的文件索引数据库 /var/lib/mlocate/mlocate.db ----->查找的数据库 ``[root@Centos6app]#ll /var/lib/mlocate/mlocate.db -h -rw-r-----. 1 root slocate 3.0M 12月 1 03:20 /var/lib/mlocate/mlocate.db 依赖于事先构建的索引 索引的构建是在系统较为空闲时自动进行(周期性任务),管理员手动更新数据库(updatedb) br/>[root@Centos6app]#updatedb [root@Centos6app]#ll /var/lib/mlocate/mlocate.db -h -rw-r-----. 1 root slocate 3.0M 12月 1 18:13 /var/lib/mlocate/mlocate.db 索引构建过程需要遍历整个根文件系统,极消耗资源 工作特点: •查找速度快 •模糊查找 •非实时查找 •搜索的是文件的全路径,不仅仅是文件名 •可能只搜索用户具备读取和执行权限的目录 locate KEYWORD 有用的选项 -i 不区分大小写的搜索 -n N 只列举前N个匹配项目 -r 使用正则表达式 搜索名称或路径中带有“conf”的文件 locate conf

linux 基础命令应用

我怕爱的太早我们不能终老 提交于 2020-03-31 19:52:09
Linux操作系统 ==================== desktop模式 #配置ip,网关# setup 网络配置--设备配置--DHCP--【*】按空格键改为【 】--在下面配置ip、子网掩码、网关、DNS =====记得要保存再退出哦! 启动网卡配置文件 ifup eth0 ifconfig 查看ip地址是否配置成功 重启reboot后需要再次启动配置文件 ifup eth0 =============================================================== Linux下删除yunjisuan目录所有文件,但只保留一个“7”不删 【3种方法】 find find yunjisuan - type "f" !- name "7" | xargs rm -rf grep ls | grep -v "7" | xargs rm -rf 嵌套 rm -rf ` ls | grep -v "7"` =============================================================== 已知test文件, 去掉第五行内容后,输出结果 【4种方法】 head/tail head -4 test && tail -45 test grep cat test | grep -v "5" sed sed '

Linux命令find讲解

北城以北 提交于 2020-03-27 18:42:37
3 月,跳不动了?>>> 感谢参考原文- http://bjbsair.com/2020-03-27/tech-info/7096/ find 命令概览 Linux下find命令在目录结构中搜索文件,并执行指定的操作。Linux下find命令提供了相当多的查找条件,功能很强大。由于find具有强大的功能,所以它的选项也很多,其中大部分选项都值得我们花时间来了解一下。即使系统中含有网络文件系统( NFS),find命令在该文件系统中同样有效,只你具有相应的权限。 在运行一个非常消耗资源的find命令时,很多人都倾向于把它放在后台执行,因为遍历一个大的文件系统可能会花费很长的时间(这里是指30G字节以上的文件系统)。 1.命令格式: find pathname -options [-print -exec -ok ...] 2.命令功能: 用于在文件树种查找文件,并作出相应的处理 3.命令参数: pathname: find命令所查找的目录路径。例如用.来表示当前目录,用/来表示系统根目录。 -print:find命令将匹配的文件输出到标准输出。 -exec:find命令对匹配的文件执行该参数所给出的shell命令。相应命令的形式为'command' { } ;,注意{ }和\;之间的空格。 -ok: 和-exec的作用相同,只不过以一种更为安全的模式来执行该参数所给出的shell命令

shell之xargs与-exec与管道的区别你造吗?

江枫思渺然 提交于 2020-03-21 21:23:40
3 月,跳不动了?>>> 1、xargs作用: (1)将前一个命令的标准输出传递给下一个命令,作为它的参数,xargs的默认命令是echo,空格是默认定界符 (2)将多行输入转换为单行 2、使用模式: front command | xargs -option latercommand front command: 前一个命令 -option: xargs的选项 later command: 后一个命令 一般与管道“|”结合使用 3、xargs常用选项 -n: 指定一次处理的参数个数 -d: 自定义参数界定符 -p: 询问是否运行 later command 参数 -t : 表示先打印命令,然后再执行 -i : 逐项处理 ...更多参数查看man xargs 4、xargs与管道|的区别 管道“|” 用来将前一个命令的标准输出传递到下一个命令的标准输入。 xargs 将前一个命令的标准输出传递给下一个命令,作为它的参数。 可见,标准输入与命令参数是不同的。个人理解,命令参数就是直接跟在命令后面的,标准输入可以是键盘,文件等。 所以,管道符 | 所传递给程序的不是简单地在程序名后面输入的参数,它们会被程序内部的读取功能如scanf和gets等接收,而xargs则是将内容作为普通的参数传递给程序,相当于直接跟在命令后面。况且,有些命令是不接受标准输入的,比如kill,rm等命令。 总结

xargs的i参数

ぐ巨炮叔叔 提交于 2020-03-18 14:39:38
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了一下看的还是不太懂,通过例子

Linux下完全重装python和yum

生来就可爱ヽ(ⅴ<●) 提交于 2020-03-17 10:19:24
转自: https://www.cnblogs.com/wangjunjiehome/p/9239005.html                                   完全重装python和yum 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 1、删除现有Python [root@ test ~] # rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps ##强制删除已安装程序及其关联 [root@ test ~] # whereis python |xargs rm -frv ##删除所有残余文件 ##xargs,允许你对输出执行其他某些命令 [root@ test ~] # whereis python ##验证删除,返回无结果 2、删除现有的yum [root@ test ~] # rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps [root@ test ~] # whereis yum |xargs rm -frv 3、从http: //mirrors .ustc.edu.cn /centos/6 .4 /os/x86_64/Packages/

定期清空日志文件,不删除文件

放肆的年华 提交于 2020-03-17 08:03:42
一.背景 Linux服务器上,程序运行一段时间后,日志可能占满了磁盘,导致磁盘可用空间告警,这时就需要批量清空(非删除)日志文件 二.错误做法 一般可能会写个批量删除的脚本,定时去运行,形如: #!/bin/bash # 查看/opt目录下,所有日志文件及大小 find /opt -name *.log | xargs du -sh # 删除/opt目录下所有的日志文件 find /opt -name *.log | xargs rm -rf 上面的命令可以完成删除的效果,但会引入一些问题,因为日志文件可能此时正在被程序使用,直接删除后,导致程序日志无法写入(删除后无法自动创建),必须重启服务后才能自动创建日志文件并再次写入。 这也正是我们查看日志时提示日志文件不存在,但系统进程存在而且系统可正常使用的原因所在。 三.正确做法 正确的做法是: 1. 删除非当天的日志文件;(一般程序日志会配置日切,每日一个文件) 2. 清空当天的日志文件; #!/bin/bash # 查看/opt目录下,所有【非当天】的日志文件及大小 find /opt -name *.log.* | xargs du -sh # 删除/opt目录下所有【非当天】的日志文件 find /opt -name *.log.* | xargs rm -rf # 查看/opt目录下,所有【当天】日志文件及大小 find

Getting error “xargs unterminated quote” when tried to print the number of lines in terminal

谁都会走 提交于 2020-03-17 04:04:24
问题 I want to get the number of lines in my application. I am using this code: find . "(" -name "*.m" -or -name "*.h" ")" -print | xargs wc -l It is working fine in other applications but for one of my applications it is giving the error "xargs unterminated quote". 回答1: Does one of your filenames have a quote in it? Try something like this: find . "(" -name "*.m" -or -name "*.h" ")" -print0 | xargs -0 wc -l The -print0 argument tells find to use the NULL character to terminate each name that it

Getting error “xargs unterminated quote” when tried to print the number of lines in terminal

你离开我真会死。 提交于 2020-03-17 04:03:27
问题 I want to get the number of lines in my application. I am using this code: find . "(" -name "*.m" -or -name "*.h" ")" -print | xargs wc -l It is working fine in other applications but for one of my applications it is giving the error "xargs unterminated quote". 回答1: Does one of your filenames have a quote in it? Try something like this: find . "(" -name "*.m" -or -name "*.h" ")" -print0 | xargs -0 wc -l The -print0 argument tells find to use the NULL character to terminate each name that it

xargs命令

妖精的绣舞 提交于 2020-03-14 15:43:08
  xargs命令,常配合管道将前面命令的输出结果转换成后面命令的参数,默认命令是echo。常配合find命令使用。   语法:     xargs [option]... command   常用选项:     -a file:从一个文件中读取数据,而非stdin;     -i:用{}来代替传递的参数,相当于-I{};     -n max-args:限制每次传输的最大参数个数;     -d delim:指定每个参数分割符,默认是空格和换行;     -p:交互式,每次执行命令都询问用户是否执行;     -t:将执行的命令通过标准错误输出打印出来;     -I replace-str:设置传递参数的替换字符; 实例:     查找/var/log文件夹下所有已“.log”结尾的文件,并复制到/tmp目录下。      来源: https://www.cnblogs.com/Stong/p/6817645.html