GeminiCLI.net

Gemini CLI Cheatsheet

Your quick reference guide for the most common Gemini CLI commands and flags.

Basic Usage

gemini "Your prompt here"

The most basic command. Sends a prompt to the Gemini model and prints the response.

Example:gemini "What are the 5 largest cities in the world?"

npx @google/generative-ai '...'

Run Gemini CLI without a permanent installation. Perfect for quick tests or infrequent use.

Example:npx @google/generative-ai "Suggest a good name for a tech blog."

File & Input Handling

gemini -f [FILE_PATH] '...'

Includes the content of a file as part of the prompt context. The file content is prefixed to your prompt.

Example:gemini -f readme.md "Summarize this README file."

cat [FILE_PATH] | gemini '...'

Pipes the content of a file (or any standard output) directly to Gemini CLI as its context.

Example:cat package.json | gemini 'Explain the purpose of these dependencies.'

ls -l | gemini '...'

Pipe any command's output to Gemini. Useful for interpreting system information.

Example:ls -l | gemini 'What is the largest file in this directory?'

Output & Model Control

gemini ... --json

Formats the output as a JSON object. Incredibly useful for scripting and automation.

Example:gemini "List 3 colors" --json

gemini ... --model [MODEL_NAME]

Specify which Gemini model to use for the query (e.g., gemini-1.5-pro-latest, gemini-1.0-pro).

Example:gemini "Translate this to French" --model gemini-1.5-flash-latest

gemini ... --temperature [0.0-1.0]

Controls the creativity of the response. Lower values (e.g., 0.2) are more deterministic, higher values (e.g., 0.9) are more creative.

Example:gemini "Write a tagline for a coffee shop" --temperature 0.9

Pro Tips & Advanced Usage

export GOOGLE_API_KEY="YOUR_KEY"

Set your API key as an environment variable so you don't have to provide it with every command.

Example:Add this to your .bashrc or .zshrc file for persistence.

gemini -f code.js "Refactor this code. Only output the raw, updated code."

Use prompting to control the output format. Asking for 'raw code' helps when you want to pipe the output directly into a new file.

Example:gemini -f old.py "..." > new.py

System & Web Tools

gemini 'List the files in the current directory as a table'

Executes the `ls` command and understands its output. You can ask for specific formats or analysis.

Example:gemini 'Show me the contents of the src folder, recursively, and identify any .css files'

gemini 'Find all instances of `useState` in the `components` directory'

Performs a `grep` search for content within files. Useful for code analysis and discovery.

Example:gemini 'Search for the text `TODO:` in all `.ts` files.'

gemini 'Find all markdown files in the `src/blog` folder'

Uses glob patterns to find files by path. The agent will then typically read or analyze these files.

Example:gemini 'Read all the `.md` files from the blog and give me a summary of each.'

gemini 'Search the web for the latest news on AI'

Performs a web search using Google Search to answer questions about current events or up-to-date information.

Example:gemini 'What were the main announcements from the last Google I/O event?'

gemini 'Remember that I prefer to use pnpm for package management.'

Allows the agent to remember specific facts or preferences for future interactions.

Example:gemini 'From now on, when you suggest installing a package, use pnpm.' 'Okay, I will remember to use pnpm.'

gemini 'Run the command `npm run test` and tell me if it succeeds.'

Executes an arbitrary shell command and analyzes its output. This is a very powerful but potentially dangerous tool.

Example:gemini 'Install the `is-odd` package using npm and then write a node script to use it.'