Argument list too long error for rm, cp, mv commands

前端 未结 27 2808
长情又很酷
长情又很酷 2020-11-22 04:50

I have several hundred PDFs under a directory in UNIX. The names of the PDFs are really long (approx. 60 chars).

When I try to delete all PDFs together using the fol

27条回答
  •  无人共我
    2020-11-22 05:18

    I only know a way around this. The idea is to export that list of pdf files you have into a file. Then split that file into several parts. Then remove pdf files listed in each part.

    ls | grep .pdf > list.txt
    wc -l list.txt
    

    wc -l is to count how many line the list.txt contains. When you have the idea of how long it is, you can decide to split it in half, forth or something. Using split -l command For example, split it in 600 lines each.

    split -l 600 list.txt
    

    this will create a few file named xaa,xab,xac and so on depends on how you split it. Now to "import" each list in those file into command rm, use this:

    rm $(

    Sorry for my bad english.

提交回复
热议问题