There is a .tar.gz archive that is downloaded using wget . As a result, I have an archive in the folder. After I unpack this archive into another folder with the command

 tar -xf myfile.tar.gz -C someDir 

I know that there will be only one folder in the archive, but I don’t know its name, since When packing, the name may change (for a version number, for example).

Question: How can I write the name of this unpacked folder into a variable, if I know that its name will start with MyDistr_2000.3000.5000 , for example?

Got the folder name in the console like this:

 ls -t someDir | head -1 

What command can I use to write the folder name?

    1 answer 1

    Got the folder name in the console in this way

    in the same way, write to a variable:

     переменная=$(ls -t someDir | head -1) 

    possible without unpacking files:

     переменная=$(tar -tf myfile.tar.gz | head -1) 
    • Hmm, apparently when I tried myDir=(ls someDir | grep MyDist) I did not assign anything (although I did), I did not try this with the second option, but yes, it turned out thanks. And you need to unpack the archive) Thanks for the help! - Vasily Barbashev
    • dollar sign missed: myDir=$(ls ... - aleksandr barakin
    • Similarly, in this I pierced. Thank you - Vasily Barbashev