> For the complete documentation index, see [llms.txt](https://www.learnros2.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.learnros2.com/ros/cookbook/how-to-publish-message-to-a-topic-from-command-line.md).

# How to publish message to a topic from command line?

To publish a message to a topic, we can use the following command:

```
ros2 topic pub --once <topic> <message-type> "<data>"
```

To publish message to a topic at a fixed rate, use the following command:

```
ros2 topic pub -r <rate> <topic> <message-type> "<data>"
```
