How do I display filetype with ls?
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
up vote
8
down vote
favorite
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.
command-line ls
add a comment |Â
up vote
8
down vote
favorite
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.
command-line ls
2
Related: How can I show all file types contained in a directory?
â dessert
Apr 26 at 18:59
add a comment |Â
up vote
8
down vote
favorite
up vote
8
down vote
favorite
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.
command-line ls
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.
command-line ls
edited Apr 29 at 22:00
asked Apr 26 at 18:52
user10853
4711423
4711423
2
Related: How can I show all file types contained in a directory?
â dessert
Apr 26 at 18:59
add a comment |Â
2
Related: How can I show all file types contained in a directory?
â dessert
Apr 26 at 18:59
2
2
Related: How can I show all file types contained in a directory?
â dessert
Apr 26 at 18:59
Related: How can I show all file types contained in a directory?
â dessert
Apr 26 at 18:59
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
11
down vote
file
is definitely the right choice to get the file type information you want. To combine its output with that of ls
I suggest to use find
:
find -maxdepth 1 -type f -ls -exec file -b ;
This finds every file in the current directory and prints the output of ls -dils
as well as the output of file -b
for it, each on an own line. Example output:
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
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:
find -maxdepth 1 -type f -exec sh -c "ls -l | tr 'n' 't'; file -b " ;
Sample output:
-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
That new column is quite long, so let's cut everything from the first comma:
find -maxdepth 1 -type f -exec sh -c "ls -l | tr 'n' 't'; file -b | cut -d, -f1" ;
The output of that looks like this:
-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
This is not quite handy, so how about an alias
? With the following line in your ~/.bash_aliases
file you just need to run lsf
to get the above output for the current directory.
alias lsf='find -maxdepth 1 -type f -exec sh -c "ls -l | tr '"'n'"' '"'t'"'; file -b | cut -d, -f1" ;'
If you use a function instead of an alias, that will be less of a quoting hell, and if you usepaste
orcolumn
, you could get better alignment:lsf () cut -d, -f1)' _ + ;
The alignment issue is not evident in the answer because of the similar sizes and dates. (This will also be slightly faster, since the commands will be invoked fewer times instead of once per file.)
â muru
Apr 27 at 10:11
@muru Thanks for the many good suggestions! Does thiscolumn
aproach work for you? It just prints the output ofls -l
for every file followed byfile
's output for every file for me, as if the shell would just dols -l "$@"; file -b "$@" | cut -d, -f1
â¦
â dessert
Apr 27 at 11:38
It does. paste.ubuntu.com/p/KjPthXPDPb - the top part is from the alias and the bottom part is the function, both run from/etc
.
â muru
Apr 27 at 12:46
I think I see the problem - ifcolumn
's output is not to the terminal, you need to specify the column count or it will output the files one after the other; socolumn -c "$COLUMNS" ...
should work in either case.
â muru
Apr 27 at 12:48
You are launching (at least?) 5 processes for each file, so this is probably going to be slow when there are lots of files in a directoryâ¦
â JanC
Apr 27 at 19:28
 |Â
show 2 more comments
up vote
7
down vote
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:
âÂÂ-FâÂÂ
âÂÂ--classifyâÂÂ
âÂÂ--indicator-style=classifyâÂÂ
Append a character to each file name indicating the file type.
Also, for regular files that are executable, append âÂÂ*âÂÂ. The file
type indicators are âÂÂ/â for directories, âÂÂ@â for symbolic links,
âÂÂ|â for FIFOs, âÂÂ=â for sockets, âÂÂ>â for doors, and nothing for
regular files.
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.
3
file
just uses magic
â dessert
Apr 26 at 20:33
@Zana Thank you for raising my attention to this flag. This would do it for now though it is not what I was looking for (actual filetypes). For this I will vote it up.
â user10853
Apr 29 at 21:55
add a comment |Â
up vote
6
down vote
I think the best way to display a file type is using this command:
file <filename>
If you want to list the types of all files in a directory, just use:
file *
For more details about the arguments, see:
man file
While this answer doesnt directly respond to the OP's question, it shows the correct way of finding the mime type of a file and should be marked as the correct answer. To get themime type
only, use:file --mime-type filename
.
â Pedro Lobito
Apr 26 at 23:56
@PedroLobito I think the closely related question coversfile
quite well, but this question is different.
â dessert
Apr 27 at 8:06
I vote this answer up given that you were the first to give afile
answer. As I replied to the others this doesn't suffice (it needs to be integrated with ls) so I keep it at a vote up. Thank you.
â user10853
Apr 29 at 21:57
add a comment |Â
up vote
3
down vote
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:$ ls -l
drwxrwxr-x 2 user user 4096 Dec 11 00:18 DIR
-rw-rw-r-- 1 user user 0 Dec 11 00:18 FILE
lrwxrwxrwx 1 user user 4 Dec 11 00:19 LINK -> FILEWhere
-
is a regular file,d
is a directory, andl
is a symlink.Option
-F
will show the filetype as a suffix, e.g:$ ls -F
DIR/ FILE LINK@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
:
âÂÂ-â regular file
âÂÂbâ block special file
âÂÂcâ character special file
âÂÂCâ high performance (âÂÂcontiguous dataâÂÂ) file
âÂÂdâ directory
âÂÂDâ door (Solaris 2.5 and up)
âÂÂlâ symbolic link
âÂÂMâ off-line (âÂÂmigratedâÂÂ) file (Cray DMF)
âÂÂnâ network special file (HP-UX)
âÂÂpâ FIFO (named pipe)
âÂÂPâ port (Solaris 10 and up)
âÂÂsâ socket
âÂÂ?â some other file type
For -F
:
nothing for regular files
âÂÂ*â regular files that are executable
âÂÂ/â directories
âÂÂ@â symbolic links
âÂÂ|â FIFOs
âÂÂ=â sockets
âÂÂ>â doors
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
11
down vote
file
is definitely the right choice to get the file type information you want. To combine its output with that of ls
I suggest to use find
:
find -maxdepth 1 -type f -ls -exec file -b ;
This finds every file in the current directory and prints the output of ls -dils
as well as the output of file -b
for it, each on an own line. Example output:
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
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:
find -maxdepth 1 -type f -exec sh -c "ls -l | tr 'n' 't'; file -b " ;
Sample output:
-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
That new column is quite long, so let's cut everything from the first comma:
find -maxdepth 1 -type f -exec sh -c "ls -l | tr 'n' 't'; file -b | cut -d, -f1" ;
The output of that looks like this:
-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
This is not quite handy, so how about an alias
? With the following line in your ~/.bash_aliases
file you just need to run lsf
to get the above output for the current directory.
alias lsf='find -maxdepth 1 -type f -exec sh -c "ls -l | tr '"'n'"' '"'t'"'; file -b | cut -d, -f1" ;'
If you use a function instead of an alias, that will be less of a quoting hell, and if you usepaste
orcolumn
, you could get better alignment:lsf () cut -d, -f1)' _ + ;
The alignment issue is not evident in the answer because of the similar sizes and dates. (This will also be slightly faster, since the commands will be invoked fewer times instead of once per file.)
â muru
Apr 27 at 10:11
@muru Thanks for the many good suggestions! Does thiscolumn
aproach work for you? It just prints the output ofls -l
for every file followed byfile
's output for every file for me, as if the shell would just dols -l "$@"; file -b "$@" | cut -d, -f1
â¦
â dessert
Apr 27 at 11:38
It does. paste.ubuntu.com/p/KjPthXPDPb - the top part is from the alias and the bottom part is the function, both run from/etc
.
â muru
Apr 27 at 12:46
I think I see the problem - ifcolumn
's output is not to the terminal, you need to specify the column count or it will output the files one after the other; socolumn -c "$COLUMNS" ...
should work in either case.
â muru
Apr 27 at 12:48
You are launching (at least?) 5 processes for each file, so this is probably going to be slow when there are lots of files in a directoryâ¦
â JanC
Apr 27 at 19:28
 |Â
show 2 more comments
up vote
11
down vote
file
is definitely the right choice to get the file type information you want. To combine its output with that of ls
I suggest to use find
:
find -maxdepth 1 -type f -ls -exec file -b ;
This finds every file in the current directory and prints the output of ls -dils
as well as the output of file -b
for it, each on an own line. Example output:
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
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:
find -maxdepth 1 -type f -exec sh -c "ls -l | tr 'n' 't'; file -b " ;
Sample output:
-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
That new column is quite long, so let's cut everything from the first comma:
find -maxdepth 1 -type f -exec sh -c "ls -l | tr 'n' 't'; file -b | cut -d, -f1" ;
The output of that looks like this:
-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
This is not quite handy, so how about an alias
? With the following line in your ~/.bash_aliases
file you just need to run lsf
to get the above output for the current directory.
alias lsf='find -maxdepth 1 -type f -exec sh -c "ls -l | tr '"'n'"' '"'t'"'; file -b | cut -d, -f1" ;'
If you use a function instead of an alias, that will be less of a quoting hell, and if you usepaste
orcolumn
, you could get better alignment:lsf () cut -d, -f1)' _ + ;
The alignment issue is not evident in the answer because of the similar sizes and dates. (This will also be slightly faster, since the commands will be invoked fewer times instead of once per file.)
â muru
Apr 27 at 10:11
@muru Thanks for the many good suggestions! Does thiscolumn
aproach work for you? It just prints the output ofls -l
for every file followed byfile
's output for every file for me, as if the shell would just dols -l "$@"; file -b "$@" | cut -d, -f1
â¦
â dessert
Apr 27 at 11:38
It does. paste.ubuntu.com/p/KjPthXPDPb - the top part is from the alias and the bottom part is the function, both run from/etc
.
â muru
Apr 27 at 12:46
I think I see the problem - ifcolumn
's output is not to the terminal, you need to specify the column count or it will output the files one after the other; socolumn -c "$COLUMNS" ...
should work in either case.
â muru
Apr 27 at 12:48
You are launching (at least?) 5 processes for each file, so this is probably going to be slow when there are lots of files in a directoryâ¦
â JanC
Apr 27 at 19:28
 |Â
show 2 more comments
up vote
11
down vote
up vote
11
down vote
file
is definitely the right choice to get the file type information you want. To combine its output with that of ls
I suggest to use find
:
find -maxdepth 1 -type f -ls -exec file -b ;
This finds every file in the current directory and prints the output of ls -dils
as well as the output of file -b
for it, each on an own line. Example output:
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
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:
find -maxdepth 1 -type f -exec sh -c "ls -l | tr 'n' 't'; file -b " ;
Sample output:
-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
That new column is quite long, so let's cut everything from the first comma:
find -maxdepth 1 -type f -exec sh -c "ls -l | tr 'n' 't'; file -b | cut -d, -f1" ;
The output of that looks like this:
-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
This is not quite handy, so how about an alias
? With the following line in your ~/.bash_aliases
file you just need to run lsf
to get the above output for the current directory.
alias lsf='find -maxdepth 1 -type f -exec sh -c "ls -l | tr '"'n'"' '"'t'"'; file -b | cut -d, -f1" ;'
file
is definitely the right choice to get the file type information you want. To combine its output with that of ls
I suggest to use find
:
find -maxdepth 1 -type f -ls -exec file -b ;
This finds every file in the current directory and prints the output of ls -dils
as well as the output of file -b
for it, each on an own line. Example output:
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
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:
find -maxdepth 1 -type f -exec sh -c "ls -l | tr 'n' 't'; file -b " ;
Sample output:
-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
That new column is quite long, so let's cut everything from the first comma:
find -maxdepth 1 -type f -exec sh -c "ls -l | tr 'n' 't'; file -b | cut -d, -f1" ;
The output of that looks like this:
-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
This is not quite handy, so how about an alias
? With the following line in your ~/.bash_aliases
file you just need to run lsf
to get the above output for the current directory.
alias lsf='find -maxdepth 1 -type f -exec sh -c "ls -l | tr '"'n'"' '"'t'"'; file -b | cut -d, -f1" ;'
edited Apr 27 at 7:50
answered Apr 26 at 20:27
![](https://i.stack.imgur.com/9L8vd.png?s=32&g=1)
![](https://i.stack.imgur.com/9L8vd.png?s=32&g=1)
dessert
19.8k55594
19.8k55594
If you use a function instead of an alias, that will be less of a quoting hell, and if you usepaste
orcolumn
, you could get better alignment:lsf () cut -d, -f1)' _ + ;
The alignment issue is not evident in the answer because of the similar sizes and dates. (This will also be slightly faster, since the commands will be invoked fewer times instead of once per file.)
â muru
Apr 27 at 10:11
@muru Thanks for the many good suggestions! Does thiscolumn
aproach work for you? It just prints the output ofls -l
for every file followed byfile
's output for every file for me, as if the shell would just dols -l "$@"; file -b "$@" | cut -d, -f1
â¦
â dessert
Apr 27 at 11:38
It does. paste.ubuntu.com/p/KjPthXPDPb - the top part is from the alias and the bottom part is the function, both run from/etc
.
â muru
Apr 27 at 12:46
I think I see the problem - ifcolumn
's output is not to the terminal, you need to specify the column count or it will output the files one after the other; socolumn -c "$COLUMNS" ...
should work in either case.
â muru
Apr 27 at 12:48
You are launching (at least?) 5 processes for each file, so this is probably going to be slow when there are lots of files in a directoryâ¦
â JanC
Apr 27 at 19:28
 |Â
show 2 more comments
If you use a function instead of an alias, that will be less of a quoting hell, and if you usepaste
orcolumn
, you could get better alignment:lsf () cut -d, -f1)' _ + ;
The alignment issue is not evident in the answer because of the similar sizes and dates. (This will also be slightly faster, since the commands will be invoked fewer times instead of once per file.)
â muru
Apr 27 at 10:11
@muru Thanks for the many good suggestions! Does thiscolumn
aproach work for you? It just prints the output ofls -l
for every file followed byfile
's output for every file for me, as if the shell would just dols -l "$@"; file -b "$@" | cut -d, -f1
â¦
â dessert
Apr 27 at 11:38
It does. paste.ubuntu.com/p/KjPthXPDPb - the top part is from the alias and the bottom part is the function, both run from/etc
.
â muru
Apr 27 at 12:46
I think I see the problem - ifcolumn
's output is not to the terminal, you need to specify the column count or it will output the files one after the other; socolumn -c "$COLUMNS" ...
should work in either case.
â muru
Apr 27 at 12:48
You are launching (at least?) 5 processes for each file, so this is probably going to be slow when there are lots of files in a directoryâ¦
â JanC
Apr 27 at 19:28
If you use a function instead of an alias, that will be less of a quoting hell, and if you use
paste
or column
, you could get better alignment: lsf () cut -d, -f1)' _ + ;
The alignment issue is not evident in the answer because of the similar sizes and dates. (This will also be slightly faster, since the commands will be invoked fewer times instead of once per file.)â muru
Apr 27 at 10:11
If you use a function instead of an alias, that will be less of a quoting hell, and if you use
paste
or column
, you could get better alignment: lsf () cut -d, -f1)' _ + ;
The alignment issue is not evident in the answer because of the similar sizes and dates. (This will also be slightly faster, since the commands will be invoked fewer times instead of once per file.)â muru
Apr 27 at 10:11
@muru Thanks for the many good suggestions! Does this
column
aproach work for you? It just prints the output of ls -l
for every file followed by file
's output for every file for me, as if the shell would just do ls -l "$@"; file -b "$@" | cut -d, -f1
â¦â dessert
Apr 27 at 11:38
@muru Thanks for the many good suggestions! Does this
column
aproach work for you? It just prints the output of ls -l
for every file followed by file
's output for every file for me, as if the shell would just do ls -l "$@"; file -b "$@" | cut -d, -f1
â¦â dessert
Apr 27 at 11:38
It does. paste.ubuntu.com/p/KjPthXPDPb - the top part is from the alias and the bottom part is the function, both run from
/etc
.â muru
Apr 27 at 12:46
It does. paste.ubuntu.com/p/KjPthXPDPb - the top part is from the alias and the bottom part is the function, both run from
/etc
.â muru
Apr 27 at 12:46
I think I see the problem - if
column
's output is not to the terminal, you need to specify the column count or it will output the files one after the other; so column -c "$COLUMNS" ...
should work in either case.â muru
Apr 27 at 12:48
I think I see the problem - if
column
's output is not to the terminal, you need to specify the column count or it will output the files one after the other; so column -c "$COLUMNS" ...
should work in either case.â muru
Apr 27 at 12:48
You are launching (at least?) 5 processes for each file, so this is probably going to be slow when there are lots of files in a directoryâ¦
â JanC
Apr 27 at 19:28
You are launching (at least?) 5 processes for each file, so this is probably going to be slow when there are lots of files in a directoryâ¦
â JanC
Apr 27 at 19:28
 |Â
show 2 more comments
up vote
7
down vote
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:
âÂÂ-FâÂÂ
âÂÂ--classifyâÂÂ
âÂÂ--indicator-style=classifyâÂÂ
Append a character to each file name indicating the file type.
Also, for regular files that are executable, append âÂÂ*âÂÂ. The file
type indicators are âÂÂ/â for directories, âÂÂ@â for symbolic links,
âÂÂ|â for FIFOs, âÂÂ=â for sockets, âÂÂ>â for doors, and nothing for
regular files.
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.
3
file
just uses magic
â dessert
Apr 26 at 20:33
@Zana Thank you for raising my attention to this flag. This would do it for now though it is not what I was looking for (actual filetypes). For this I will vote it up.
â user10853
Apr 29 at 21:55
add a comment |Â
up vote
7
down vote
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:
âÂÂ-FâÂÂ
âÂÂ--classifyâÂÂ
âÂÂ--indicator-style=classifyâÂÂ
Append a character to each file name indicating the file type.
Also, for regular files that are executable, append âÂÂ*âÂÂ. The file
type indicators are âÂÂ/â for directories, âÂÂ@â for symbolic links,
âÂÂ|â for FIFOs, âÂÂ=â for sockets, âÂÂ>â for doors, and nothing for
regular files.
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.
3
file
just uses magic
â dessert
Apr 26 at 20:33
@Zana Thank you for raising my attention to this flag. This would do it for now though it is not what I was looking for (actual filetypes). For this I will vote it up.
â user10853
Apr 29 at 21:55
add a comment |Â
up vote
7
down vote
up vote
7
down vote
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:
âÂÂ-FâÂÂ
âÂÂ--classifyâÂÂ
âÂÂ--indicator-style=classifyâÂÂ
Append a character to each file name indicating the file type.
Also, for regular files that are executable, append âÂÂ*âÂÂ. The file
type indicators are âÂÂ/â for directories, âÂÂ@â for symbolic links,
âÂÂ|â for FIFOs, âÂÂ=â for sockets, âÂÂ>â for doors, and nothing for
regular files.
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.
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:
âÂÂ-FâÂÂ
âÂÂ--classifyâÂÂ
âÂÂ--indicator-style=classifyâÂÂ
Append a character to each file name indicating the file type.
Also, for regular files that are executable, append âÂÂ*âÂÂ. The file
type indicators are âÂÂ/â for directories, âÂÂ@â for symbolic links,
âÂÂ|â for FIFOs, âÂÂ=â for sockets, âÂÂ>â for doors, and nothing for
regular files.
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.
edited Apr 27 at 8:42
answered Apr 26 at 20:13
![](https://i.stack.imgur.com/8CW8e.png?s=32&g=1)
![](https://i.stack.imgur.com/8CW8e.png?s=32&g=1)
Zanna
48k13119227
48k13119227
3
file
just uses magic
â dessert
Apr 26 at 20:33
@Zana Thank you for raising my attention to this flag. This would do it for now though it is not what I was looking for (actual filetypes). For this I will vote it up.
â user10853
Apr 29 at 21:55
add a comment |Â
3
file
just uses magic
â dessert
Apr 26 at 20:33
@Zana Thank you for raising my attention to this flag. This would do it for now though it is not what I was looking for (actual filetypes). For this I will vote it up.
â user10853
Apr 29 at 21:55
3
3
file
just uses magicâ dessert
Apr 26 at 20:33
file
just uses magicâ dessert
Apr 26 at 20:33
@Zana Thank you for raising my attention to this flag. This would do it for now though it is not what I was looking for (actual filetypes). For this I will vote it up.
â user10853
Apr 29 at 21:55
@Zana Thank you for raising my attention to this flag. This would do it for now though it is not what I was looking for (actual filetypes). For this I will vote it up.
â user10853
Apr 29 at 21:55
add a comment |Â
up vote
6
down vote
I think the best way to display a file type is using this command:
file <filename>
If you want to list the types of all files in a directory, just use:
file *
For more details about the arguments, see:
man file
While this answer doesnt directly respond to the OP's question, it shows the correct way of finding the mime type of a file and should be marked as the correct answer. To get themime type
only, use:file --mime-type filename
.
â Pedro Lobito
Apr 26 at 23:56
@PedroLobito I think the closely related question coversfile
quite well, but this question is different.
â dessert
Apr 27 at 8:06
I vote this answer up given that you were the first to give afile
answer. As I replied to the others this doesn't suffice (it needs to be integrated with ls) so I keep it at a vote up. Thank you.
â user10853
Apr 29 at 21:57
add a comment |Â
up vote
6
down vote
I think the best way to display a file type is using this command:
file <filename>
If you want to list the types of all files in a directory, just use:
file *
For more details about the arguments, see:
man file
While this answer doesnt directly respond to the OP's question, it shows the correct way of finding the mime type of a file and should be marked as the correct answer. To get themime type
only, use:file --mime-type filename
.
â Pedro Lobito
Apr 26 at 23:56
@PedroLobito I think the closely related question coversfile
quite well, but this question is different.
â dessert
Apr 27 at 8:06
I vote this answer up given that you were the first to give afile
answer. As I replied to the others this doesn't suffice (it needs to be integrated with ls) so I keep it at a vote up. Thank you.
â user10853
Apr 29 at 21:57
add a comment |Â
up vote
6
down vote
up vote
6
down vote
I think the best way to display a file type is using this command:
file <filename>
If you want to list the types of all files in a directory, just use:
file *
For more details about the arguments, see:
man file
I think the best way to display a file type is using this command:
file <filename>
If you want to list the types of all files in a directory, just use:
file *
For more details about the arguments, see:
man file
edited Apr 27 at 8:01
![](https://i.stack.imgur.com/9L8vd.png?s=32&g=1)
![](https://i.stack.imgur.com/9L8vd.png?s=32&g=1)
dessert
19.8k55594
19.8k55594
answered Apr 26 at 19:01
singrium
616113
616113
While this answer doesnt directly respond to the OP's question, it shows the correct way of finding the mime type of a file and should be marked as the correct answer. To get themime type
only, use:file --mime-type filename
.
â Pedro Lobito
Apr 26 at 23:56
@PedroLobito I think the closely related question coversfile
quite well, but this question is different.
â dessert
Apr 27 at 8:06
I vote this answer up given that you were the first to give afile
answer. As I replied to the others this doesn't suffice (it needs to be integrated with ls) so I keep it at a vote up. Thank you.
â user10853
Apr 29 at 21:57
add a comment |Â
While this answer doesnt directly respond to the OP's question, it shows the correct way of finding the mime type of a file and should be marked as the correct answer. To get themime type
only, use:file --mime-type filename
.
â Pedro Lobito
Apr 26 at 23:56
@PedroLobito I think the closely related question coversfile
quite well, but this question is different.
â dessert
Apr 27 at 8:06
I vote this answer up given that you were the first to give afile
answer. As I replied to the others this doesn't suffice (it needs to be integrated with ls) so I keep it at a vote up. Thank you.
â user10853
Apr 29 at 21:57
While this answer doesnt directly respond to the OP's question, it shows the correct way of finding the mime type of a file and should be marked as the correct answer. To get the
mime type
only, use: file --mime-type filename
.â Pedro Lobito
Apr 26 at 23:56
While this answer doesnt directly respond to the OP's question, it shows the correct way of finding the mime type of a file and should be marked as the correct answer. To get the
mime type
only, use: file --mime-type filename
.â Pedro Lobito
Apr 26 at 23:56
@PedroLobito I think the closely related question covers
file
quite well, but this question is different.â dessert
Apr 27 at 8:06
@PedroLobito I think the closely related question covers
file
quite well, but this question is different.â dessert
Apr 27 at 8:06
I vote this answer up given that you were the first to give a
file
answer. As I replied to the others this doesn't suffice (it needs to be integrated with ls) so I keep it at a vote up. Thank you.â user10853
Apr 29 at 21:57
I vote this answer up given that you were the first to give a
file
answer. As I replied to the others this doesn't suffice (it needs to be integrated with ls) so I keep it at a vote up. Thank you.â user10853
Apr 29 at 21:57
add a comment |Â
up vote
3
down vote
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:$ ls -l
drwxrwxr-x 2 user user 4096 Dec 11 00:18 DIR
-rw-rw-r-- 1 user user 0 Dec 11 00:18 FILE
lrwxrwxrwx 1 user user 4 Dec 11 00:19 LINK -> FILEWhere
-
is a regular file,d
is a directory, andl
is a symlink.Option
-F
will show the filetype as a suffix, e.g:$ ls -F
DIR/ FILE LINK@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
:
âÂÂ-â regular file
âÂÂbâ block special file
âÂÂcâ character special file
âÂÂCâ high performance (âÂÂcontiguous dataâÂÂ) file
âÂÂdâ directory
âÂÂDâ door (Solaris 2.5 and up)
âÂÂlâ symbolic link
âÂÂMâ off-line (âÂÂmigratedâÂÂ) file (Cray DMF)
âÂÂnâ network special file (HP-UX)
âÂÂpâ FIFO (named pipe)
âÂÂPâ port (Solaris 10 and up)
âÂÂsâ socket
âÂÂ?â some other file type
For -F
:
nothing for regular files
âÂÂ*â regular files that are executable
âÂÂ/â directories
âÂÂ@â symbolic links
âÂÂ|â FIFOs
âÂÂ=â sockets
âÂÂ>â doors
add a comment |Â
up vote
3
down vote
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:$ ls -l
drwxrwxr-x 2 user user 4096 Dec 11 00:18 DIR
-rw-rw-r-- 1 user user 0 Dec 11 00:18 FILE
lrwxrwxrwx 1 user user 4 Dec 11 00:19 LINK -> FILEWhere
-
is a regular file,d
is a directory, andl
is a symlink.Option
-F
will show the filetype as a suffix, e.g:$ ls -F
DIR/ FILE LINK@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
:
âÂÂ-â regular file
âÂÂbâ block special file
âÂÂcâ character special file
âÂÂCâ high performance (âÂÂcontiguous dataâÂÂ) file
âÂÂdâ directory
âÂÂDâ door (Solaris 2.5 and up)
âÂÂlâ symbolic link
âÂÂMâ off-line (âÂÂmigratedâÂÂ) file (Cray DMF)
âÂÂnâ network special file (HP-UX)
âÂÂpâ FIFO (named pipe)
âÂÂPâ port (Solaris 10 and up)
âÂÂsâ socket
âÂÂ?â some other file type
For -F
:
nothing for regular files
âÂÂ*â regular files that are executable
âÂÂ/â directories
âÂÂ@â symbolic links
âÂÂ|â FIFOs
âÂÂ=â sockets
âÂÂ>â doors
add a comment |Â
up vote
3
down vote
up vote
3
down vote
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:$ ls -l
drwxrwxr-x 2 user user 4096 Dec 11 00:18 DIR
-rw-rw-r-- 1 user user 0 Dec 11 00:18 FILE
lrwxrwxrwx 1 user user 4 Dec 11 00:19 LINK -> FILEWhere
-
is a regular file,d
is a directory, andl
is a symlink.Option
-F
will show the filetype as a suffix, e.g:$ ls -F
DIR/ FILE LINK@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
:
âÂÂ-â regular file
âÂÂbâ block special file
âÂÂcâ character special file
âÂÂCâ high performance (âÂÂcontiguous dataâÂÂ) file
âÂÂdâ directory
âÂÂDâ door (Solaris 2.5 and up)
âÂÂlâ symbolic link
âÂÂMâ off-line (âÂÂmigratedâÂÂ) file (Cray DMF)
âÂÂnâ network special file (HP-UX)
âÂÂpâ FIFO (named pipe)
âÂÂPâ port (Solaris 10 and up)
âÂÂsâ socket
âÂÂ?â some other file type
For -F
:
nothing for regular files
âÂÂ*â regular files that are executable
âÂÂ/â directories
âÂÂ@â symbolic links
âÂÂ|â FIFOs
âÂÂ=â sockets
âÂÂ>â doors
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:$ ls -l
drwxrwxr-x 2 user user 4096 Dec 11 00:18 DIR
-rw-rw-r-- 1 user user 0 Dec 11 00:18 FILE
lrwxrwxrwx 1 user user 4 Dec 11 00:19 LINK -> FILEWhere
-
is a regular file,d
is a directory, andl
is a symlink.Option
-F
will show the filetype as a suffix, e.g:$ ls -F
DIR/ FILE LINK@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
:
âÂÂ-â regular file
âÂÂbâ block special file
âÂÂcâ character special file
âÂÂCâ high performance (âÂÂcontiguous dataâÂÂ) file
âÂÂdâ directory
âÂÂDâ door (Solaris 2.5 and up)
âÂÂlâ symbolic link
âÂÂMâ off-line (âÂÂmigratedâÂÂ) file (Cray DMF)
âÂÂnâ network special file (HP-UX)
âÂÂpâ FIFO (named pipe)
âÂÂPâ port (Solaris 10 and up)
âÂÂsâ socket
âÂÂ?â some other file type
For -F
:
nothing for regular files
âÂÂ*â regular files that are executable
âÂÂ/â directories
âÂÂ@â symbolic links
âÂÂ|â FIFOs
âÂÂ=â sockets
âÂÂ>â doors
edited Apr 26 at 20:54
answered Apr 26 at 20:44
![](https://i.stack.imgur.com/eVuAv.png?s=32&g=1)
![](https://i.stack.imgur.com/eVuAv.png?s=32&g=1)
wjandrea
7,15342255
7,15342255
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1028506%2fhow-do-i-display-filetype-with-ls%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
Related: How can I show all file types contained in a directory?
â dessert
Apr 26 at 18:59