xargs

XARGS Long Arguments and Pause Between Commands

半城伤御伤魂 提交于 2019-12-06 14:03:45
问题 Xargs will execute command more than once automatically if the command arguments are too long. I am currently retrieving the revision differences in git and passing those arguments to git archive through xargs. It happens that the revision differences are long hence xargs automatically split the command into two times. Because of that, git archive done twice for the same archive that leads to whatever being archived by the first command is wiped out by the second command. Is there any way to

Linux下杀掉所有得java进程

≡放荡痞女 提交于 2019-12-06 12:18:19
--转自 https://blog.csdn.net/oppo62258801/article/details/81434038 1.Linux查看所有Java进程 ps -ef | grep java | grep -v grep (是在列出的进程中去除含有关键字"grep"的进程) 2. 使用awk分割结果,获取PID awk '{print $2}' ps -ef | grep java | grep -v grep | awk '{print $2}' 3. 杀死进程 kill -9 PID xargs 作用是将参数列表转换成小块分段传递给其他命令,以避免参数列表过长的问题 ps -ef | grep java | grep -v grep | awk '{print $2}' | xargs kill -9 具体xargs的用法请查看https://blog.csdn.net/u011517841/article/details/53196380 4.是用jar包运行的进程,需要kill掉的话 jps -l | grep 'test.jar' | grep -v grep | awk '{print $1}' | xargs kill -9 5.有时发现jar运行的进程杀不死,很可能是僵尸进程,需要把父进程杀掉 cat /proc/$(jps | grep 'jar' |

xargs原理及用法详解

不羁岁月 提交于 2019-12-06 10:27:20
为什么需要xargs                     管道实现的是将前面的stdout作为后面的stdin,但是有些命令不接受管道的传递方式,最常见的就是ls命令。有些时候命令希望管道传递的是参数,但是直接用管道有时无法传递到命令的参数位,这时候需要xargs,xargs实现的是将管道传输过来的stdin进行处理然后传递到命令的参数位上。 也就是说xargs完成了两个行为:处理管道传输过来的stdin;将处理后的传递到正确的位置上。 可以试试运行下面的几条命令,应该能很好理解xargs的作用了: [root@node2 scprits]# echo "/etc/inittab" | cat /etc/inittab [root@node2 scprits]# echo "/etc/inittab" | xargs cat # inittab is no longer used when using systemd. # # ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM. # # Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target # # systemd uses 'targets' instead of

Linux/Cygwin recursively copy file change extension [closed]

余生长醉 提交于 2019-12-06 09:58:34
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I'm looking for a way to recursively find files with extension X ( .js) and make a copy of the file in the same directory with extension Y ( .ts). e.g. /foo/bar/foobar.js --> /foo/bar/foobar.js and /foo/bar/foobar.ts /foo/bar.js --> /foo/bar.js and /foo/bar.ts etc etc My due diligence: I was thinking of using

Is Python 'sys.argv' limited in the maximum number of arguments?

社会主义新天地 提交于 2019-12-06 07:05:36
问题 I have a Python script that needs to process a large number of files. To get around Linux's relatively small limit on the number of arguments that can be passed to a command, I am using find -print0 with xargs -0 . I know another option would be to use Python's glob module, but that won't help when I have a more advanced find command, looking for modification times, etc. When running my script on a large number of files, Python only accepts a subset of the arguments, a limitation I first

linux 下删除指定文件之外的其他文件

别说谁变了你拦得住时间么 提交于 2019-12-06 06:57:47
一、 Linux 下删除文件和文件夹常用命令如下: 删除文件: rm file 删除文件夹: rm -rf dir 需要注意的是, rmdir 只能够删除 空文件夹。 二、删除制定文件(夹)之外的所有文件呢? 1 、方法 1 ,比较麻烦的做法是: 复制需要保留的文件到其他文件夹,然后将该目录删除, 然后将需要保留的移动 回来。 mv keep ../ # 保留文件(夹) keep rm -rf * # 删除当前文件夹里的所有文件 mv ../keep ./ # 将原来的东西移动回来 2 、方法 2 ,需要在当前文件夹中进行 : rm -rf !(keep) # 删除 keep 文件之外的所有文件 rm -rf !(keep1 | keep2) # 删除 keep1 和 keep2 文件之外的所有文件 3 、方法 3 ,当前文件夹中结合使用 grep 和 xargs 来处理文件名: ls | grep -v keep | xargs rm # 删除 keep 文件之外的所有文件 说明: ls 先得到当前的所有文件和文件夹的名字, grep -v keep ,进行 grep 正则匹配查找 keep , -v 参数决定了结果为匹配之外的结果,也就是的到了 keep 之外的所有文件名,然后 xargs 用于从 标准输入获得参数 并且传递给后面的命令,这里使用的命令是 rm ,然后由 rm

Run a specifiable number of commands in parallel - contrasting xargs -P, GNU parallel, and “moreutils” parallel

前提是你 提交于 2019-12-06 04:14:43
问题 I'm trying to run multiple mongodump's on 26 servers in a bash script. I can run 3 commands like mongodump -h staging .... & mongodump -h production .... & mongodump -h web ... & at the same time, and when one finishes I want to start another mongodump. I can't run all 26 mongodumps commands at the same time, the server will run out on CPU. Max 3 mongodumps at the same time. 回答1: You can use xarg 's -P option to run a specifiable number of invocations in parallel : Note that the -P option is

xargs command length limits

扶醉桌前 提交于 2019-12-06 04:10:41
问题 I am using jsonlint to lint a bunch of files in a directory (recursively). I wrote the following command: find ./config/pages -name '*.json' -print0 | xargs -0I % sh -c 'echo Linting: %; jsonlint -V ./config/schema.json -q %;' It works for most files but some files I get the following error: Linting: ./LONG_FILE_NAME.json fs.js:500 return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode); ^ Error: ENOENT, no such file or directory '%' It appears to fail for long filenames.

xargs and find, rm complaining about \n (newline) in filename

左心房为你撑大大i 提交于 2019-12-06 03:36:15
问题 I am trying to delete the oldest file in a tree with a script in Debian. find /home/backups -type f \( -name \*.tgz -o -name \*.gz \) -print0 | xargs -0 ls -t | tail -1 | xargs -0 rm But I am getting an error: rm: cannot remove `/home/backups/tree/structure/file.2011-12-08_03-01-01.sql.gz\n': No such file or directory Any ideas what I am doing wrong (or is there an easier/better way?), I have tried to RTFM, but am lost. 回答1: The ls appends a newline and the last xargs -0 says the newline is

linux笔记

点点圈 提交于 2019-12-06 01:04:53
目录 命令 linux相关命令、配置。 参考文献: 命令 字符编码转换 iconv命令 iconv命令 是用来转换文件的编码方式的 # 语法 iconv -f encoding [-t encoding] [inputfile]... # 选项 -f encoding :把字符从encoding编码开始转换。 -t encoding :把字符转换到encoding编码。 -l :列出已知的编码字符集合 -o file :指定输出文件 -c :忽略输出的非法字符 -s :禁止警告信息,但不是错误信息 --verbose :显示进度信息 -f和-t所能指定的合法字符在-l选项的命令里面都列出来了。 # 列出当前支持的字符编码: iconv -l # 将文件file1转码,转后文件输出到fil2中: iconv file1 -f EUC-JP-MS -t UTF-8 -o file2 rm与管道使用 linux shell: rm 、ls、grep 关于 find grep xargs 命令总结 find、xargs、grep基本用法 ls 与 grep 结合 ls -l | grep ^d # 列出当前路径下的所有文件夹 rm -fr `ls | grep -v "^space.txt$"` # greo正则,ls、rm结合 find、xargs、grep配合使用