How to list files on terminal so that we can see the file types such executable, ascii etc

command linefile-commandfilesls

I have been trying to list files in directory using ls and passing it different options.

Does it have the ability to list types of files as well ? I want to know which ones are executable , sharedlibs or just ascii files without doing file command on individual files.

Best Answer

ls itself won't show this information.

You can pipe the output of the find to file -f -, as follows:

$ find /usr/local/bin | file -f -
/usr/local/bin:              directory 
/usr/local/bin/apt:                  Python script, ASCII text executable
/usr/local/bin/mint-md5sum:                          ASCII text
/usr/local/bin/search:                     Bourne-Again shell script, ASCII text executable
/usr/local/bin/gnome-help:                         Python script, ASCII text executable
/usr/local/bin/office-vb.sh:                           ASCII text
/usr/local/bin/pastebin:                       Python script, ASCII text executable
/usr/local/bin/highlight:                        POSIX shell script, ASCII text executable
/usr/local/bin/yelp:                   Python script, ASCII text executable

Note that find is used instead of ls as it will print the full path, whereas ls will only print the file name. Therefore, if you simply need to do this with the files in your current directory, then:

ls | file -f -

would work.

Related Question