• 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 Install SSH Keys on Ubuntu 22.04

    How to Set up SSH Keys on Ubuntu 22.04

    January 7, 2023
  • How to Install Fail2ban on Ubuntu 22.04

    How to Install and Configure Fail2ban on Ubuntu 22.04

    December 5, 2022
  • How to Enable SSH on Ubuntu 22.04

    How to Enable SSH on Ubuntu 22.04

    December 1, 2022

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install Microsoft Edge Browser on Ubuntu 22.04
    How to Install Microsoft Edge Browser on Ubuntu 22.04 March 14, 2023
  • How to Install Ruby on Ubuntu 22.04 LTS
    How to Install Ruby on Ubuntu 22.04 LTS February 27, 2023
  • How to Install LEMP Stack on Ubuntu 22.04
    How to Install LEMP Stack on Ubuntu 22.04 March 18, 2023
  • How to Install Set Up Apache Virtual Hosts on Ubuntu 22.04
    How to Set Up Apache Virtual Hosts on Ubuntu 22.04 March 2, 2023
  • How to Install MariaDB on Debian 11 Bullseye
    How to Install MariaDB on Debian 11 Bullseye March 8, 2023
© 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