Fork me on GitHub

Command Line InvocationΒΆ

filemagic can be invoked from the command line by running the magic.command module as a script. Pass -h or --help to print usage information.

$ python -m magic.command --help
Usage: python -m magic [options] file ...

  -h, --help            show this help message and exit
  -m PATHS, --magic=PATHS
                        A colon separated list of magic files to use
  --json                Format output in JSON

One or more files can be passed to be identified. The textual description, mimetype and encoding type will be printed beneath each file’s name.:

$ python -m magic.command
    Python script, ASCII text executable

The output can also be rendered in machine parseable JSON instead of the simple textual description of above..

$ python -m magic.command --json
  "": {
    "textual": "Python script, ASCII text executable",
    "mimetype": "text/x-python",
    "encoding": "us-ascii"

The magic.command module is not intended to be a replacement for the file command.