• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

Linux File Command With Example

Written by Admin, Updated On June 12, 2019
file, linux commands, terminal
Linux File Command

File command in Linux used to determine the type of a file. Generally users are assume file type by looking at extension of file. For example when you see a file with an extension of gif, jpg, bmp, or png you think of an image file. File command helps you when you don’t know the file format or the file does not have a file extension.

Basic Syntax#

Below is the basic syntax of Linux file command:

file [OPTION] [FILE]

Where,

  • OPTION and additional option which you can pass along with file command.
  • FILE is the name of file or files.

How to Use file Command to Find File Type#

The file command differentiate files based on first set of tests to return a valid response causes the file type to be printed.

If you will use file command without any option then it will display the file name along with the file type:

file /etc/timezone

It will return output as below:

Output
/etc/timezone: ASCII text

If you want to show just file type then pass -b option along with command:

file -b /etc/timezone

It will show output as below and you can see that /etc/timezone file is a text file.

Output
ASCII text

How to Find File Type of Multiple Files#

To get type of multiple files you can pass more than one files along with command as following:

file /etc/timezone /etc/ucf.conf

It will print output in separate line for each file as following:

Output
/etc/timezone: ASCII text /etc/ucf.conf: ASCII text

How to View the Mime Type of a File#

You can determine the mime type of a file by passing -i (--mime)option along with command:

file -i /var/www/index.html
Output
/var/www/index.html: text/html; charset=us-ascii

Conclusion#

By this tutorial you have successfully learned how to use the Linux file command. If you want to learn more about file command visit file man page.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article Uptime Command in Linux With Example
Next Article   How to Install and Use Docker on Ubuntu 18.04

Related Posts

  • How to Use sed to Find and Replace String in Files

    How to Use sed to Find and Replace String in Files

    December 18, 2020
  • Linux Head Command

    Linux Head Command

    December 16, 2020
  • Rename Files and Directories in Linux

    How to Rename Files and Directories in Linux

    December 15, 2020

Leave a Reply Cancel reply

Popular Posts

  • How to Install Python 3.9 on Debian 10
    How to Install Python 3.9 on Debian 10 December 25, 2020
  • How to Install Python 3.9 on Ubuntu 20.04
    How to Install Python 3.9 on Ubuntu 20.04 December 21, 2020
  • How to Install GIMP on Ubuntu 20.04
    How to Install GIMP 2.10 on Ubuntu 20.04 December 22, 2020
  • How to Install Notepad++ on Debian 10
    How to Install Notepad++ on Debian 10 December 23, 2020
  • How to Install Php 8 on Debian 10
    How to Install PHP 8 on Debian 10 January 2, 2021
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook