Facebook Twitter Instagram
    WiredRevolution.com
    • Home
    • About
    • Contact Us
    • Essential Linux Commands
    • Sitemap
    Facebook Twitter Instagram
    WiredRevolution.com
    commands

    Determine file type with the file command

    RyanBy RyanOctober 8, 20082 Mins Read
    Facebook Twitter Pinterest LinkedIn Reddit WhatsApp Email

    The file command identifies the type or format of a file. It is a very handy command that can show you how to approach a file when the format is unknown. There are a variety of tests that it uses to determine its type, these tests include a filesystem test, magic number test, and language tests. The first successful test is the one that is printed to the user.

    The magic number tests are used to check for files with data in particular fixed formats. To determine the format of a file in this manner, either a magic number identifier exists at the beginning of the file, or a specific identifier can be determined at a specific offset within the file. The file /usr/share/file/magic specifies what magic numbers are to be tested for, what message to print if a particular magic number is found, and additional information to extract from the file.

    Here is an example with a directory which contains a variety of file types. The output lists the filename along with its type.

    $ file *
    
    data:        data
    directory:   directory
    emptyfile:   empty
    program:     ELF 64-bit LSB executable, x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), stripped
    script.sh:   Bourne-Again shell script text executable
    source.c:    ASCII C program text
    symlink:     symbolic link to `program'
    tarball.tar: POSIX tar archive (GNU)
    tarball.tbz: bzip2 compressed data, block size = 900k
    tarball.tgz: gzip compressed data, from Unix
    text.txt:    ASCII text
    

    This works equally well when the file names do not have have an extension, which is a very common case with Linux.

    Share. Facebook Twitter Pinterest LinkedIn WhatsApp Reddit Email
    Previous ArticleUsing tar to archive files
    Next Article Update your entire Gentoo Linux system

    Related Posts

    How to get Boxee to correctly identify local media files

    Extract the contents of an RPM package

    Convert PDF file to text with pdftotext

    Most Commented
    March 12, 2009

    Fix blue tinted video in Ubuntu

    September 10, 2010

    Setup SSH access between VirtualBox Host and Guest VMs

    March 8, 2011

    Install GNOME Shell in Ubuntu 10.10 Maverick

    April 4, 2009

    Setup the PS3 Bluetooth Controller on Ubuntu

    October 22, 2008

    How to correctly use LD_LIBRARY_PATH

    Recent Comments
    • Execute command on linux virtual machine (or server) from windows commandline on Setup SSH access between VirtualBox Host and Guest VMs
    • Solved: How to SSH to a VirtualBox guest externally through a host? - Daily Developer Blog on Setup SSH access between VirtualBox Host and Guest VMs
    • How to SSH to a VirtualBox guest externally through a host? [closed] – Code D3 on Setup SSH access between VirtualBox Host and Guest VMs
    • How to copy and paste from VirtualBox? [duplicate] on Setup SSH access between VirtualBox Host and Guest VMs
    • Jackie Laguna on Fix OpenGL: ChoosePixelFormat SketchUp error in WINE
    © 2025 ThemeSphere. Designed by ThemeSphere.

    Type above and press Enter to search. Press Esc to cancel.