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

답변2

이와 같이,MCVE방법:

curl -s https://gist.githubusercontent.com/sputnick-dev/1d2303e5fb75af8792f828ff33c127af/raw/e42cd4f56ce1b430752269cff2571342b19eb58a/gistfile1.txt | bash
cd /tmp
zip -r rand_dirs.zip rand_dirs
unzip -l rand_dirs.zip |
    grep -oP '^\s+\d+\s+\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}\s+\K[^/]+/[^/]+' |
    sort -u

산출

rand_dirs/Yqol
rand_dirs/yT3oVke
rand_dirs/yt7p
rand_dirs/z
rand_dirs/z8Tx
rand_dirs/ZaQ7cE
rand_dirs/zeWgeCr8RbS
rand_dirs/zVf4
[...]

관련 정보