質問

用していただきたいと思いリストフォルダの現在のレベルを含まないそのサブフォルダ)や印刷のフォルダの名前をカウント数のファイルをフォルダ(好ましくはフィルタリング*.jpg可能な場合).

こんなことが可能なので、標準bashシェル? ls -l 版画約も、ファイル数:)

役に立ちましたか?

解決

私たちがこちら!

find -maxdepth 1 -type d | while read dir; do 
    count=$(find "$dir" -maxdepth 1 -iname \*.jpg | wc -l)
    echo "$dir ; $count"
done

落第二 -maxdepth 1 場合の検索内のディレクトリのためのjpgファイルを再帰的検討サブディレクトリが入っています。注意のことだけを考慮した名前のファイルです。お名前の変更、ファイルが隠れるところ。で利用できます file コマンドを用いて行うかを当てるというものコンテンツの代わりに(もうちょっと待っててくださいね検索を再帰的に):

find -mindepth 1 -maxdepth 1 -type d | while read dir; do 
    count=$(find "$dir" -type f | xargs file -b --mime-type | 
            grep 'image/jpeg' | wc -l)
    echo "$dir ; $count"
done

しかし、その速度の遅さでは、これまでのファイルが解釈するには何が含まれている場合では、運が良けできるようにするためのlibsoupおよ魔法のidをファイルのファイル).の -mindepth 1 を防止でから印刷 . (現在のディレクトリ)としてしようとしているディレクトリ検索の対象にしています。

他のヒント

すことが問題となっているんでね、自分の似す。そうで着条件は非常に柔軟ないとして追加します、次のように答えた。

メリット:

  • できグルーピング 任意の深さにおいて (0 ., の1のための最初のレベルのサブディレクトリなど)
  • 版画写出力
  • 無ループ、み find コマンドで奥高尾にひっそりと建つ料亭。がより大きなディレクトリ
  • きな期待を追加カスタムフィルター(maxdepthで非再帰的には、ファイル名のパターン)

原コード:

  find -P . -type f | rev | cut -d/ -f2- | rev | \
      cut -d/ -f1-2 | cut -d/ -f2- | sort | uniq -c

包み込機能説明:

fc() {
  # Usage: fc [depth >= 0, default 1]
  # 1. List all files, not following symlinks.
  #      (Add filters like -maxdepth 1 or -iname='*.jpg' here.)
  # 2. Cut off filenames in bulk. Reverse and chop to the
  #      first / (remove filename). Reverse back.
  # 3. Cut everything after the specified depth, so that each line
  #      contains only the relevant directory path
  # 4. Cut off the preceeding '.' unless that's all there is.
  # 5. Sort and group to unique lines with count.

  find -P . -type f \
      | rev | cut -d/ -f2- | rev \
      | cut -d/ -f1-$((${1:-1}+1)) \
      | cut -d/ -f2- \
      | sort | uniq -c
}

出力のようになります:

$ fc 0
1668 .

$ fc # depth of 1 is default
   6 .
   3 .ssh
  11 Desktop
  44 Downloads
1054 Music
 550 Pictures

もちろんの最初のできるパ sort:

$ fc | sort
   3 .ssh
   6 .
  11 Desktop
  44 Downloads
 550 Pictures
1054 Music

鉱山は高速タイプからョンをインストールして下さい。:)

ている他のご提案意を得ている場合はこの限りでは利用できる以上は次のうちどれでしょう?

find -name '*.jpg' | wc -l               # recursive


find -maxdepth 1 -name '*.jpg' | wc -l   # current directory only
#!/bin/bash
for dir in `find . -type d | grep -v "\.$"`; do
echo $dir
ls $dir/*.jpg | wc -l
done;

ずにでき外部コマンド:

for d in */; do 
  set -- "$d"*.jpg
  printf "%s: %d\n" "${d%/}" "$#"
done

ことができま awk (nawk または /usr/xpg4/bin/awkSolaris):

printf "%s\n" */*jpg |
  awk -F\/ 'END { 
    for (d in _) 
      print d ":",_[d] 
      }
  { _[$1]++ }'
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top