Get Your Last Downloaded File

February 15, 2017

Mac software is setup to receive files in ~/Downloads. Since I live on the command-line, the duality of downloading files and interacting with them is jarring.

I wanted a way to say:

…get the file I just downloaded…

It’s possible to tab-complete on ~/Downloads/ but that directory is usually full of crap (possibly, that’s the real problem).

I’ve been experimenting with the simplest way to automate this:

ldf() {  # stands for "last downloaded file"
  local file=~/Downloads/$(ls -1t ~/Downloads/ | head -n1)
  read -p "confirm: $file "
  mv "$file" .
}

Breakdown:

This hack is what I need most of the time.

Added bonus: you can keep calling the function if you need multiple files … it will “pop” them out in reverse, as if from a stack.

Discuss on Twitter