Creating Files & Folders

touch creates empty files and updates timestamps; mkdir creates directories.

Syntaxtouch file mkdir [-p] directory

Two commands cover most of what you need to create things.

touch — create a file

touch name creates an empty file if it does not exist. If it does exist, touch simply updates its "last modified" time.

mkdir — make directory

mkdir name creates a new folder. The -p option creates any missing parent folders in one go, and never complains if the folder already exists.

Example

Example · bash
# Create three empty files at once
touch notes.txt todo.txt ideas.txt

# Create a single folder
mkdir projects

# Create a nested path in one command
mkdir -p projects/web/src

ls projects/web
# src

When to use it

  • A CI pipeline uses 'mkdir -p /build/artifacts/reports' to create a nested output directory tree before writing test results.
  • A developer runs 'touch src/__init__.py' to create an empty Python package marker file without opening an editor.
  • A sysadmin uses 'touch /var/lock/myapp.lock' to create a lock file signalling another process is running.

More examples

Create files and directories

Shows 'touch' for creating files and 'mkdir -p' for creating a full directory tree in one go.

Example · bash
# Create an empty file
touch README.md

# Create a single directory
mkdir src

# Create nested directories in one command
mkdir -p src/utils/helpers

Create multiple items at once

Uses brace expansion to create multiple files or directories with a single command.

Example · bash
# Create several files at once
touch index.html style.css app.js

# Create several directories at once
mkdir -p {src,tests,docs}/
ls
# docs/  src/  tests/

Update file timestamp with touch

Demonstrates that 'touch' on an existing file updates its modification timestamp without changing contents.

Example · bash
# Show current timestamp
stat -c '%y' build.log
# 2026-07-10 08:00:00

# Update to current time
touch build.log
stat -c '%y' build.log
# 2026-07-16 14:30:00

Discussion

  • Be the first to comment on this lesson.