file
必要なファイルタイプ情報を取得するには、間違いなく正しい選択です。その出力をls
私が使用する出力と組み合わせるにはfind
:
find -maxdepth 1 -type f -ls -exec file -b {} \;
これにより、現在のディレクトリ内のすべてのファイルが検索さls -dils
れ、その出力とその出力がfile -b
それぞれ独自の行に出力されます。出力例:
2757145 4 -rw-rw-r-- 1 dessert dessert 914 Apr 26 14:02 ./some.html
HTML document, ASCII text
2757135 4 -rw-rw-r-- 1 dessert dessert 201 Apr 13 15:26 ./a_text_file
UTF-8 Unicode text, with CRLF, LF line terminators
ただし、filetype 行ではなくfiletype 列が必要な場合は、行間の改行文字を削除する方法を次に示します。
find -maxdepth 1 -type f -exec sh -c "ls -l {} | tr '\n' '\t'; file -b {}" \;
出力例:
-rw-rw-r-- 1 dessert dessert 914 Apr 26 14:02 ./some.html HTML document, ASCII text
-rw-rw-r-- 1 dessert dessert 201 Apr 13 15:26 ./a_text_file UTF-8 Unicode text, with CRLF, LF line terminators
その新しい列は非常に長いので、最初のカンマからすべてを削除してみましょう。
find -maxdepth 1 -type f -exec sh -c "ls -l {} | tr '\n' '\t'; file -b {} | cut -d, -f1" \;
その出力は次のようになります。
-rw-rw-r-- 1 dessert dessert 914 Apr 26 14:02 ./some.html HTML document
-rw-rw-r-- 1 dessert dessert 201 Apr 13 15:26 ./a_text_file UTF-8 Unicode text
これはあまり便利ではないので、どうalias
ですか?~/.bash_aliases
ファイルの次の行を使用してlsf
、現在のディレクトリの上記の出力を取得するために実行する必要があります。
alias lsf='find -maxdepth 1 -type f -exec sh -c "ls -l {} | tr '"'\n'"' '"'\t'"'; file -b {} | cut -d, -f1" \;'