xargs用法

1. 当尝试用rm 删除太多的文件,可能得到一个错误信息:/bin/rm Argument list too long. 用xargs 去避免这个问题

find ~ -name '*.log' | xargs rm -fv


2. 获得/etc/ 下所有*.conf 结尾的文件列表,有几种不同的方法能得到相同的结果,下面的例子仅仅是示范怎么实用xargs ,在这个例子中实用 xargs将find 命令的输出传递给ls -l

# find /etc -name '*.conf' | xargs ls -l


3. 假如你有一个文件包含了很多你希望下载的URL, 你能够使用xargs 下载所有链接

# cat url-list.txt | xargs wget -c


4. 查找所有的jpg 文件,并且压缩它

# find / -name *.jpg -type f -print | xargs tar -cvzf images.tar.gz


5. 拷贝所有的图片文件到一个外部的硬盘驱动 

# ls *.jpg | xargs -n1 -i cp {} /external-hard-drive/directory

6. 移动某一时间段文件
touch -t 11181200 file1
touch -t 11191600 file2
find vbbw*csv -newer file1 ! -newer file2|xargs ls -ltr
find vbbw*csv -newer file1 ! -newer file2 -exec mv {} backup/folder1 \;

7. 只查找当前目录(AIX)
find .  ! -name "." -type d -prune -o -type f -name "*.txt" -print

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22558114/viewspace-1216814/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/22558114/viewspace-1216814/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值