Search code examples
linuxtar

Extracting executable with tar


I am downloading mysql client into a mysql-client.tar.gz folder with the following command:

$ curl -fL -o mysql-client.tar.gz https://dev.mysql.com/get/Downloads/MySQL-8.4/mysql-8.4.0-linux-glibc2.28-x86_64.tar.xz

Next, I would like to unpack it and copy the executable mysql to /usr/local/bin:

$ tar xf mysql-client.tar.gz 
$ cd mysql-8.4.0-linux-glibc2.28-x86_64/bin
$ cp mysql /usr/local/bin
$ rm -f ~/mysql-client.tar.gz
$ chmod a+x /usr/local/bin/mysql

Is there a more elegant/clean way of doing it?


Solution

  • Ultimately you could download and extract without a temporary file:

    curl -L https://dev.mysql.com/get/Downloads/MySQL-8.4/mysql-8.4.0-linux-glibc2.28-x86_64.tar.xz | 
        tar -Jx -C /usr/local/bin --strip-components=2 mysql-8.4.0-linux-glibc2.28-x86_64/bin/mysql