xargs:将输入数据重新格式化后输出
简介xargs命令是给其他命令传递参数的一个过滤器,也是组合多个命令的一个工具。能将标准输出或管道的数据转换成xargs命令后其他命令的命令参数。 xargs也可以将单行或多行文本输入转换为其他格式,例如多行变单行,单行变多行。 xargs的默认命令是echo,空格是默认定界符。
说明
xargs命令是给其他命令传递参数的一个过滤器,也是组合多个命令的一个工具。能将标准输出或管道的数据转换成xargs命令后其他命令的命令参数。
xargs也可以将单行或多行文本输入转换为其他格式,例如多行变单行,单行变多行。
xargs的默认命令是echo,空格是默认定界符。
格式
xargs [option]
参数说明:
- -n:指定每行显示的数量
- -d:自定义分隔符
- -i:以{}代替前面的结果,这个使用最多
- -I:自定义一个符号来代替前面的结果,而不用-i的{}来代替
- -0:用null代替空格作为分隔符,配合find命令的-print0来一起使用,这个需要解决文件名中有空格
示例
多行文本边单行文本
[root@localhost test]# vim test.txt
[root@localhost test]# cat test.txt
a b c d e
f g h i j
k
l
m n o p
[root@localhost test]# cat test.txt | xargs #使用管道
a b c d e f g h i j k l m n o p
[root@localhost test]# xargs < test.txt #直接从文件从读取
a b c d e f g h i j k l m n o p
使用-n来指定每行显示的个数(默认以空格分隔)
[root@localhost test]# cat test.txt | xargs -n 3
a b c
d e f
g h i
j k l
m n o
p
[root@localhost test]# xargs -n 3 < test.txt
a b c
d e f
g h i
j k l
m n o
p
使用-d来指定分隔符
[root@localhost test]# echo "php|python|go|java"
php|python|go|java
[root@localhost test]# echo "php|python|go|java"|xargs -d "|"
php python go java
[root@localhost test]# echo "php|python|go|java"|xargs -d "|" -n 1 #也是将单行变成多行
php
python
go
java
使用-i参数
[root@localhost test]# find . -name "test*.txt"|xargs -i mv {} dir1/
[root@localhost test]# ll
total 4
drwxr-xr-x. 2 root root 4096 May 6 02:32 dir1
[root@localhost test]# ls dir1/
test01.txt test02.txt test03.txt test04.txt test05.txt test06.txt test07.txt test08.txt test09.txt test10.txt test.txt
-I参数的使用
[root@localhost test]# find dir1/ -name "test*.txt"|xargs -I [] mv [] .
[root@localhost test]# ls
dir1 test01.txt test02.txt test03.txt test04.txt test05.txt test06.txt test07.txt test08.txt test09.txt test10.txt test.txt
[root@localhost test]# ls dir1/
[root@localhost test]#
-0参数的使用
[root@localhost test]# touch test\ new.txt
[root@localhost test]# find . -name "test*.txt"|xargs rm
rm: cannot remove ‘./test’: No such file or directory
rm: cannot remove ‘new.txt’: No such file or directory
必须使用下面的命令才有用
[root@localhost test]# find . -name "test*.txt" -print0|xargs -0 rm
无向图(Undirected Graph)
《血色湘西》瞿先生临死前的独白,振奋人心。
Python调用WPS把文档转换PDF,并把PDF转图片,首先需要安装WPS,然后利用pypiwin32把文档转化成PDF,再利用fitz、PyMuPD把PDF转化成图片
GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的web服务。
本文主要整理工作中常用的Docker命令,以便后期进行查找使用。
快速生成表格
Electron页面跳转、浏览器打开链接和打开新窗口
Docker编译镜像出现:fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.12/main: temporary error (try again later)
WARNING: Ignoring APKINDEX.2c4ac24e.tar.gz: No such file or directory问题
在使用Git的过程中,不想每次都输入用户名和密码去拉取代码,所以就需要保存这些信息,那么既然有保存了,就必须有清除功能。
在Mac电脑中,如何对Git的用户名和密码进行修改呢?起初不懂Mac,所以整了很久,本文将记录如何对这个进行操作,以便后期使用。