LoginSignup
2
1

More than 3 years have passed since last update.

ShellScript ls コマンド で 得られた ファイルとフォルダ の 個数 を 出力する

Posted at

目的

  • ShellScriptでlsコマンドの結果として得られたファイルとフォルダの個数を出力する方法を知る。

書き方の例

  • 下記にShellScriptの処理を記載する。
変数=(`ls`)
echo ${#変数[*]}

より具体的な例

  • フォルダ/home/miriwo/work直下のフォルダとファイルの数を出力する。
  • 下記にShellScriptの処理を記載する。
# ディレクトリ数、ファイル数を知りたいディレクトリに移動
cd /home/miriwo/work

# lsコマンドの結果を変数ls_resultに格納
ls_result=(`ls`)

# 結果数を格納した内容を出力する
echo ${#ls_result[*]}
2
1
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
2
1