4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

指定したディレクトリ中にあるディレクトリ内のファイルの総数を数える

4
Posted at

きっかけ

  1. Dropboxに11GB以上のファイルを保存している
  2. PCを再起動する度に、Dropboxがファイルのインデックスを作成する
  3. 6万近い数のファイルのインデックスを作成するのはすごく時間がかかる :boom:
  4. 不要なファイルをDropboxの管理外に置きたいが、どのディレクトリにファイルが多いのかわからない

コマンド

find . -maxdepth 1 -type directory | xargs -I%% sh -c 'echo "%%" ; find "%%" -type file | wc -l'
  1. カレントディレクトリ内のディレクトリの一覧を作成
  2. 各ディレクトリごとに、ファイルの一覧を作成
  • この時、どのディレクトリに対して行っているか分かるようにechoする
  1. ファイルの一覧を元に、行数カウントをして、ファイルの総数を出力する
  • どこにファイルが多いか知りたいだけなので、空白行などの誤差は無視している
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?