How can I specify command line arguments using pipes in Linux?

I'm a newbie to shell programming and have no idea how to solve this problem.

I just downloaded a file from the Internet to the default directory ~/Downloads. I want to move that file to another directory, ~/Documents.

Since I don't know the exact name of the downloaded file, I think I can use the following command to achieve my goal:

ls -t ~/Downloads | head -1 | mv [source] [destination]

How can I specify which formal parameter to replace. In my case, I want to omit [source] and fill in the [destination] parameter as ~/Documents myself.


You want xargs.

echo "foo" | xargs touch
ls -l foo

ls -t ~/Downloads | head -1 | xargs -I  {} mv ~/Downloads/{} ~/Documents

This will work with files that have spaces in their names.