How to download a file using curl

后端 未结 4 1761
余生分开走
余生分开走 2021-02-05 02:50

I\'m on mac OS X and can\'t figure out how to download a file from a URL via the command line. It\'s from a static page so I thought copying the download link and then using

4条回答
  •  情深已故
    2021-02-05 03:37

    There are several options to make curl output to a file

     # saves it to myfile.txt
    curl http://www.example.com/data.txt -o myfile.txt -L
    
    # The #1 will get substituted with the url, so the filename contains the url
    curl http://www.example.com/data.txt -o "file_#1.txt" -L 
    
    # saves to data.txt, the filename extracted from the URL
    curl http://www.example.com/data.txt -O -L
    
    # saves to filename determined by the Content-Disposition header sent by the server.
    curl http://www.example.com/data.txt -O -J -L
    
    # -O Write output to a local file named like the remote file we get
    # -o  Write output to  instead of stdout (variable replacement performed on )
    # -J Use the Content-Disposition filename instead of extracting filename from URL
    # -L Follow redirects  
    

提交回复
热议问题