---
title: "Part 3 [touch & mkdir] - Know your commands"
date: 2019-11-16
url: https://devsv.in/blog/know_your_commands_touch_mkdir/
tags: ["linux", "terminal", "knowyourcommands"]
description: "Hey guys, this is part 3 of the series Know your commands. This post covers the commands touch and mkdir."
---

# Part 3 [touch & mkdir] - Know your commands

Hey guys, this is part 3 of the series `Know your commands`.

If you are new here, please also checkout the other parts of this series.

- Part 1 - [pwd & cd](https://devsv.in/blog/know_your_commands_pwd_cd/)
- Part 2 - [echo & ls](https://devsv.in/blog/know_your_commands_ls_echo/)
- Part 3 - [touch & mkdir](https://devsv.in/blog/know_your_commands_touch_mkdir/)

In this part I will be covering the use of [touch](#touch) and [mkdir](#mkdir) commands.

---

## touch

touch command is used to create an empty file if not exists.

**Syntax**

```bash
touch [optional flags] [filenames]
```

**Usage**
```bash
$ pwd
/home/subin

$ ls Documents
test_doc.txt

# This creates file inside Documents directory
$ touch Documents/another_file.txt

$ ls Documents
another_file.txt
test_doc.txt
```
* `touch [multiple files]` - touch command can be also used to create multiple files at once. 
  ```bash
  $ pwd
  /home/subin

  $ cd Documents

  $ pwd 
  /home/subin/Documents

  # Creating multiple files at once
  $ touch file1 file2 yet_another_file

  $ ls
  another_file.txt
  file1
  file2
  test_doc.txt
  yet_another_file
  ```
___

## mkdir
mkdir stands for Make Directory. As the name suggests, it is used to create an directory.

**Syntax**

```bash
mkdir [optional flags] [directories]
```

**Usage**

```bash
$ pwd
/home/subin

$ ls
Desktop
Documents
Downloads
Music
Pictures

# This creates an empty directory
$ mkdir test_dir

$ ls
Desktop
Documents
Downloads
Music
Pictures
test_dir
```
* `mkdir [multiple files]` - mkdir command can be also used to create multiple directories at once. 
  ```bash
  $ pwd
  /home/subin

  # Creating multiple directories at once
  $ mkdir dir1 dir2 another_dir

  $ ls
  another_dir
  Desktop
  dir1
  dir2
  Documents
  Downloads
  Music
  Pictures
  test_dir
  ```
* `mkdir -v [directories]` - `-v` or `--verbose` flag is used to display a status message for each directory passed as an argument.
  ```bash
  $ pwd
  /home/subin

  $ ls
  another_dir
  Desktop
  dir1
  dir2
  Documents
  Downloads
  Music
  Pictures
  test_dir

  $ mkdir -v new_dir dir1
  mkdir: created directory 'new_dir'
  mkdir: dir1: File exists
  ``` 
* `mkdir -p [directories]` -  This command is used to create parent directories if not exists.
  ```bash
  $ pwd
  /home/subin

  # This command will fail since Folder1 doesn't exist
  $ mkdir Documents/Folder1/Folder2
  mkdir: Documents/Folder1: No such file or directory

  $ mkdir -p Documents/Folder1/Folder2

  $ ls Documents/Folder1
  Folder2
  ```
___

## What's next
I hope this article gave you an insight on creating files and directory. 
In next part of this series, we will see basic file operations.

---

**Note:**
All examples above are based on below imaginary directory structure.

```
.
├── home
│   └── subin
│       ├── .bashrc
│       ├── .config
│       ├── Downloads
│       │   └── movie
│       │       └── some_movie.mp4
│       ├── Desktop
│       ├── Documents
│       │   └── test_doc.txt
│       ├── Music
│       └── Pictures
├── lib
├── opt
└── tmp
```
