LoginSignup
0
0

More than 1 year has passed since last update.

Bashでシンプルなファイル一覧のCSVを作る

Last updated at Posted at 2022-04-20
create-file-list.sh
#!/bin/bash

# 1行目
lines="path,size (byte),MIME type\n"

# 出力ファイル名
output_filename='./file-list.csv'

for file in $(find -type f | sort); do
  # このファイルと出力ファイルを除外
  if test $file = $0 -o $file = $output_filename; then
    continue
  fi

  # 1行目の内容に沿った要素の準備
  path=$file
  size=$(ls -lh $file | awk '{ print $5 }')
  mime_type=$(file --mime-type $file | awk '{ print $2 }')

  # 行を整形
  line="$path,$size,$mime_type\n"

  # 行を追加
  lines="$lines$line"
done

# ファイルを出力
echo -e $lines >$output_filename

適宜置き換える

0
0
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
0
0