Featured Article

"How to Create a New File Using the Command Line"

Alan Jun 16, 2026

Mastering Command Line: Creating Files

Linux Commands Cheat Sheet (Day 8): touch, mkdir, tree Explained with Examples - Day 8
Linux Commands Cheat Sheet (Day 8): touch, mkdir, tree Explained with Examples - Day 8

The command line, a powerful tool for Linux and macOS users, offers a quick and efficient way to create files. This guide will walk you through the process, from basic file creation to more advanced techniques.

Learn Linux from Beginner to Advanced (Part-1) | Essential Terminal Commands Cheat Sheet
Learn Linux from Beginner to Advanced (Part-1) | Essential Terminal Commands Cheat Sheet

Creating a Simple Text File

To create a new text file, use the following command:

📄 cat – Display File Content in Linux
📄 cat – Display File Content in Linux

touch filename.txt

Replace filename.txt with the name you want for your file. The touch command is a versatile tool that can also update the timestamp of existing files.

Linux Day 2 | File Operations Cheat Sheet for Beginners
Linux Day 2 | File Operations Cheat Sheet for Beginners

Creating and Editing Files with nano

If you want to create and edit a file in one step, use the nano text editor. Here's how:

nano filename.txt

the command line sheet is shown in blue and white, with instructions for each section
the command line sheet is shown in blue and white, with instructions for each section

This command creates a new file and opens it in the nano editor. You can start typing your content, then save and exit by pressing Ctrl+X, followed by Y to confirm, and finally Enter.

Creating Multiple Files at Once

You can create multiple files at once using a loop. Here's an example using a for loop to create files named file1.txt, file2.txt, etc., up to file5.txt:

Linux Basics I Wish I Learned Earlier
Linux Basics I Wish I Learned Earlier

for i in {1..5}; do touch file$i.txt; done

Creating Directories and Files

mkdir – Make Directory in Linux
mkdir – Make Directory in Linux
the linux command line is shown in this manual
the linux command line is shown in this manual
How To Open And Run Commands In The Terminal (Beginner Friendly)
How To Open And Run Commands In The Terminal (Beginner Friendly)
Ultimate Linux Command Cheatsheet for Beginners
Ultimate Linux Command Cheatsheet for Beginners
Create directories on Linux using mkdir
Create directories on Linux using mkdir
the command window for windows command
the command window for windows command
Command Line Basics Every Beginner Should Learn
Command Line Basics Every Beginner Should Learn
an image of a computer screen that is running on windows xp and has the command window open
an image of a computer screen that is running on windows xp and has the command window open
Create Perfect ePub Books from Multiple Txt Files
Create Perfect ePub Books from Multiple Txt Files
Command Line Cheat Sheet
Command Line Cheat Sheet
PDF Automation Server for Linux has more Command Line applications for Linux Developers
PDF Automation Server for Linux has more Command Line applications for Linux Developers
How to Run Shell Scripts in Linux [with Detailed Explanation for Beginners]
How to Run Shell Scripts in Linux [with Detailed Explanation for Beginners]
How to Create and Use a ZIP File
How to Create and Use a ZIP File
Command Line Cheat Sheet
Command Line Cheat Sheet
➤ Most Used Git Commands | Sandeep Bonagiri
➤ Most Used Git Commands | Sandeep Bonagiri
How to Find a File or Folder in MS-DOS or Windows Command Line
How to Find a File or Folder in MS-DOS or Windows Command Line
Top 52 Linux Commands
Top 52 Linux Commands
Linux less Command Explained: Read Huge Files Without Terminal Overload
Linux less Command Explained: Read Huge Files Without Terminal Overload

You can create directories and files in one command using the mkdir and touch commands together. Here's how to create a directory named myfolder and a file named myfile.txt inside it:

mkdir -p myfolder && touch myfolder/myfile.txt

Creating Empty Files vs. Files with Content

By default, the touch command creates empty files. If you want to create a file with initial content, you can use the echo command or redirection:

  • echo "Hello, World!" > filename.txt
  • touch filename.txt && echo "Hello, World!" >> filename.txt

Comparing File Creation Methods

Command Creates File Opens in Editor Creates with Content
touch ✓ ✗ ✗
nano ✓ ✓ ✓
echo ✗ ✗ ✓