xargs

Can xargs' default delimiter be changed?

荒凉一梦 提交于 2019-12-10 02:39:46
问题 I want the following behavior without having to explicitly specify it with options: xargs -d '\n' Unlike with most commands, you can't just use an alias because pipes don't recognize aliases (as a side-note, why is it designed this way?). I also tried creating my own ~/bin/xargs script but I think it's not as simple as reading "$@" as a string inside the script. Any suggestions how to make the delimiter a newline by default? I don't want to get a bunch of errors when I have a space in the

When to use xargs when piping?

给你一囗甜甜゛ 提交于 2019-12-09 16:23:46
问题 I am new to bash and I am trying to understand the use of xargs , which is still not clear for me. For example: history | grep ls Here I am searching for the command ls in my history. In this command, I did not use xargs and it worked fine. find /etc - name "*.txt" | xargs ls -l I this one, I had to use xargs but I still can not understand the difference and I am not able to decide correctly when to use xargs and when not. 回答1: To answer your question, xargs can be used when you need to take

Alternatives to xargs -l

心不动则不痛 提交于 2019-12-09 16:04:13
问题 I want to rename a bunch of dirs from DIR to DIR.OLD. Ideally I would use the following: find . -maxdepth 1 -type d -name \"*.y\" -mtime +`expr 2 \* 365` -print0 | xargs -0 -r -I file mv file file.old But the machine I want to execute this on has BusyBox installed and the BusyBox xargs doesn't support the "-I" option. What are some common alternative methods for collecting an array of files and then executing on them in a shell script? 回答1: You can use -exec and {} features of the find

How can I avoid “no input files” error from sed, when run from xargs?

时光毁灭记忆、已成空白 提交于 2019-12-08 17:59:08
问题 I have this shell script to update IP addresses in my configuration files (any that match $old_address_pattern must be changed to $new_address ): grep -rl "$old_address_pattern" /etc \ | xargs sed -i "s/$old_address_pattern/$new_address/g" If the grep command finds no matching files, then sed will complain 'no input files'. How can I make this pipeline succeed when the list of files is empty? 回答1: If you want to avoid running sed when grep produces no output, then (since you've tagged this

Search and Replace String from text file Ubuntu

狂风中的少年 提交于 2019-12-08 11:33:26
问题 I have to replace following String //@Config(manifest with below string, @Config(manifest So this i created following regex \/\/@Config\(manifest And tried grep -rl \/\/@Config\(manifest . | xargs sed -i "\/\/@Config\(manifest@Config\(manifest/g" But i am getting following error: sed: -e expression #1, char 38: Unmatched ( or \( I have to search recursively and do this operation, though i am stuck with above error. 回答1: grep -rl '//@Config(manifest' | xargs sed -i 's|//@Config(manifest|

常用Linux命令行技巧

时光怂恿深爱的人放手 提交于 2019-12-08 07:03:59
结果以表格形式输出 column -t 比如; mount | column -t 默认分隔符为空格,如果输出文件是以别的字符进行分割的呢,比如 /etc/passwd 中的冒号,那么,我们可以通过 -s 参数来指定 cat /etc/passwd | column -t -s: 重复执行某个命令直至执行结果成功 while true 按内存使用大小列出进程信息 ps aux | sort -rnk 4 按CPU使用情况列出进程信息 ps aux | sort -nk 3 同时查看多个日志文件 multitail file1.log file2.log 返回之前目录 cd - 调整非交互式Shell为交互式 将设置从 ~/.bashrc 调整为 ~/.bash_profile ,更多请参考 https://blog.csdn.net/kangkanglou/article/details/82698177 Different shell types: interactive, non-interactive, login 定时获取命令输出 watch 命令 watch df -h 会话结束后仍然可正常运行程序命令 nohup 命令忽略所有挂断信号 nohup ping -c 10 www.baidu.com 自动输入Yes或者No 自动输入 yes ,使用 yes 命令 yes |

Format all XML files in a directory and save them in a subdirectory

做~自己de王妃 提交于 2019-12-08 01:50:33
问题 I'm trying to write a script that will look through a directory, find all the XML files, run them through xmllint , and save the formatted results to a file of the same name in a subdirectory called formatted . Here's the script I have so far: find . -maxdepth 1 -type f -iname "*.xml" | xargs -I '{}' xmllint --format '{}' > formatted/'{}' This works, to an extent. The subdirectory ends up with one file, named "{}" , which is just the results of the final file that was processed through

cat/Xargs/command VS for/bash/command

心已入冬 提交于 2019-12-07 07:36:57
问题 The page 38 of the book Linux 101 Hacks suggests: cat url-list.txt | xargs wget –c I usually do: for i in `cat url-list.txt` do wget -c $i done Is there some thing, other than length, where the xargs-technique is superior to the old good for-loop-technique in bash? Added The C source code seems to have only one fork. In contrast, how many forks have the bash-combo? Please, elaborate on the issue. 回答1: From the Rationale section of a UNIX manpage for xargs. (Interestingly this section doesn't

find with xargs and tar

我是研究僧i 提交于 2019-12-06 19:47:43
问题 I have the following I want to do: find . -maxdepth 6 ( -name *.tar.gz -o -name bediskmodel -o -name src -o -name ciao -o -name heasoft -o -name firefly -o -name starlink -o -name Chandra ) -prune -o -print| tar cvf somefile.tar --files-from=- i.e. exclude a whole lot of stuff, only look to 6 subdirs depth, and then once pruning is done, tar up the rest. Not hard. The bit before the pipe (|) works 100%. If I exclude the tar, then I get what I'm after (to the screen). But once I include the

centos7上借助于xargs快速查询并卸载rpm软件

梦想的初衷 提交于 2019-12-06 15:30:28
在centos上卸载某些软件的时候,如果查询的软件包比较多,可以考虑使用xargs,边查询边卸载 如:下面在查询mysql包时候,将查询结果通过管道传送给xargs,然后使用rpm -e --nodeps进行卸载 当然如果你不想使用这种方式,那就直接用yum吧! 来源: https://www.cnblogs.com/cosmos-wong/p/11992940.html