xargs

Linux命令行里的“瑞士军刀”

拈花ヽ惹草 提交于 2020-01-08 21:11:30
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 这里说的“瑞士军刀”是指那些简单的一句命令就能完成其它高级语言一大片代码才能完成的工作。 下面的这些内容是 Quora 网站上Joshua Levy网友的总结: 通过sort/uniq获取文件内容的交集、合集和不同之处:假设有a、b两个文本文件,文件本身已经去除了重复内容。下面是效率最高的方法,可以处理任何体积的文件,甚至几个G的文件。(Sort对内存没有要求,但也许你需要用 -T 参数。)可以试着比较一下,你可以看看如果用Java来处理磁盘上文件的合并,需要用多少行代码。 cat a b | sort | uniq > c # c 是a和b的合集 cat a b | sort | uniq -d > c # c 是a和b的交集 cat a b b | sort | uniq -u > c # c 是a和b的不同 汇总一个文本内容里第三列数字的和(这个方法要比用Python来做快3倍并只需1/3的代码量): awk ‘{ x += $3 } END { print x }’ myfile 如果你想查看一个目录树里的文件的体积和修改日期,用下面的方法,相当于你挨个目录做”ls -l”,而且输出的形式比你用”ls -lR”更可读: find . -type f -ls 使用xargs命令。这个命令非常的强大

xargs input involving spaces

て烟熏妆下的殇ゞ 提交于 2020-01-05 10:07:54
问题 I am working on a Mac using OSX and I'm using bash as my shell. I have a script that goes something to the effect of: VAR1="pass me into parallel please!" VAR2="oh me too, and there's actually a lot of us, but its best we stay here too" printf "%s\n" {0..249} | xargs -0 -P 8 -n 1 . ./parallel.sh I get the error: xargs: .: Permission denied . The purpose is to run a another script in parallel (called parallel.sh) which get's fed the numbers 0-249. Additionally I want to make sure that parallel

An odd behavior of `find`

微笑、不失礼 提交于 2020-01-05 08:23:15
问题 Under my fetch/evs/ , there is no sub-folder, I have a command which is supposed to list all the files of fetch/evs/*.ev which don't contain text ' Error : find . -ipath '*/fetch/evs/*.ev' | xargs grep -L -e "' Error" > try0.txt This command returns 692 files. What is odd is that it ignores a part of files which satisfy the criteria, for instance if I do: find . -ipath '*/fetch/evs/grades*.ev' | xargs grep -L -e "' Error" > try1.txt This command returns 72 files which are not in try0.txt at

【linux系列知识】基础知识

ε祈祈猫儿з 提交于 2020-01-04 13:02:29
基础知识 linux系统特点:安全、稳定、费用低 基本指令:cd、pwd、mkdir、tree、rmdir、rm -r、touch、cat、cp、mv、head/tail 权限表示介绍: 改权限:chmod u-x a.out find:find ./ -type l/xargs ls -l xargs将find命令查找的结果分成若干块输出给后面的指令 find ./ -type f/grep txt grep:过滤 来源: CSDN 作者: 烊萌 链接: https://blog.csdn.net/qq_36417014/article/details/103830036

Change text in argument for xargs (or GNU Parallel)

£可爱£侵袭症+ 提交于 2020-01-04 09:27:10
问题 I have a program that I can run in two ways: single-end or paired-end mode. Here's the syntax: program <output-directory-name> <input1> [input2] Where the output directory and at least one input is required. If I wanted to run this on three files, say, sample A, B, and C, I would use something like find with xargs or parallel: user@host:~/single$ ls sampleA.txt sampleB.txt sampleC.txt user@host:~/single$ find . -name "sample*" | xargs -i echo program {}-out {} program ./sampleA.txt-out .

Change text in argument for xargs (or GNU Parallel)

限于喜欢 提交于 2020-01-04 09:27:03
问题 I have a program that I can run in two ways: single-end or paired-end mode. Here's the syntax: program <output-directory-name> <input1> [input2] Where the output directory and at least one input is required. If I wanted to run this on three files, say, sample A, B, and C, I would use something like find with xargs or parallel: user@host:~/single$ ls sampleA.txt sampleB.txt sampleC.txt user@host:~/single$ find . -name "sample*" | xargs -i echo program {}-out {} program ./sampleA.txt-out .

find with spaces in filename

半世苍凉 提交于 2020-01-04 04:40:12
问题 I often use grep twice with find in order to search for two patterns in a file as follows: find . -name \*.xml | xargs grep -l "<beans" | xargs grep singleton Then I ran into files with spaces which of course broke the above command. I modified it as follows to deal with the spaces: find . -name \*.xml -print0 | xargs -0 grep -l "<beans" | xargs grep singleton The option -print0 tells find to use print null as a separator instead of space and -0 tells xargs to expect a null. This works as

Modifying replace string in xargs

自古美人都是妖i 提交于 2019-12-31 07:57:13
问题 When I am using xargs sometimes I do not need to explicitly use the replacing string: find . -name "*.txt" | xargs rm -rf In other cases, I want to specify the replacing string in order to do things like: find . -name "*.txt" | xargs -I '{}' mv '{}' /foo/'{}'.bar The previous command would move all the text files under the current directory into /foo and it will append the extension bar to all the files. If instead of appending some text to the replace string, I wanted to modify that string

reading in from stdin from a command executed with xargs

久未见 提交于 2019-12-30 18:00:11
问题 Using xargs did something I didn't quite expect, though I guess it sort of makes sense. This is not what I did, but this is an example which should show what happened. fn.sh #!/usr/bin/bash index=1 for arg in "$@"; do echo "Arg #$index = '$arg'"; let ++index; done read -p "type something followed by enter: " a echo "You typed '$a'." Now here is the command: echo boo hoo | xargs ./fn.sh Now what I want is that fn.sh can read from stdin to allow user interaction, but that's been usurped by

Linux 误卸载自带python后的解决办法

好久不见. 提交于 2019-12-27 21:40:35
1:卸载python(以免有些同学没有卸载干净)   rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps #强制删除已安装程序及其关联    whereis python|xargs rm -frv #删除所有残余文件 #xargs,允许你对输出执行其他某些命令 2.卸载yum   rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps    rm -rf /etc/yum.repos.d/*   whereis yum|xargs rm -frv<br> 3.验证是否删除干净   whereis python #验证删除,返回应该是没有结果的<br>whereis yum 4.安装python和yum   一定要选对应自己系统版本的文件!! http://vault.centos.org/,进入网站,选择自己系统对应的版本,进入OS文件夹,选择系统对应的位数,32位选i386,64位选择x86_64,进入Packages文件夹,进去之后你会看到很多rpm文件,下载如下文件:    python-2.6.6-66.el6_8.x86_64.rpm    python-devel-2.6.6-66.el6_8.x86_64.rpm    python-iniparse-0.3