Printing the Location of a Command with which
The purpose of which is to tell you exactly which command would be
executed if you typed it. For example, which mkdir returns
/bin/mkdir, telling you that running the command mkdir runs
/bin/mkdir.
Downloading Files with wget
Let’s say you see a website with useful content that you need to download to
your server—(for example, http://releases.ubuntu.com) because you want to
make available to students who work in your computer lab a copy of the ISO
of the current release of Ubuntu. This practice, called mirroring, is commonly
accepted. Or, maybe you want to download the latest Minecraft server file to
your server and don’t want to download it from the website to your local
machine first before you upload it to your server. You can do this with wget,
which exists to download files using HTTP, HTTPS, and FTP, like this:
Click here to view code image
matthew@seymour:~$ wget http://releases.ubuntu.com/16.04/ubuntu-
16.04-desktop-amd64.iso
This downloads the linked file directly to the directory in which you issue the
command.
What if you want to copy all of the content files from your existing web
server onto a new server? You can use the -m or the —mirror flag to do this.
This example downloads all of the contents of the directory you specify,
assuming that you have access, to your current directory:
Click here to view code image
matthew@seymour:~$ wget http://youroldserver.com/website/files
TIP
You can use wget with any standard URL syntax, including specifying
ports and usernames and passwords, but you should realize that the
username and password information will be transmitted in plain text;
therefore, this is not considered a secure method of data transfer. For that,
use scp, which is covered in Chapter 19, “Remote Access with SSH,
Telnet, and VNC.”