2017-08-16 8 views
0

私は次のシナリオを持っている: - その内容abcd.zipマイZipファイル=: -シングル「.zipの」ファイル - Linuxの

  1. A.TXT
  2. B.TXT c.txt

今私は、フォルダA/B/Cと/にこのzipファイルを解凍します。 (Txtファイルは大文字でも小文字でもかまいません)

基本的に私は自分の指定したディレクトリにファイルを解凍しようとしています。

+0

あなたのzipファイルにはディレクトリが含まれていませんか?私はそれは常に.txtファイルしか含んでいないのですか? – Abis

+0

はい、ディレクトリはありません –

答えて

0
  1. アーカイブを現在のディレクトリに解凍します。

    はzipファイルと同じディレクトリにこのスクリプトを入れて、
    for i in `ls -1 *.txt | sed 's/\.[a-z]*//g'`; do mkdir $i; mv $i.* $i/; done

0

あなたは、次のよう試みることができるとの引数としてzipファイルの名前を渡します

  • は、次のコマンドを実行しますスクリプト。それはすべての.txtなら

    /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 
    
  • 0

    #!/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を無効にします。

    関連する問題