私は次のシナリオを持っている: - その内容abcd.zipマイZipファイル=: -シングル「.zipの」ファイル - Linuxの
を- A.TXT
- B.TXT c.txt
今私は、フォルダA/B/Cと/にこのzipファイルを解凍します。 (Txtファイルは大文字でも小文字でもかまいません)
基本的に私は自分の指定したディレクトリにファイルを解凍しようとしています。
私は次のシナリオを持っている: - その内容abcd.zipマイZipファイル=: -シングル「.zipの」ファイル - Linuxの
を今私は、フォルダA/B/Cと/にこのzipファイルを解凍します。 (Txtファイルは大文字でも小文字でもかまいません)
基本的に私は自分の指定したディレクトリにファイルを解凍しようとしています。
はzipファイルと同じディレクトリにこのスクリプトを入れて、for i in `ls -1 *.txt | sed 's/\.[a-z]*//g'`; do mkdir $i; mv $i.* $i/; done
あなたは、次のよう試みることができるとの引数としてzipファイルの名前を渡します
/home/abis> ./unzip.sh test.zip
Archive: test.zip
extracting: 1/1.txt
Archive: test.zip
extracting: 2/2.txt
Archive: test.zip
extracting: 3/3.txt
:
#!/usr/bin/ksh
name="$1"
list="$(unzip -l "${name}" | sed -n '/---/,/---/{ /----/d; p; }' | awk '{print $4}')"
for file in ${list}
do
dirnam=$(basename "${file}" ".txt")
mkdir -p "${dirnam}"
unzip "${name}" -d "${dirnam}" "${file}"
done
例えば
zipinfo -1 abc.zip | while read line;do mkdir -p ${line%.*}; unzip abc.zip $line -d ${line%.*};done
:任意の拡張子については
zipinfo -1 abc.zip | while read line;do mkdir -p ${line%.txt}; unzip abc.zip $line -d ${line%.txt};done
(拡張機能として、最後のドットの後のすべてを考慮して)内線番号のリスト:
zipinfo -1 abc.zip | while read line;do mkdir -p ${line%.?(txt|jpg|gif)}; unzip abc.zip $line -d ${line%.?(txt|jpg|gif)};done
最後のオプションはextglobを必要とします。これはデフォルトでは無効になっています。だから、shopt extglob
を実行して、オンかオフかを確認します。 shopt -s extglob
を有効にし、shopt -u extglob
を無効にします。
あなたのzipファイルにはディレクトリが含まれていませんか?私はそれは常に.txtファイルしか含んでいないのですか? – Abis
はい、ディレクトリはありません –