curl is a command-line tool to transfer data to or from a server, using any of the supported protocols (HTTP, FTP, IMAP, SCP, SFTP, SMTP, TFTP, TELNET, LDAP, or FILE). This tool is preferred for automation since it is meant to work without user interaction. curl can transfer multiple files at once.

Installation of curl command on CentOS 8

When trying to download a file with curl, if receive a message that 'curl command not found' indicates that the curl package is not installed in your CentOS device.

Curl package is possible in the official CentOS 8 repositories.

Run the following command to install it.

 sudo dnf install curl

Once the installation is completed, that can be verified by typing the curl in the terminal.

curl

The output is:

curl: try 'curl --help' or 'curl --manual' for more information

It means that the curl has been installed on your CentOS system.

How to use curl?

When used without any option, curl prints the source code of the given URL to the standard output:

curl https://test.com

To download a file with curl, use either the '-o' or '-O' option, followed by the URL to the file.

The lowercase '-o' option allows you to specify the name of the saved file:

curl -o linux.tar.xz https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.5.3.tar.xz

The uppercase '-O' saves the file with its original filename:

curl -O https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.5.3.tar.xz

When used with the '-I' option curl shows the HTTP headers of a given URL:

curl -I https://www.centos.org/

The output is:

HTTP/1.1 200 OK
Date: Sat, 08 Apr 2021 18:02:01 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips
Strict-Transport-Security: max-age=31536000
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Referrer-Policy: same-origin
Last-Modified: Sat, 08 Apr 2021 18:02:01 GMT
ETag: "5421-59deb7fadfdfd"
Accept-Ranges: bytes
Content-Length: 21537
Content-Type: text/html; charset=UTF-8

With curl you can also download data from FTP servers that would be password protected.

Run below command:

curl -u FTP_USERNAME:FTP_PASSWORD ftp://ftp.example.com/file.tar.gz

War diese Antwort hilfreich? 0 Benutzer fanden dies hilfreich (0 Stimmen)