xargs标准输出作为参数 给命令 echo file{1..10}| xargs touch

xargs标准输出作为参数 给命令

echo file{1..10}| xargs touch

file1 ...file10 作为文件名 被xargs 一个一个传给 touch

echo {1..10} |xargs -n 2 echo

配置 1 2 之后就换行

[07:29:04 [email protected] /]$echo {1..10} | xargs -n 2 echo

1 2
3 4
5 6
7 8
9 10

[07:30:11 [email protected] /]$echo {1..10} | xargs -n 1 echo --加 "-n" 制定几个数值作为参数 这里执行 一个数字为 参数

1
2
3
4
5
6
7
8
9
10
[07:30:29 [email protected] /]$

[07:38:38 [email protected] /]$ll /home
total 4
drwx------. 3 test test 78 Feb 17 01:05 test
drwx------. 3 zhong1 zhong1 78 Feb 17 07:35 zhong1
drwx------. 3 zhong10 zhong10 78 Feb 17 07:35 zhong10
drwx------. 3 zhong2 zhong2 78 Feb 17 07:35 zhong2
drwx------. 3 zhong3 zhong3 78 Feb 17 07:35 zhong3
drwx------. 3 zhong4 zhong4 78 Feb 17 07:35 zhong4
drwx------. 3 zhong5 zhong5 78 Feb 17 07:35 zhong5
drwx------. 3 zhong6 zhong6 78 Feb 17 07:35 zhong6
drwx------. 3 zhong7 zhong7 78 Feb 17 07:35 zhong7
drwx------. 3 zhong8 zhong8 78 Feb 17 07:35 zhong8
drwx------. 3 zhong9 zhong9 78 Feb 17 07:35 zhong9
drwx------. 15 zhonghua zhonghua 4096 Feb 16 16:25 zhonghua

[07:38:46 [email protected] /]$echo zhong{1..10}| xargs -n 1 userdel -r ---删除用户及家目录

find /etc -perm /700 | xargs ls -l /etc下文件所有者具备读或写或执行的权限 文件作为参数传给 ls -l

[10:05:38 [email protected] test1]$ls

2}.txt fb.txt fd.txt fg.txt fj.txt fm.txt fp.txt fs.txt fv.txt fy.txt
fa.txt f c.txt fe.txt fh.txt fk.txt fn.txt fq.txt ft.txt fw.txt fz.txt
f{a..z fc.txt ff.txt fi.txt fl.txt fo.txt fr.txt fu.txt fx.txt
[10:05:48 [email protected] test1]$find -name "f.txt" -print0 |xargs -0 rm ---print0 以16进制0为分隔符 ;Xargs -0 (告知指定参数 0 为分隔符)
[10:06:22 [email protected] test1]$ll
total 0
-rw-r--r--. 1 root root 0 Feb 17 10:04 2}.txt
-rw-r--r--. 1 root root 0 Feb 17 10:04 f{a..z
[10:06:24 [email protected] test1]$

find /tmp -ctime +3 -user zhonghua -ok rm {} \; 查找zhonghua 三天以上的文件并删除 --需要手动确认

find /tmp -ctime +3 -user zhonghua -exec rm {} \; 不进攻确认直接删除

find ~ -perm -002 -exec chmod o-w {} \; --在主目录寻找可被其他用户写入的文件 并删除other写入权限

find /home -type d -ls 查看home目录的目录

原文地址:https://blog.51cto.com/12246080/2472109

时间: 2024-08-29 23:16:36

xargs标准输出作为参数 给命令 echo file{1..10}| xargs touch的相关文章

[服务器]脚本:批处理带参数ping命令 发送邮件脚本

1.批处理带参数ping命令 @echo offecho Input you IP address ......set /p IP=echo Your IP number is %IP%.ping %IP%set IP=pause 2.发送告警脚本 For counter = 1 To 3 Step 1SendMailNext Public Sub SendMailNameSpace = "http://schemas.microsoft.com/cdo/configuration/"

Linux命令find及exec、xargs的使用

由于f i n d具有强大的功能,所以它的选项也很多,其中大部分选项都值得我们花时间来了解一下.即使系统中含有网络文件系统( N F S ),f i n d命令在该文件系统中同样有效,只要你具有相应的权限. F i n d命令的一般形式为:find pathname -options [-print -exec -ok] 该命令的参数:pathname:  find命令所查找的目录路径.例如用.来表示当前目录,用/来表示系统根目录.-print:find命令将匹配的文件输出到标准输出.-exec

Linux常用命令(二十) - find之xargs

在使用 find命令的-exec选项处理匹配到的文件时, find命令将所有匹配到的文件一起传递给exec执行.但有些系统对能够传递给exec的命令长度有限制,这样在find命令运行几分钟之后,就会出现溢出错误.错误信息通常是"参数列太长"或"参数列溢出".这就是xargs命令的用处所在,特别是与find命令一起使用. find命令把匹配到的文件传递给xargs命令,而xargs命令每次只获取一部分文件而不是全部,不像-exec选项那样.这样它可以先处理最先获取的一

find命令处理之exec与xargs区别

对符合条件的文件执行所给的Linux 命令,而不询问用户是否需要执行该命令.{}表示命令的参数即为所找到的文件,以:表示comman命令的结束.\是转义符,因为分号在命令中还有它用途,所以就用一个\来限定表示这是一个分号而不是表示其它意思. -ok: 和-exec的作用相同,格式也一样,只不过以一种更为安全的模式来执行该参数所给出的shell给出的这个命令之前,都会给出提示,让用户来确定是否执行. xargs 要结合管道来完成 格式:find [option] express |xargs co

xargs、sort、uniq命令

xargs.sort.uniq命令,我们由LeetCode的一道题来引入,并使用加以理解: 题目是这样的:写一个 bash 脚本以统计一个文本文件 words.txt 中每个单词出现的频率. words.txt的内容为: the day is sunny the the the sunny is is 1.cat words.txt | sort 来看下会是什么效果 [[email protected] tmp]# cat words.txt | sort the day is sunny th

xargs的- n1参数

起因在对一堆*.tar.gz文件解压缩时,发现tar xvfz *.tar.gz不管用,一查,原来是tar xvfz *.tar.gz会被shell给拆成tar xvfz a.tar.gz b.tar.gz c.tar.gz,而在a.tar.gz中不存在b.tar.gz,当然会报错. 解决方法是使用脚本,写法很多,其中一种是:  for i in $(ls *.tar);do tar xvf $i;done或:for tar in *.tar.gz; do tar tvfz $tar;done

Linux命令echo -e

在Linux命令中 echo -e 这个参数e是什么意思. echo –e “I will use ‘touch’ command to create 3 files.” 这里参数e的作用是什么 man帮助的解释是,允许后面的输出进行转义,假设你是 echo -e "i will use \n $HOME" 输出的将是 i will use /root(当前用户的主目录) 如果是 echo "i will use \n $HOME" 则输出是: i will use

【转载】gcc 使用中常用的参数及命令

本文转载自:http://www.cnblogs.com/yaozhongxiao/archive/2012/03/16/2400473.html 如需转载,请注明原始出处.谢谢. ---------------------------------------------------------------------------------------- gcc 使用中常用的参数及命令 1.  执行过程 虽然我们称Gcc是C语言的编译器,但使用gcc由C语言源代码文件生成可执行文件的过程不仅仅

我使用过的Linux命令之file - 检测并显示文件类型

摘自:http://codingstandards.iteye.com/blog/804463 我使用过的Linux命令之file - 检测并显示文件类型 用途说明 file命令是用来检测并显示文件类型(determine file type). 常用参数 -b 不显示文件名称,只显示文件类型.在shell脚本中时有用. -i     显示MIME类别. -L 直接显示符号连接所指向的文件的类别. -f namefile    指定名称文件(namefile),该文件每一行为一个文件名,file