How to Determine the File Type of a File in Linux



Linux


In this article, we show how to determine the file type of a file in Linux.

So we can determine the file type of a file using the file keyword followed by the name of the file that we want to find the type of.

This not only tells us the type of file it is but other key information such as the language encoding of the file and so on.

So if we want to find the file type of a file named document1.html, we would do this with the following code below.



After running this code, we will get the type of file it is, plus the language encoding.

This is shown below.

Determining a file type in linux

So above we list the contents of the current working directory.

You can see a bunch of directories and files. The directories are highlighted in blue, while the files are in white.

The first file type we get is of f1.html

In response, we get that it's an HTML document of ASCII text.

We then get the file type of the file, Document1.html

In response, we get that it's an HTML document of UTF-8 Unicode text.

You can see that one HTML document is of ASCII text. The other is of UTF-8 Unicode encoding.

We then get the file type of dropboxfile.txt.

In response, we get that it's of ASCII text.

So determining the file type in linux can tell us a bit of information about the file.

And this is how to determine the file type of a file in linux.


Related Resources

How to Randomly Select From or Shuffle a List in Python



HTML Comment Box is loading comments...