Suspausti visus katalogus

Iš Žinynas.
01:50, 22 liepos 2022 versija, sukurta \dev\null (Aptarimas | indėlis) (Naujas puslapis: Suspausti katalogus esančius esamame kataloge. <syntaxhighlight lang="bash"> #!/bin/bash # 7zip parameters ZPARM="a -t7z -mx=9 -mfb=273 -ms -md=31 -myx=9 -mtm=- -mmt -mmtf -md...)
(skirt) ← Ankstesnė versija | Dabartinė versija (skirt) | Vėlesnė versija → (skirt)
Jump to navigation Jump to search

Suspausti katalogus esančius esamame kataloge.

#!/bin/bash

# 7zip parameters
ZPARM="a -t7z -mx=9 -mfb=273 -ms -md=31 -myx=9 -mtm=- -mmt -mmtf -md=1536m -mmf=bt3 -mmc=10000 -mpb=0 -mlc=0"

DIRB=""
REMOVE=0

if [[ "$1" == "" ]]; then
echo "You must provide the directory as the main parameter"
echo "The second parameter can be 'remove' to remove the directories which where compressed"
exit
fi

if [[ "$1" == "." ]]; then
DIRB="`pwd`"
else
DIRB="$1"
fi

if [[ "$DIRB" == "" ]]; then
echo "There must be some error..."
exit 1
fi

if [[ "$2" == "remove" ]]; then
REMOVE=1
fi

cd "$DIRB"
for dir in */
do
  base=$(basename "$dir")
  echo "Compressing directory: $dir to archive: ${base}.7z"
  7z $ZPARM "${base}.7z" "$dir" > /dev/null 2>&1
  if [[ $REMOVE == 1 ]]; then
     if [ -f "${base}.7z" ]; then
        echo "Removing directory $dir"
        rm -rf "$dir"
     fi
  fi
done


Naudojimas:

7z_dir /home/test
7z_dir /home/test remove 
7z_dir . remove

remove parametras suspaudžia ir ištrina katalogus