Search code examples
androidzipadbbusybox

Unzip files in phone from ADB terminal


I am trying to unzip files in my android (11) phone with ADB from the terminal (Ubuntu 20.04). I need to run a script from my Ubuntu laptop to unzip files on my phone.

I have already tried Busybox from this suggestion. With this app, I can unzip files after accessing the shell. I mean -

$ adb shell                
a60q:/ $ cd /sdcard/
a60q:/sdcard $ unzip data.zip                                            
Archive:  data.zip
  inflating: Screenshot from 2020-11-30 16-45-46 (7th copy).png
  inflating: Screenshot from 2020-11-30 16-45-46 (10th copy).png

But when I try to use the direct command, it shows an error.

$ adb shell unzip /sdcard/data.zip
unzip: couldn't create file Screenshot from 2020-11-30 16-45-46 (7th copy).png: Read-only file system
Archive:  /sdcard/data.zip

Rooting phone isn't an option. My questions are -

  1. What can I do here to unzip from the terminal?
  2. Is there any tool to make compressed zip files (in Android) from the terminal?

Solution

  • In order to successfully invoke the unzip command from the terminal you should explicitly specify the folder where the zip's content will be extracted, for instance:

    adb shell unzip /sdcard/data.zip -d /sdcard
    

    By invoking unzip --help you will get more information on the other parameters available as well.