One form of filetype is whether a file is a regular file, directory, device, symlink, etc. 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.įor 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. 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). wjandrea's answer describes this in more detail.īut I don't think this is what you mean by file type. You can see that information slightly less cryptically displayed in the first letter of the output of ls -l, though. ‘|’ for FIFOs, ‘=’ for sockets, ‘>’ for doors, and nothing for Type indicators are ‘/’ for directories, for symbolic links, To combine its output with that of ls I suggest to use find: find -maxdepth 1 -type f -ls -exec file -b | cut -d, -f1" \ 'įor 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’Īppend a character to each file name indicating the file type.Īlso, for regular files that are executable, append ‘*’. File is definitely the right choice to get the file type information you want.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |