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/