zipファイルの最初のディレクトリのみをリストする方法は?

zipファイルの最初のディレクトリのみをリストする方法は?

unzip -lすべてのディレクトリとサブディレクトリ/ファイルを表示します。

-maxdepth 1コマンドと同様に、zipファイルサイズの最初のディレクトリ構造のみをリストしたいと思いますfind

スクリプト全体を使わずにこれを行う方法はありますか?

ベストアンサー1

UnZip 6.00Debianベースのディストリビューションでは、以下-xのようにワイルドカードでオプションを使用できますman unzip

[-x xfile(s)]
      An optional list of archive members to be excluded from process‐
      ing.   Since  wildcard characters normally match (`/') directory
      separators (for exceptions see the option -W), this  option  may
      be  used  to  exclude any files that are in subdirectories.  For
      example, ``unzip foo *.[ch] -x */*'' would extract all C  source
      files  in  the  main  directory, but none in any subdirectories.
      Without the -x option, all C source  files  in  all  directories
      within the zipfile would be extracted.

例えば、与えられた

$ unzip -l dir
Archive:  dir.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2023-03-11 07:57   dir/
       24  2023-03-11 12:50   dir/file
     1464  2023-03-04 12:51   dir/input.csv
      187  2023-03-06 09:03   dir/input
        0  2023-02-28 10:25   dir/subdir3/
        0  2023-02-28 10:25   dir/subdir3/Files.txt
       55  2023-02-28 10:51   dir/file2
       26  2023-03-10 20:00   dir/utf-16BE.txt
        0  2023-02-28 10:25   dir/subdir2/
        0  2023-02-28 10:25   dir/subdir2/File.txt
        0  2023-02-28 10:25   dir/subdir1/
        0  2023-02-28 10:25   dir/subdir1/file.txt
      585  2023-03-01 06:54   dir/source.CSV
      115  2023-02-28 10:50   dir/file1
      211  2023-03-10 09:01   dir/01-netcfg.yaml
---------                     -------
     2667                     15 files

それから

$ unzip -l dir -x '*/*/*'
Archive:  dir.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2023-03-11 07:57   dir/
       24  2023-03-11 12:50   dir/file
     1464  2023-03-04 12:51   dir/input.csv
      187  2023-03-06 09:03   dir/input
       55  2023-02-28 10:51   dir/file2
       26  2023-03-10 20:00   dir/utf-16BE.txt
      585  2023-03-01 06:54   dir/source.CSV
      115  2023-02-28 10:50   dir/file1
      211  2023-03-10 09:01   dir/01-netcfg.yaml
---------                     -------
     2667                     9 files

おすすめ記事