【问题】
想要批量删除一些文件,知道linux中有管道和重定向,所以打算利用管道或重定向去批量删除。
结果是不行:
Administrator@PC-20130611GART /cygdrive/e/Dev_Root/docbook/dev/books $ find . -name build.xml ./arm_vs_mips/src/build.xml ./binutils_intro/src/build.xml ./build_website/src/build.xml ./buy_house/src/build.xml ./char_encoding/src/build.xml ./compute_basic/src/build.xml ./crifanlib_csharp/src/build.xml ./crifan_rec_soft/src/build.xml ./crosstool_ng/src/build.xml ./cross_compile/src/build.xml ./csharp_summary/src/build.xml ./cygwin_intro/src/build.xml ./dma_pl08x_analysis/src/build.xml ./docbook_dev_note/src/build.xml ./english_learn/src/build.xml ./fieldbus_intro/src/build.xml ./firmware_download/src/build.xml ./hardware_basic/src/build.xml ./interrupt_related/src/build.xml ./json_tutorial/src/build.xml ./language_dev_basic/src/build.xml ./language_summary/src/build.xml ./linux_nand_driver/src/build.xml ./linux_wireless/src/build.xml ./mpeg_vbr/src/build.xml ./nand_get_type/src/build.xml ./programming_language_basic/src/build.xml ./python_beginner_tutorial/src/build.xml ./python_intermediate_tutorial/src/build.xml ./python_summary/src/build.xml ./python_topic_beautifulsoup/src/build.xml ./python_topic_re/src/build.xml ./python_topic_str_encoding/src/build.xml ./python_topic_web_scrape/src/build.xml ./rec_soft_npp/src/build.xml ./regular_expression/src/build.xml ./runtime_upgrade_linux/src/build.xml ./soft_dev_basic/src/build.xml ./symbology_code128/src/build.xml ./symbology_gs1128/src/build.xml ./symbology_plessey/src/build.xml ./symbology_upc/src/build.xml ./uboot_starts_analysis/src/build.xml ./usb_basic/src/build.xml ./usb_disk_driver/src/build.xml ./usb_hid/src/build.xml ./virtualbox_tutorial/src/build.xml ./virutal_machine_tutorial/src/build.xml ./vmware_tutorial/src/build.xml ./website_transfer/src/build.xml ./web_scrape_emulate_login/src/build.xml Administrator@PC-20130611GART /cygdrive/e/Dev_Root/docbook/dev/books $ find . -name build.xml | rm rm: 缺少操作数 请尝试执行"rm --help"来获取更多信息。 Administrator@PC-20130611GART /cygdrive/e/Dev_Root/docbook/dev/books $ find . -name build.xml > rm Administrator@PC-20130611GART /cygdrive/e/Dev_Root/docbook/dev/books $ find . -name build.xml ./arm_vs_mips/src/build.xml ./binutils_intro/src/build.xml ./build_website/src/build.xml ./buy_house/src/build.xml ./char_encoding/src/build.xml ./compute_basic/src/build.xml ./crifanlib_csharp/src/build.xml ./crifan_rec_soft/src/build.xml ./crosstool_ng/src/build.xml ./cross_compile/src/build.xml ./csharp_summary/src/build.xml ./cygwin_intro/src/build.xml ./dma_pl08x_analysis/src/build.xml ./docbook_dev_note/src/build.xml ./english_learn/src/build.xml ./fieldbus_intro/src/build.xml ./firmware_download/src/build.xml ./hardware_basic/src/build.xml ./interrupt_related/src/build.xml ./json_tutorial/src/build.xml ./language_dev_basic/src/build.xml ./language_summary/src/build.xml ./linux_nand_driver/src/build.xml ./linux_wireless/src/build.xml ./mpeg_vbr/src/build.xml ./nand_get_type/src/build.xml ./programming_language_basic/src/build.xml ./python_beginner_tutorial/src/build.xml ./python_intermediate_tutorial/src/build.xml ./python_summary/src/build.xml ./python_topic_beautifulsoup/src/build.xml ./python_topic_re/src/build.xml ./python_topic_str_encoding/src/build.xml ./python_topic_web_scrape/src/build.xml ./rec_soft_npp/src/build.xml ./regular_expression/src/build.xml ./runtime_upgrade_linux/src/build.xml ./soft_dev_basic/src/build.xml ./symbology_code128/src/build.xml ./symbology_gs1128/src/build.xml ./symbology_plessey/src/build.xml ./symbology_upc/src/build.xml ./uboot_starts_analysis/src/build.xml ./usb_basic/src/build.xml ./usb_disk_driver/src/build.xml ./usb_hid/src/build.xml ./virtualbox_tutorial/src/build.xml ./virutal_machine_tutorial/src/build.xml ./vmware_tutorial/src/build.xml ./website_transfer/src/build.xml ./web_scrape_emulate_login/src/build.xml Administrator@PC-20130611GART /cygdrive/e/Dev_Root/docbook/dev/books $ rm < find . -name build.xml bash: find: No such file or directory
所以想要解决此问题。
【解决过程】
1.找了下,没有看到很好的解释。
但是看到有些好像提到了那个xargs。
2.参考:
先去看看这个xargs:
3.如此,就基本命令xargs的含义,并且知道此处不应该传递-0等参数了。
所以去试试:
Administrator@PC-20130611GART /cygdrive/e/Dev_Root/docbook/dev/books $ find . -name build.xml | xargs rm Administrator@PC-20130611GART /cygdrive/e/Dev_Root/docbook/dev/books $ find . -name build.xml
就可以实现,批量删除build.xml的效果了:
【总结】
此处,还是要明白用find和xargs组合,才能实现批量删除的效果。
所用命令如下:
find . -name build.xml | xargs rm
简单解释:
- find . -name build.xml : 将当前文件夹下面的build.xml都找出来
- xargs rm :通过xargs,将上面find出来的字符串,该字符串是一堆的文件其中是换行符隔开的,所以可以被xargs(去掉换行符)分割成一个文件的列表,送给rm去删除