# Format files from the command line

CLion can [format your code](reformat-and-rearrange-code.html) according to the configured code style settings. You can also apply your code style formatting to the specified files from the command line.

The command-line formatter launches an instance of CLion in the background and applies the formatting. It will not work if another instance of CLion is already running. In this case, you can perform code style formatting from the running instance. Use the command-line formatter for automated regular maintenance of a large codebase with many contributors to ensure a consistent coding style.

To be able to format files, install and enable plugins with support for the corresponding file types in CLion (for example, the Shell Script plugin to format shell script files).

Windows:

You can find the executable for running CLion in the [installation directory](directories-used-by-the-ide-to-store-settings-caches-plugins-and-logs.html) under `bin`. To use this executable as the command-line launcher, add it to your system `PATH` as described in [Command-line interface](working-with-the-ide-features-from-command-line.html).

Syntax
: ```PLAINTEXT
: clion64.exe format [<options>] <path ...>
: ```

Examples
: Format two specific files from the `C:\Data\src` directory using the default code style settings:
:
:
:
:
:
:
: ```SHELL
: clion64.exe format -allowDefaults C:\Data\src\hello.cpp C:\Data\src\world.cpp
: ```
:
:
:
:
:
:
:
:
:
: Recursively format all files in the `C:\Data\src` directory including all subdirectories using the default code style settings:
:
:
:
:
:
:
: ```SHELL
: clion64.exe format -allowDefaults -r C:\Data\src
: ```
:
:
:
:
:
:
:
:
:
: Non-recursively format all the `.cpp` and `.h` files in the `C:\Data\src` directory using code style settings from `C:\Data\settings.xml`:
:
:
:
:
:
:
: ```SHELL
: clion64.exe format -s C:\Data\settings.xml -m *.cpp,*.h C:\Data\src
: ```

macOS:

CLion includes a script for running the command-line code formatter. By default, it is located in the application package: `CLion.app/Contents/bin/format.sh`

Syntax
: ```PLAINTEXT
:
: ./format.sh [<options>] <path ...>
: ```

Examples
: Format two specific files from the `~/Data/src` directory using the default code style settings:
:
:
:
:
:
:
:
:
: ```SHELL
:
: ./format.sh -allowDefaults ~/Data/src/hello.html ~/Data/src/world.html
: ```
:
:
:
:
:
:
:
: Recursively format all files in the `~/Data/src` directory including all subdirectories using the default code style settings:
:
:
:
:
:
:
:
:
: ```SHELL
:
: ./format.sh -allowDefaults -r ~/Data/src
: ```
:
:
:
:
:
:
:
: Non-recursively format all the `.cpp` and `.h` files in the `~/Data/src` directory using code style settings from `~/Data/settings.xml`:
:
:
:
:
:
:
:
:
: ```SHELL
:
: format.sh -s ~/Data/settings.xml -m *.cpp,*.h ~/Data/src
: ```

Linux:

You can find the script for running CLion in the [installation directory](directories-used-by-the-ide-to-store-settings-caches-plugins-and-logs.html) under `bin`. To use this script as the command-line launcher, add it to your system `PATH` as described in [Command-line interface](working-with-the-ide-features-from-command-line.html).

Syntax
: ```PLAINTEXT
: clion.sh format [<options>] <path ...>
: ```

Examples
: Format two specific files from the `~/Data/src` directory using the default code style settings:
:
:
:
:
:
:
:
:
:
:
: ```SHELL
: clion.sh format -allowDefaults ~/Data/src/hello.cpp ~/Data/src/world.cpp
: ```
:
:
:
:
:
: Recursively format all files in the `~/Data/src` directory including all subdirectories using the default code style settings:
:
:
:
:
:
:
:
:
:
:
: ```SHELL
: clion.sh format -allowDefaults -r ~/Data/src
: ```
:
:
:
:
:
: Non-recursively format all the `.cpp` and `.h` files in the `~/Data/src` directory using code style settings from `~/Data/settings.xml`:
:
:
:
:
:
:
:
:
:
:
: ```SHELL
: clion.sh format -s ~/Data/settings.xml -m *.cpp,*.h ~/Data/src
: ```

## Options

| Option | Description |
| --- | --- |
| `-h` | Show the help message and quit. |
|  `-m\|-mask`  |  Specify a comma-separated list of file masks that define the files to be processed. You can use the `*` (any string) and `?` (any single character) wildcards.  |
|  `-r\|-R`  |  Process specified directories recursively.  |
|  `-s\|-settings`  |     Specify the code style settings file to use for formatting. This can be one of the following:                             * A file with the exported code style settings: open the Editor \| Code Style settings page `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `⌘ Comma` (Xcode), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (ReSharper), `⌘ Comma` (ReSharper (macOS)), `Ctrl+Alt+S` (QtCreator), `⌘ Comma` (QtCreator (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) , click ![The Show Scheme Actions button](https://resources.jetbrains.com/help/img/idea/2026.2/Project.xml` file stored in your project directory (for CLion version 2017.3 and later).                                                If this option is not specified, the file will be skipped. If there is a project in one of the parent folders, its settings will be used implicitly as well as EditorConfig.    |
|  `-allowDefaults`  |  Use the default code style settings when the code style is not defined for a file or a group of files: when `-s` is not set and the file does not belong to any project. Otherwise, the file or files will be ignored.  |
|  `-charset`  |    Preserve encoding and enforce the charset for reading and writing source files, for example: `-charset ISO-8859-15`.     This option is useful if the command-line formatter cannot correctly process special letters in a source file.    |
|  `-d\|-dry`  |  Run the formatter in the validation mode. The formatter will perform the same formatting operations in memory and will exit with a non-zero status in case any of the formatted files differs from the original one.  |

