2

I'm pretty new at using the terminal and was wondering how to place a folder full of .zip files into sub folders named the same as the .zip file it was extracted from.

So far I figured that unzip '*.zip' -d will extract all the .zip files into a single directory, but I'm not sure how to point/create destination folders for the -d for each .zip file.

Alternatively, the Nautilus Action Config Tool seems like if might be able to mimic the 7zip Extract To command, but this seems a bit more daunting.

D. Joe
  • 43

3 Answers3

1

I edited a script that I found for file name to folder name to extract into the created folder.

Revised: In your directory create a file with:

#!/bin/bash
find . -type f ! -name "*exto*" | while read file;
do
    f=$(basename "$file")
    f1=${f%.zip}
    mkdir "$f1"
    unzip "$f" -d "$f1" 
done

In terminal:

chmod +x exto
./exto
derHugo
  • 3,356
  • 5
  • 31
  • 51
D. Joe
  • 43
1

Using the Nautilus Action Config Tool option and calling my script zippy.sh:

#!/bin/bash
# Unzipping and organizing files from nautilus
m=0 # counter
while [ -n "$1" ] && [ -f "$1" ]
do
    if [[ "$1" =~ \.zip$ ]]
    then
        dir="$1"
        dir=${dir%.*}
        unzip "$1" -d "$dir"
        m=$(($m + 1))
        shift
    fi
done
zenity --info --text="Operations finished and "$m" zip files unzipped"
exit 0
  1. Place script here:

    ~/.local/share/nautilus/scripts/
    
  2. Make it executable with chmod +x ~/.local/share/nautilus/scripts/zippy.sh

Explained:

  1. -n and -f check file number is not zero and is file respectively

  2. =~ \.zip$ make sure it's a zip file

  3. ${dir%.*} cut off the zip part of filename

  4. m=$(($m + 1)) count how many zip files are worked on.

  5. shift flip through files

  6. zenity display a message box to indicate operations conclusion

derHugo
  • 3,356
  • 5
  • 31
  • 51
George Udosen
  • 36,677
  • Great! I will definitely try that out. And I had to edit my previous code as I just got luck with the files extracting to the correct folders on my test run. – D. Joe Jan 25 '17 at 21:07
  • 2
    No problemo, first time on, didn't notice the check mark. – D. Joe Jan 25 '17 at 21:45
0

You could also just download the 7Zip version for linux. https://sourceforge.net/projects/p7zip/files/ It is called p7zip

https://www.ibm.com/developerworks/community/blogs/6e6f6d1b-95c3-46df-8a26-b7efd8ee4b57/entry/how_to_use_7zip_on_linux_command_line144?lang=en This also provides a very detailed guide of installation and use

  • I did, but it didn't add anything to the context menu nor did I find a command that would create folders from the file names from the archlinux wiki link – D. Joe Jan 25 '17 at 21:21
  • Have you tried this https://www.ibm.com/developerworks/community/blogs/6e6f6d1b-95c3-46df-8a26-b7efd8ee4b57/entry/how_to_use_7zip_on_linux_command_line144?lang=en – roberthayek Jan 25 '17 at 21:24