{"id":13595,"date":"2019-04-03T11:23:51","date_gmt":"2019-04-03T11:23:51","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13595"},"modified":"2019-04-03T11:23:51","modified_gmt":"2019-04-03T11:23:51","slug":"how-to-find-out-file-types-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/03\/how-to-find-out-file-types-in-linux\/","title":{"rendered":"How to Find Out File Types in Linux"},"content":{"rendered":"<p>The easiest way to determine the type of a file on any operating system is usually to look at its extension (for instance\u00a0<strong>.xml<\/strong>,\u00a0<strong>.sh<\/strong>,\u00a0<strong>.c<\/strong>,\u00a0<strong>.tar<\/strong>\u00a0etc..). What if a file doesn\u2019t have an extension, how can you determine its type?<\/p>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/find-linux-filesystem-type\/\" target=\"_blank\" rel=\"noopener\">7 Ways to Find Out File System Types in Linux<\/a><\/p>\n<p>Linux has a useful utility called\u00a0<strong>file<\/strong>\u00a0which carry out some tests on a specified file and prints the file type once a test is successful. In this short article, we will explain useful\u00a0<strong>file command<\/strong>\u00a0examples to determine a file type in Linux.<\/p>\n<p><strong>Note<\/strong>: To have all the options described in this article, you should be running file version\u00a0<strong>5.25<\/strong>\u00a0(available in\u00a0<strong>Ubuntu<\/strong>\u00a0repositories) or newer.\u00a0<strong>CentOS<\/strong>\u00a0repositories have an older version of\u00a0<strong>file<\/strong>\u00a0command (<strong>file-5.11<\/strong>) which lacks some options.<\/p>\n<p>You can run following command to verify the version of file utility as shown.<\/p>\n<pre><strong>$ file -v<\/strong>\r\n\r\nfile-5.33\r\nmagic file from \/etc\/magic:\/usr\/share\/misc\/magic\r\n<\/pre>\n<h3>Linux file Command Examples<\/h3>\n<p><strong>1.<\/strong>\u00a0The simplest\u00a0<strong>file command<\/strong>\u00a0is as follows where you just provide a file whose type you want to find out.<\/p>\n<pre>$ file etc\r\n<\/pre>\n<div id=\"attachment_30643\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/09\/Find-File-Type-in-Linux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30643\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/09\/Find-File-Type-in-Linux.png\" alt=\"Find File Type in Linux\" width=\"402\" height=\"59\" aria-describedby=\"caption-attachment-30643\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-30643\" class=\"wp-caption-text\">Find File Type in Linux<\/p>\n<\/div>\n<p><strong>2.<\/strong>\u00a0You can also pass the names of the files to be examined from a file (one per line), which you can specify using the\u00a0<code>-f<\/code>\u00a0flag as shown.<\/p>\n<pre>$ file -f files.list\r\n<\/pre>\n<div id=\"attachment_30644\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/09\/Find-File-Type-in-Filename.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30644\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/09\/Find-File-Type-in-Filename.png\" alt=\"Find Files Type in Filename List\" width=\"462\" height=\"173\" aria-describedby=\"caption-attachment-30644\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-30644\" class=\"wp-caption-text\">Find Files Type in Filename List<\/p>\n<\/div>\n<p><strong>3.<\/strong>\u00a0To make file work faster you can exclude a test (valid tests include apptype, ascii, encoding, tokens, cdf, compress, elf, soft and tar) from the list of tests made to determine the file type, use the\u00a0<code>-e<\/code>\u00a0flag as shown.<\/p>\n<pre>$ file -e ascii -e compress -e elf etc\r\n<\/pre>\n<p><strong>4.<\/strong>\u00a0The\u00a0<code>-s<\/code>\u00a0option causes file to also read block or character special files, for example.<\/p>\n<pre><strong>$ file -s \/dev\/sda<\/strong>\r\n\r\n\/dev\/sda: DOS\/MBR boot sector, extended partition table (last)\r\n<\/pre>\n<p><strong>5.<\/strong>\u00a0Adding the\u00a0<code>-z<\/code>\u00a0options instructs file to look inside compressed files.<\/p>\n<pre>$ file -z backup\r\n<\/pre>\n<div id=\"attachment_30645\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/09\/determine-compressed-files.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30645\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/09\/determine-compressed-files.png\" alt=\"Determine Compressed Files\" width=\"592\" height=\"59\" aria-describedby=\"caption-attachment-30645\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-30645\" class=\"wp-caption-text\">Determine Compressed Files<\/p>\n<\/div>\n<p><strong>6.<\/strong>\u00a0If you want to report information about the contents only not the compression, of a compressed file, use the\u00a0<code>-Z<\/code>\u00a0flag.<\/p>\n<pre>$ file -Z backup\r\n<\/pre>\n<p><strong>7.<\/strong>\u00a0You can tell file command to output mime type strings instead of the more traditional human readable ones, using the\u00a0<code>-i<\/code>\u00a0option.<\/p>\n<pre><strong>$ file -i -s \/dev\/sda<\/strong>\r\n\r\n\/dev\/sda: application\/octet-stream; charset=binary\r\n<\/pre>\n<p><strong>8.<\/strong>\u00a0In addition, you can get a slash-separated list of valid extensions for the file type found by adding the\u00a0<strong>\u2013extension<\/strong>\u00a0switch.<\/p>\n<pre>$ file --extension \/dev\/sda\r\n<\/pre>\n<p>For more information and usage options, consult the\u00a0<strong>file command<\/strong>\u00a0man page.<\/p>\n<pre>$ man file\r\n<\/pre>\n<p>That\u2019s all!\u00a0<strong>file command<\/strong>\u00a0is a useful Linux utility to determine the type of a file without an extension. In this article, we shared some useful file command examples. If you have any questions or thoughts to share, use the feedback form below to reach us.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/find-file-types-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The easiest way to determine the type of a file on any operating system is usually to look at its extension (for instance\u00a0.xml,\u00a0.sh,\u00a0.c,\u00a0.tar\u00a0etc..). What if a file doesn\u2019t have an extension, how can you determine its type? Read Also:\u00a07 Ways to Find Out File System Types in Linux Linux has a useful utility called\u00a0file\u00a0which carry &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/03\/how-to-find-out-file-types-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Find Out File Types in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13595","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13595","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13595"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13595\/revisions"}],"predecessor-version":[{"id":13596,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13595\/revisions\/13596"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13595"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13595"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13595"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}