ls
doesn't do this. Its job is to report on file metadata (permissions, timestamp, etc.), not on file contents. But file
itself does (combined with a shell wildcard to list all files):
file *
for the current directory, or
file /some/directory/*
in another directory.
If you want to combine metadata and file content information, you can combine the output of ls
and file
. One way is to arrange for two commands to list one file per line in the same order, and use the paste
utility to combine them — something like
paste <(ls -dlog -- *) <(file -b -- *)
(This uses process substitution, which is available in common interactive shells: bash, zsh, also in ksh93.) If you have the column
utility, it's a convenient way of aligning the columns:
paste <(ls -dlog -- *) <(file -b -- *) | column -ts $'\t'
If you want to output the fields in a different order, join
the fields on the file name instead. I do a bit of back-and-forth between spaces and tabs to cope with file names containing spaces and produce vertically aligned results.
join -t $'\t' -1 2 -2 1 <(ls -dlog -- * |
sed 's/^\([^ ][^ ]* *[^ ][^ ]* *[^ ][^ ]* *[^ ][^ ]* *[^ ][^ ]* *[^ ][^ ]*\) */\1\t/') \
<(file -- * | sed 's/: */\t/') |
column -ts $'\t'
file
, nowaday you can also usemimetype