Search code examples
linuxdirectoryzipunzip

Unzip wrongly: All files are scattered in the current directory


On CentOS, I wanted to unzip files in A.zip into ./A/. However, I didn't notice that there were hundreds of files in A.zip and I just use unzip A.zip. So now these extra files are all in the current directory. How could I solve this problem?

Thank you very much for any help!


Solution

  • You can try this -

    unzip -Z1 is the zip info mode which basically returns the files which were zipped. The output is then piped onto other command which removes that file based on the input(from the previous command).

    Assuming, first you take a proper backup of that folder.

    unzip -Z1 t1.zip | xargs rm -f
    

    If the zip files has folders inside of it then

    unzip -Z1 t1.zip | xargs rm -rf
    

    t1.zip is the zip file which I tested with.