• Uncategorized

About linux : How-to-undo-extracted-files-by-7z

Question Detail

I was trying to install aws cli.

I executed the following command
curl “https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip” -o “awscliv2.zip”

It downloaded to my directory awscliv2.zip

Then I installed 7zip to extract files and used the command:

7z e awscliv2.zip

It seems that 7z extracted all those files not in an aws directory, but It unfolded all files recursively without directories at all.

I’ve taken a screenshot to show you the issue. If I extract the file again, it shows it wants to overwrite my existing file in the root with a file which has depth 1. It somehow extracts recursively file than preserving a hierarchy of directories.

Well, I’ve got thousands files in my user directory and don’t know how to undo the operation. 🤷‍♂️

I’ve tried those commands, but both of them failed.

7z l awscliv2.zip | sed 's/\(.\{53\}\)//'

7z l awscliv2.zip | awk 'BEGIN { OFS="" ; ORS="" } ; { for ( i=4; i<NF; i++ ) print $i " "; print $NF "\n" }' | xargs -I{} rm -v {}

How can I resolve this mess?

Question Answer

Well, I think I found a solution:

7z l awscliv2.zip | awk ' {print $6} ' | awk '
  function basename(file) {
    sub(".*/", "", file)
    return file
  {print basename($1)} ' | xargs rm -rf

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.