Wednesday, May 15, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 3217  / 2 Years ago, mon, february 14, 2022, 12:08:01

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.


More From » extract

 Answers
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



[#12324] Tuesday, February 15, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
fieldcheon

Total Points: 24
Total Questions: 105
Total Answers: 109

Location: Western Sahara
Member since Tue, Feb 16, 2021
3 Years ago
;