# Linux: How to Create a File from the Terminal

> Create a file from a Linux terminal with touch for an empty file, echo with output redirection for one-line content, or a text editor like vi or nano

**URL:** https://sentry.io/answers/create-a-file-from-terminal-in-linux/

---

## The Problem

How can I create a new file from a Linux terminal window (i.e. shell)?

## The Solution

The simplest way to do this is by using the `touch` command:

```bash
touch new-file.txt
```

This will create an empty file with the provided name in the current directory.

To create a file containing some text, we can redirect the output of a command using the `>` operator:

```bash
echo "Hello world" > hello-world.txt
```

We can also do this interactively using `cat`:

```bash
cat > new-file.txt
```

After pressing Enter, we can type some text for the file contents. Once we're done, pressing Enter and then Ctrl+D will save and close the file.

Finally, we can create a new file using a terminal-based text editor such as `vi` or `nano`:

```bash
vi filename.txt
```
```bash
nano filename.txt
```

Note that this last method will only create a file if we save before exiting (`:w` in `vi` or `Ctrl+O` in `nano`).

---

*Source: [sentry.io/answers/create-a-file-from-terminal-in-linux/](https://sentry.io/answers/create-a-file-from-terminal-in-linux/)*
