Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Easily download web files in the Terminal UNIX
Okay, we all know and love curl at the terminal for downloading files when we want a rock-solid download, with resume and all that... After getting sick of always copying a URL from the browser and going to the terminal typing curl -O and pasting the URL have come up with a little trick that saves some time. In your, say, ~/.bashrc file (or whatever your shell uses as its rc file), define the alias:
alias getit='curl -O `pbpaste`'
Mind the directions of the quotes and backticks there! Now, go to the browser, copy the URL, then change to the terminal and type getit. This will call curl to download the URL that's currently on the clibpoard, and save it as the original name.
    •    
  • Currently 2.33 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[11,796 views]  

Easily download web files in the Terminal | 19 comments | Create New Account
Click here to return to the 'Easily download web files in the Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
dosn't work with dynamic pages ala php
Authored by: macubergeek on May 30, '03 10:58:44AM

I get these errors:

curl: (26) Receeived problem in the chunky parser



[ Reply to This | # ]
dosn't work with dynamic pages ala php
Authored by: mervTormel on May 30, '03 11:49:25AM

try the crispy parser



[ Reply to This | # ]
dosn't work with dynamic pages ala php
Authored by: macubergeek on Jun 02, '03 01:03:47PM

heh
the chunky parsley didn't work either ;-)



[ Reply to This | # ]
Easily download web files in the Terminal
Authored by: obakasan on May 30, '03 10:59:08AM

Neat trick. I modified it a bit so that it would put the target URL from the clipboard onto my desktop, because I tend to use curl from the command line without remembering where I am, and end up with lots of downloaded files in places where I can't find them later.

alias grabfile='cd ~/Desktop && curl -O $(pbpaste) && cd - '

Note that the $(pbpaste) construction (and possibly even the alias='' construction) is specific to bash. Otherwise, replace it with the backticks like in the original hint.

[ Reply to This | # ]

Please HELP!
Authored by: JohnnyBender on Jun 02, '03 10:40:40PM

I can't get this to work, can you please help me?

I've tried pasting:
alias grabfile='cd ~/Desktop && curl -O $(pbpaste) && cd - '

into both my .tcshrc and .bshrc file, but when I type "grabfile" from the terminal, I get the error "grabfile: Command not found."

What am I doing wrong?



[ Reply to This | # ]
Javascript anyone?
Authored by: sinjin on May 30, '03 02:17:57PM
This has got javascript + Safari written all over it ala this hint.

I don't know javascript from a hole in the ground, but would appreciate it if someone who did provided a curl solution here! Perhaps a contextual menu add on, "Download with curl", for right-clicked links?

[ Reply to This | # ]

Javascript anyone?
Authored by: datawrangler on Jun 01, '03 12:07:02PM

Try using OnMyCommand (free.abracode.com) to create contextual menuitems for nifty CLI commands such as 'curl -O'. It's a great utility for adding unix-powered contextual menuitems. Or maybe one of the Konfabulator people has a similar widget.

In my shell (bash), I alias wget='curl -# -O' (the -# option gives a nice progress bar). This way, any CLI programs which rely on wget continue to work properly, even though I haven't installed the wget package.



[ Reply to This | # ]
Easily download web files in the Terminal
Authored by: Cantus on May 30, '03 02:26:00PM

Shameless plug here:

My AppleScript Studio application Simple cURL allows you to download files using cURL from the application itself or by sending to Terminal. Resume supported.

Download Here



[ Reply to This | # ]
Easily download web files in the Terminal
Authored by: omnivector on May 30, '03 04:56:59PM

For those fink users, try out wget. It's a much more well known, and very easy to use. I didn't even know about curl until OSX, as I had always been an avid wget fan.

---
- Tristan



[ Reply to This | # ]
Easily download web files in the Terminal
Authored by: Darkshadow on May 31, '03 12:23:19PM

cURL has more options than wget does, though. I'm an oldschool wget user too, and I have them both installed, but I find myself using cURL more than wget these days.



[ Reply to This | # ]
Easily download web files in the Terminal
Authored by: jcteo on Jun 01, '03 10:06:02AM

I used curl quite a bit and I'm the author of FileChute which uses curl behind the scene.

While this is a very neat trick, I'm wondering why people are using curl when they already have the link they can click on in the browser. Can someone enlighten me? I'm genuinely curious as to how folks are using curl.

-j



[ Reply to This | # ]
Why use curl?
Authored by: gatorparrots on Jun 01, '03 10:49:02AM

Ever seen a misconfigured web server serve up a .dmg file as a page full of gibberish text? If so, you can see the necessity of this hint.



[ Reply to This | # ]
Why use curl?
Authored by: jcteo on Jun 01, '03 12:33:56PM

Good point. But wouldn't right-clicking on the link and selecting "Download to disk" be easier?

Please don't get me wrong, I use curl a lot, just not in this context and I'm really interested in exploring more ways to utilize this awesome tool.



[ Reply to This | # ]
Easily download web files in the Terminal
Authored by: wzpgsr on Jun 01, '03 03:45:12PM

I sometimes browse the web at work, only to find a file I want to download to my home computer. I will copy the URL, ssh into my home computer, and use wget or curl to download the file.



[ Reply to This | # ]
Easily download web files in the Terminal
Authored by: fxt on Jun 01, '03 06:09:28PM

the place where i work has an institutional subsscription to various professional journals. in order to download the latest and greatest research papers, the domain name from where the request originates must match the domain name on the institutional subscription. if i'm working from home, the most efficient way i'm aware of to get the desired manuscript is to ssh into a work machine, curl the desired document, and scp it back home.

fxt



[ Reply to This | # ]
Easily download web files in the Terminal
Authored by: fxt on Jun 02, '03 12:34:12AM

sometimes something is embedded in a web page and not clickable. so i peek at the source, find the location of the file i desire (e.g. a flash animation), copy the location, and curl it.

fxt



[ Reply to This | # ]
Easily download web files in the Terminal
Authored by: HyperSeeker on Jun 02, '03 12:10:37AM

This is a bit off-topic, I guess. I can never get the alias thing to work. I use the default (tcsh) shell and added the line above as it was to the file .tcshrc (there is nothing else in this file). When I type getit after I copied the url, it said "getit: Command not found". I really like this feature as I want to download stuff to my home HD instead at work.

Am I missing something? Is there anything I have to include on the top of the file?

---
--
"At my signal, unleash hell" -Maximus



[ Reply to This | # ]
Easily download web files in the Terminal
Authored by: HyperSeeker on Jun 02, '03 12:23:03AM

Never mind. I found out from a topic in the forums that I needed to drop the "=". Maybe this differes from shell to shell.

---
"At my signal, unleash hell" -Maximus



[ Reply to This | # ]
Easily download web files in the Terminal
Authored by: RalfM on Jun 02, '03 02:26:19AM

You can of course also just drag and drop the URL into the terminal window, rather than copy and pasting. In Mozilla, the little ribbon looking thing; in Safari the globe; etc ... Or, from within a page, just drag the hyperlink across.

Drag and drop also works with icons, i.e. dropping an icon onto terminal cuts and pastes in the path to that object. Useful when you want to use vi or other terminal based editors to quickly get into a text file, e.g. a resource file.

Drag and drop also has the advantage here that you don't need to copy the link into the buffer, and it works for every app not just the one you alias.

Ralf




[ Reply to This | # ]