I was in the middle of an introductory workshop for Data Science at General Assembly and I was talking about using command line instructions to facilitate the manipulation of files and folders. We covered some of the usual ones such as ls, mv, mkdir, cat, more, less, etc. I was then going to demonstrate how easy it was to download a file from the command line using curl and I had prepared a small file uploaded to Dropbox and shortened its URL with bit.ly.
“So far so good” – I thought – and then proceeded with the demonstration… Only to find out that the command I was using was indeed downloading a file, but it was the only downloading the wrapper html created by bit.ly for the re-directioning… I should have known better than that! Of course all this happening while various pairs of gazing eyes were upon me… I tried again using a different flag and… nothing! and again… nothing… Pressure mounting, I decided to cut the embarrassment short and apologised. Got them to download the file in the less glamorous way by using the browser…
So, if you are ever in that predicament, here is the solution, use the -L flag with curl:
$ curl -L -o newname.ext http://your.shortened.url
The -L deals with the redirectioning of the shortened URL and make sure that you use the -o flag to assign a new name to your file.