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

前端 未结 27 2508
长情又很酷
长情又很酷 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:07

    To delete all *.pdf in a directory /path/to/dir_with_pdf_files/

    mkdir empty_dir        # Create temp empty dir
    
    rsync -avh --delete --include '*.pdf' empty_dir/ /path/to/dir_with_pdf_files/
    

    To delete specific files via rsync using wildcard is probably the fastest solution in case you've millions of files. And it will take care of error you're getting.


    (Optional Step): DRY RUN. To check what will be deleted without deleting. `

    rsync -avhn --delete --include '*.pdf' empty_dir/ /path/to/dir_with_pdf_files/
    

    . . .

    Click rsync tips and tricks for more rsync hacks

提交回复
热议问题