Skip to content

Instantly share code, notes, and snippets.

@yingziwu
Last active October 16, 2017 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yingziwu/b8616dcc676e9115630294c6bd89ac43 to your computer and use it in GitHub Desktop.
Save yingziwu/b8616dcc676e9115630294c6bd89ac43 to your computer and use it in GitHub Desktop.
#!/bin/bash
find . -type d -printf "%f\n" > file_list.tmp
sed -i -e 's/^/"/g' -e 's/$/"/g' -e '1d' file_list.tmp
mkdir origin/ converted/
function run_convert(){
f_in=$@
f_out=$(echo ${f_in}|sed 's/$/\.zip/g')
mkdir tmp2/
find "${f_in}" -name "*.png" -exec cp -l {} tmp2/ \;
find "${f_in}" -name "*.jpg" -exec cp -l {} tmp2/ \;
find "${f_in}" -name "*.jpeg" -exec cp -l {} tmp2/ \;
find "${f_in}" -name "*.gif" -exec cp -l {} tmp2/ \;
cd tmp2/
zip -r "../converted/${f_out}" *
cd ../
rm -r tmp2
mv "${f_in}" origin/
}
export -f run_convert
xargs -a file_list.tmp -n 1 bash -c 'run_convert "$@"' _
rm file_list.tmp
#!/bin/bash
# rar
# find . -name "*.rar" -printf "%f\n" > file_list.tmp
# 7z
# find . -name "*.7z" -printf "%f\n" > file_list.tmp
sed -i -e 's/^/"/g' -e 's/$/"/g' file_list.tmp
mkdir origin/ converted/
function run_convert(){
mkdir tmp1/
f_in=$@
# rar
# f_out=$(echo ${f_in} | sed 's/\.rar/\.zip/g')
# 7z
# f_out=$(echo ${f_in} | sed 's/\.rar/\.zip/g')
# rar 无密码
# unrar x "${f_in}" tmp1
# rar 有密码
# password="扶她奶茶"
# unrar x -p${password} "${f_in}" tmp1
# 7z 无密码
# 7z x -otmp1 "${f_in}"
# 7z 有密码
# password="扶她奶茶"
# 7z x -otmp1 -p${password} "${f_in}"
mkdir tmp2/
find tmp1/ -name "*.png" -exec mv {} tmp2/ \;
find tmp1/ -name "*.jpg" -exec mv {} tmp2/ \;
find tmp1/ -name "*.jpeg" -exec mv {} tmp2/ \;
find tmp1/ -name "*.gif" -exec mv {} tmp2/ \;
cd tmp2/
zip -r "../converted/${f_out}" *
cd ../
rm -r tmp1 tmp2
mv "${f_in}" origin/
}
export -f run_convert
xargs -a file_list.tmp -n 1 bash -c 'run_convert "$@"' _
rm file_list.tmp
#!/bin/bash
# rar
find . -name "*.rar" -printf "%f\n" > file_list.tmp
# 7z
# find . -name "*.7z" -printf "%f\n" > file_list.tmp
sed -i -e 's/^/"/g' -e 's/$/"/g' file_list.tmp
mkdir origin/ converted/
function run_convert(){
mkdir tmp1/
f_in=$@
# rar
f_out=$(echo ${f_in} | sed 's/\.rar/\.zip/g')
# 7z
# f_out=$(echo ${f_in} | sed 's/\.rar/\.zip/g')
# rar 无密码
unrar x "${f_in}" tmp1
# rar 有密码
# password="扶她奶茶"
# unrar x -p${password} "${f_in}" tmp1
# 7z 无密码
# 7z x -otmp1 "${f_in}"
# 7z 有密码
# password="扶她奶茶"
# 7z x -otmp1 -p${password} "${f_in}"
mkdir tmp2/
find tmp1/ -name "*.png" -exec mv {} tmp2/ \;
find tmp1/ -name "*.jpg" -exec mv {} tmp2/ \;
find tmp1/ -name "*.jpeg" -exec mv {} tmp2/ \;
find tmp1/ -name "*.gif" -exec mv {} tmp2/ \;
cd tmp2/
zip -r "../converted/${f_out}" *
cd ../
rm -r tmp1 tmp2
mv "${f_in}" origin/
}
export -f run_convert
xargs -a file_list.tmp -n 1 bash -c 'run_convert "$@"' _
rm file_list.tmp
#!/bin/bash
# rar
find . -name "*.rar" -printf "%f\n" > file_list.tmp
# 7z
# find . -name "*.7z" -printf "%f\n" > file_list.tmp
sed -i -e 's/^/"/g' -e 's/$/"/g' file_list.tmp
mkdir origin/ converted/
function run_convert(){
mkdir tmp1/
f_in=$@
# rar
f_out=$(echo ${f_in} | sed 's/\.rar/\.zip/g')
# 7z
# f_out=$(echo ${f_in} | sed 's/\.rar/\.zip/g')
# rar 无密码
# unrar x "${f_in}" tmp1
# rar 有密码
password="扶她奶茶"
unrar x -p${password} "${f_in}" tmp1
# 7z 无密码
# 7z x -otmp1 "${f_in}"
# 7z 有密码
# password="扶她奶茶"
# 7z x -otmp1 -p${password} "${f_in}"
mkdir tmp2/
find tmp1/ -name "*.png" -exec mv {} tmp2/ \;
find tmp1/ -name "*.jpg" -exec mv {} tmp2/ \;
find tmp1/ -name "*.jpeg" -exec mv {} tmp2/ \;
find tmp1/ -name "*.gif" -exec mv {} tmp2/ \;
cd tmp2/
zip -r "../converted/${f_out}" *
cd ../
rm -r tmp1 tmp2
mv "${f_in}" origin/
}
export -f run_convert
xargs -a file_list.tmp -n 1 bash -c 'run_convert "$@"' _
rm file_list.tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment