I am ignorant as to whether ls
is capable of displaying a filetype column.
Doing a quick online search and searching the man
did not reveal such a capability. Is it capable of doing this?
Clarification: This is especially helpful if files do not have an extension.
Update
As of 2018-04-28 the answers have been quite interesting however they did not provide what I was looking for. More specifically,
file
does give the actual filetypes but it doesn't integrate well withls
. Specifically, I usels -lhtrpG --group-directories-first --color=always
ls -F
is anls
solution however it provides symbols not a column of actual filetypes.
For this reason I have not marked any of the answers as the answer I am looking for.
I think the best way to display a file type is using this command:
If you want to list the types of all files in a directory, just use:
For more details about the arguments, see:
file
is definitely the right choice to get the file type information you want. To combine its output with that ofls
I suggest to usefind
:This finds every file in the current directory and prints the output of
ls -dils
as well as the output offile -b
for it, each on an own line. Example output:But, as you don't want a filetype line but rather a filetype column, here's a way to get rid of the newline character between the lines:
Sample output:
That new column is quite long, so let's cut everything from the first comma:
The output of that looks like this:
This is not quite handy, so how about an
alias
? With the following line in your~/.bash_aliases
file you just need to runlsf
to get the above output for the current directory.For clarity, I'm going to point out that you can see the file type in a basic sense with
ls
, using the-F
flag (classify) which appends a symbol to the filename depending on its type:You can see that information slightly less cryptically displayed in the first letter of the output of
ls -l
, though. wjandrea's answer describes this in more detail.But I don't think this is what you mean by file type. The
ls
command does not look inside regular files - only at directory listings (which store filenames) and inodes (which store metadata, including the "type" in the sense mentioned earlier).So, the
ls
command cannot show the file type in the sense of whether it is a JPG image or a binary file or a text file or a LibreOffice document of some kind, because it does not have that information.For that, as singrium's answer points out, you need the
file
command, which looks at the first 50-100kB or so of files' contents to determine their type.One form of filetype is whether a file is a regular file, directory, device, symlink, etc.
ls
can show this using options-l
or-F
.Option
-l
will show the filetype as a single character at the start of a listing, e.g:Where
-
is a regular file,d
is a directory, andl
is a symlink.Option
-F
will show the filetype as a suffix, e.g:Where no suffix is a regular file,
/
is a directory, and@
is a symlink.More info on these is available in
info coreutils 'ls invocation'
, summed up here:For
-l
:For
-F
:here is another way using paste to merge two output of ls and file command