Search code examples
linuxunzip

Change directory after unziping


I am making a script that allow's me to unzip a given file. My problem is that i don't now how to change directory to the directory just created by the unzip process. I tried with this command, but it's not working: SITE_DIRECTORY="$(ls -dt */ | head -1)"

Any idea on how to get the name of the directory just extracted ?

Edit: Now i got to SITE_DIRECTORY=unzip $SITE_NAME | grep 'creating:' | head -1 | cut -d' ' -f5-

But a new problem arise: the unzip command does not extract all the files. New ideas ?


Solution

  • The solution to my problem was the following commands:

    unzip $SITE_NAME >output.txt
    SITE_DIRECTORY=$(cat output.txt | grep -m1 'creating:' |  cut -d' ' -f5-)
    rm output.txt
    

    Thanks goes to Evan @ Unzip File which directory was created