How to Create Files in Ubuntu: Terminal, GUI, Templates, and Permissions (Beginner Guide)

目次

1. What You’ll Learn in This Article

When working on Ubuntu, you will inevitably run into situations where you think, “I want to create a new file.”
For example, you might create a text file for notes, make a new configuration file, or prepare a shell script—there are many use cases.

If you’re used to Windows, it’s also very common to wonder, “Can’t I create a new file with a right-click?” or “Which method is the correct one?”—a classic Ubuntu moment.

In this article, we’ll organize and explain the most common ways to create files in Ubuntu so that even beginners can follow without getting lost.

1.1 Common Ways to Create Files in Ubuntu (Command Line / GUI)

There are two main ways to create files in Ubuntu:

Create Files with Commands (Terminal)

Using the terminal is extremely fast once you get used to it, and it’s commonly used in real-world work.

  • Create an empty file: touch
  • Create a file and write content at the same time: echo or printf + redirection (>)
  • Create a multi-line file in one go: cat (heredoc)

For tasks like server work or editing configuration files, command-line operations are the standard approach.

Create Files with the GUI (File Manager)

In Ubuntu’s desktop environment, you can also use the file app (Nautilus) to work visually.

  • Open a text editor and use “New File → Save”
  • Use the Templates feature (Templates) to create files from a right-click menu

This is a comfortable option even if you usually work primarily with the GUI.

1.2 Which Method Should You Choose? (Quick Reference by Use Case)

It’s easy to get stuck thinking, “So which one should I use?”—so here’s the conclusion upfront.

What you want to doRecommended methodWhy
Create an empty file as fast as possibletouchFastest and reliable
Create a file with just one lineecho + >Easy to copy/paste
Create a multi-line configuration filecat (heredoc)Create in one shot, fewer mistakes
Create while viewing on screenSave from a text editorBeginner-friendly
Create from right-clickTemplatesUbuntu-specific solution

If you’re a beginner, simply learning “Save from the GUI” and “touch” is already enough.
Once you’re comfortable, adding redirection and heredoc to your toolkit will make your workflow much smoother.

1.3 Target Audience (Beginners to Light Practical Use)

This article is written for people like:

  • You just started using Ubuntu and don’t know how to create files
  • You’re not comfortable with the terminal, but you want to learn minimum essential commands
  • You’re increasingly creating configuration files or scripts
  • You’re stuck because you can’t create a new file via right-click
  • You’ve been blocked by errors like “Permission denied”

Later in the article, we also cover post-creation checks (permissions and ownership) and common troubleshooting,
so it should become a “reference you’ll come back to” for everyday Ubuntu use.

2. What “Creating a File” Means in Ubuntu

In Ubuntu, “creating a file” simply means “preparing a container where some data can be saved.”
However, in real work, beginners often get confused because the following situations get mixed together:

  • You thought you created a file, but you actually created a directory (folder)
  • You can’t remember where you created it
  • You created it without a file extension, then couldn’t tell what it was for
  • You created it, but can’t edit it (permissions issue)

Here we’ll整理 the basics you need to understand file creation in Ubuntu.

2.1 The Difference Between a File and a Directory (Often Confused)

First, on Ubuntu (Linux), a “file” and a “directory (folder)” are different things.

  • File: something that contains content (text, settings, data)
  • Directory: a container used to organize files

For example:

  • memo.txt → file
  • Documents/ → directory
  • config.ini → file
  • project/ → directory

A very common beginner mistake is creating a directory when you intended to create a file.

  • Command to create a directory: mkdir
  • Command to create a file: touch (and others)

This article focuses on creating files, so we’ll mainly use touch and redirection like >.

2.2 Extensions Aren’t Required, but They’re Important in Practice

On Windows, file extensions (.txt, .jpg, .exe, etc.) are very important,
and people often feel like the extension “defines” what the file is.

In Ubuntu (Linux), on the other hand, extensions are not required.
In extreme cases, files like these can exist without any problems:

  • memo
  • config
  • run

That said, adding an extension is usually clearer in real usage.
Especially for beginners, it’s recommended to use extensions so the purpose is obvious.

Common examples include:

  • memo.txt: text notes
  • script.sh: shell script
  • settings.conf: configuration file
  • data.csv: CSV data
  • README.md: documentation (Markdown)

Also, on Ubuntu, “file contents” and “permissions (whether it can be executed)” often matter more than extensions.
That’s why later in this article we’ll also touch on chmod (execute permission).

2.3 Reduce Mistakes by Thinking About the Save Location (Path) (Home / Working Directory)

This is one of the most common beginner problems when creating files on Ubuntu:

“I created the file, but I can’t find where it is…”

This usually happens because you didn’t pay attention to which directory you created it in.

In Ubuntu, there are two common patterns for where you create files.

Create Under Your Home Directory (Recommended for Beginners)

Your logged-in user typically has a personal workspace.
This is called your home directory.

Example path:

  • /home/username/

In the terminal, it’s represented by the symbol ~.

Examples:

  • ~/Documents
  • ~/Downloads
  • ~/Desktop

As a beginner, it’s generally safest to work under your home directory.

Create in Your Working Directory (Understand Once You’re Comfortable)

When you create a file from the terminal, it’s created in “where you are now.”
This is called the current directory.

The command to check your current location is pwd.

pwd

Example: If the output is:

/home/user/Documents

Then running touch test.txt will create the file here:

  • /home/user/Documents/test.txt

So file creation isn’t just about the “action”—you need to understand the location (path) as part of it.

3. Fastest Option: Create an Empty File (touch)

When you think, “I just want to create a file for now” on Ubuntu, the simplest and most reliable method is the touch command.

touch is commonly used in situations like:

  • Create an empty file for notes and edit it later
  • Prepare an “empty container” first for a configuration file
  • Create multiple files at once for a project
  • Prepare a file that must exist before running another process

For the goal of “create an empty file,” touch is close to the best answer.

3.1 Basics of touch filename (Create an Empty File)

The basic form is extremely simple.

touch filename

For example, to create an empty file named memo.txt:

touch memo.txt

To confirm it was created, list files with ls.

ls

You should see the file you created:

memo.txt

If you want to confirm “Is it really empty?”, you can display its contents with cat.

cat memo.txt

If nothing is displayed, the file is empty.

3.2 What Happens If You Run touch on an Existing File? (Timestamp Update)

touch doesn’t only create files that don’t exist.
If you run it on a file that already exists, it generally behaves like this:

  • The file contents do not change
  • The modified time (timestamp) becomes newer

For example, if memo.txt already exists and you run:

touch memo.txt

The contents stay the same, but the file’s “modified time” is updated.

In many everyday tasks this doesn’t matter, but be careful in cases like:

  • Backup/sync tools treat it as “updated”
  • Build or automation processes rely on timestamps
  • Monitoring systems may misinterpret it as a change

As a beginner, it’s fine to remember “touch = create an empty file.”
As you gain experience, it’s even better to remember that it can also “update timestamps.”

3.3 Create Multiple Files at Once (Example: touch a.txt b.txt)

You can also create multiple files in a single command.

touch a.txt b.txt c.txt

This one line creates a.txt, b.txt, and c.txt together.

It’s also handy when you want to prepare a basic project skeleton.

touch index.html style.css script.js

In web development and learning contexts, creating multiple files like this is very common.

3.4 Common Mistakes: Typos Create Unintended Files / Wrong Location

touch is convenient, but because it’s so easy, it can also cause “accidents.”
Here are common beginner pitfalls.

You Don’t Notice a Filename Typo

For example, you intended to create config.txt, but accidentally typed:

touch confgi.txt

As expected, a different file named confgi.txt is created.
touch won’t show an error—it just creates it—so it’s easy to miss.

Tip: run ls right after creating files to confirm what was actually created.

You Created It in the Wrong Place (You Can’t Find It)

This happens very often.

When you create a file from the terminal, it’s created in your current directory.

The command to check “Where am I right now?” is pwd.

pwd

If you’re not where you expected, move with cd first, then create the file.

Example: move to Documents, then create a file

cd ~/Documents
touch memo.txt

At this point, you’ve learned the shortest path to creating an empty file on Ubuntu: touch.

4. Create a File with Content: Use Redirection (echo / printf / cat)

touch is perfect for creating an empty file.
But in real work, you’ll often want this instead:

  • Not just create a file, but write content at the same time
  • Write only one line and finish
  • Create a configuration file in bulk

That’s where redirection (using > or >>) becomes very useful.

Redirection takes a little practice, but once you learn it, your workflow becomes much faster.

4.1 Create with > (Also Explaining the Overwrite Risk)

On Ubuntu, you can save the output of a command into a file.
The operator used for that is >.

The basic form looks like this:

command > filename

For example, to write hello into memo.txt while creating it:

echo "hello" > memo.txt

If memo.txt doesn’t exist, it will be created. If it already exists, the content will be replaced.

This is the key point:

> can create a new file, but it also overwrites existing files.

So if you use > on a file that already contains important content, that content will be deleted.

As a safe beginner rule of thumb:

  • > means replace (overwrite)
  • >> means add (append)

4.2 Append with >> (A Common Pattern for Config Files)

If you want to append content instead of overwriting, use >>.

echo "second line" >> memo.txt

This adds a new line to the end of memo.txt.

When working with configuration files or logs, appending is often the safer option.

For example, adding one line to a config file might look like this:

echo "export PATH=\$PATH:/opt/tools/bin" >> ~/.bashrc

This is the advantage of >>: it keeps the existing content and adds new content.

4.3 When printf Is Safer (Newlines and Escapes)

echo is simple, but in practical environments, printf is sometimes more reliable.

Main reasons include:

  • echo may behave slightly differently depending on the environment
  • printf makes it easier to handle \n (newlines) and \t (tabs) precisely

For example, to write multiple lines using explicit newlines:

printf "line1\nline2\n" > memo.txt

This creates memo.txt containing exactly two lines in one shot.

printf is also great when you want to include blank lines or more complex formatting.

4.4 Write Multiple Lines at Once: Heredoc (How cat << 'EOF' > file Works)

When creating configuration files, appending line by line with echo can be tedious.
That’s where heredoc (here-document) becomes very useful.

With the following syntax, you can save multiple lines into a file all at once:

cat << 'EOF' > sample.conf
server_name example.com;
root /var/www/html;
index index.html;
EOF

The key points are:

  • EOF is a marker that means “input ends here” (you can use other words too)
  • Quoting it like 'EOF' helps prevent variable expansion and makes it safer

Heredoc is commonly used in server setup and configuration work.
It may look a bit advanced at first, but once you get used to it, it’s extremely convenient.

4.5 Small “Accident Prevention” Tips: Avoid Overwriting by Mistake

The scariest part of redirection is accidentally overwriting a file.

For example, this can be dangerous:

echo "test" > important.conf

If important.conf contained critical settings, the contents would be lost.

To reduce mistakes in real operations, remember these two ideas:

1) Create a Backup Before Overwriting

For example, for a configuration file:

cp important.conf important.conf.bak

2) Check the Contents Before Editing with cat or less

Building the habit of checking before editing will prevent many accidents.

cat important.conf

5. Create Files with an Editor (Beginner-Friendly: nano / GUI Text Editor)

So far, we’ve covered touch and redirection, which become very powerful once you’re comfortable with them.
But if you’re new to Ubuntu, you might feel like this:

  • The terminal still feels intimidating
  • What if I overwrite something by mistake?
  • I want to edit while looking at the screen

In that case, using an editor to create files is the safest approach.
With an editor, the flow is simply “create new → save,” which is easy to understand intuitively.

5.1 Edit from the Terminal: nano file (How to Save and Exit)

The most beginner-friendly terminal editor on Ubuntu is nano.
It’s simple to use, and shortcut keys are shown at the bottom of the screen, so it’s easy not to get lost.

For example, to create and edit memo.txt:

nano memo.txt

If memo.txt doesn’t exist, it will be created automatically and nano will open.
Write your text, save, and exit—done.

Basic nano Shortcuts (3 Things Beginners Should Learn First)

nano uses shortcut keys.
The basic idea is to hold Ctrl while pressing another key.

  • Save: Ctrl + O (Write Out)
  • Enter: confirm the filename
  • Exit: Ctrl + X

If you try to exit without saving, nano will ask for confirmation, which makes it beginner-friendly.

5.2 vim Is for Advanced Users (Only the Minimum Save/Exit)

Many Ubuntu users rely on vim, but it can be difficult for beginners.
That’s because it has multiple modes, and it’s easy to get stuck thinking “I can’t type” or “I can’t exit.”

Still, knowing the bare minimum—“open” and “save & quit”—can help in emergencies.

Open a file (or create it if it doesn’t exist):

vim memo.txt

Basic steps to save and quit:

  1. Press Esc
  2. Type :wq and press Enter (write + quit)

To quit without saving:

  1. Esc
  2. Type :q! and press Enter

As a beginner, nano is usually enough.
Think of vim as an “advanced tool” and learn it gradually only when needed.

5.3 Create Files with the GUI (Text Editor → Save)

If you prefer not to use the terminal, you can create files completely through the GUI.

The easiest method is:

  1. Open a text editor (for example, “Text Editor” or “GNOME Text Editor”)
  2. Create a new file
  3. Click “Save” and choose a location

This is very similar to Windows, so beginners usually feel comfortable with it.

Also, because you explicitly choose the save location, it’s harder to lose track of where the file was created.

5.4 Recommended Editors (Ubuntu Default / VS Code)

On Ubuntu, there are several editor options depending on your purpose.

Ubuntu Default: Text Editor (Simple and Lightweight)

Ubuntu typically comes with a simple text editor installed by default.
It’s perfect for quick notes, small config edits, and simple scripts.

VS Code (Best for Programming)

If you write code or manage many files, Visual Studio Code (VS Code) is highly recommended.

  • Syntax highlighting (easy to read)
  • Auto formatting
  • Integrated terminal
  • Extensions for many languages

For beginners, the “default text editor” is enough at first.
If you feel you want a more comfortable development environment, you can switch to VS Code later.

6. Right-Click “New File” on Ubuntu: Use Templates

Many people moving from Windows to Ubuntu expect this workflow:

“Right-click → New → Create a file”

On Ubuntu, the file manager does not always show “New File” by default.
This often leads beginners to think, “Ubuntu can’t create new files from right-click.”

But the solution exists: Templates.

6.1 What Is the Templates Folder? (How It Works)

Ubuntu has a feature called Templates that lets you create new files from templates using the right-click menu.

The idea is simple:

  • If you put files into the Templates folder
  • They appear as “New Document” options in the right-click menu

This is the Ubuntu-style way to create “new files” from the GUI.

6.2 Enable Right-Click “New Document” (Create a Blank Template)

To use Templates, you need at least one template file.

First, check if you have a Templates folder in your home directory.

ls ~

If you see a folder named Templates, that’s the one.

If it doesn’t exist, create it:

mkdir -p ~/Templates

Now create a blank template file inside it.
For example, a blank text file template:

touch ~/Templates/Empty\ Text\ File.txt

After this, open the file manager, right-click in a folder, and you should see something like:

  • New Document
  • Empty Text File.txt

Select it, and Ubuntu will create a new file based on that template.

6.3 Add Multiple Templates (Text / Markdown / Shell Script)

Once you understand the concept, you can add multiple templates depending on your needs.

Examples:

touch ~/Templates/README.md
touch ~/Templates/script.sh
touch ~/Templates/config.conf

Now you can create these common files from right-click as well.

If you want to make script.sh immediately executable, you can also prepare an executable template file (covered later in the permissions section).

6.4 Troubleshooting: “Templates Doesn’t Show Up”

If “New Document” doesn’t appear in the right-click menu, check these points:

  • The Templates folder exists under your home directory
  • There is at least one file inside Templates
  • You are using the default Ubuntu file manager (Nautilus)

In many cases, simply creating one template file is enough to make the menu appear.

7. Common Errors When Creating Files (Permission Denied, Read-Only, etc.)

At this point, you can create files using multiple methods.
But many beginners hit another wall:

“I tried to create a file, but it says Permission denied.”

This happens because Ubuntu has a strong permission system.
It protects the system from accidental changes, but it can confuse beginners at first.

7.1 Why “Permission denied” Happens (Owner / Permissions)

On Ubuntu, every file and directory has:

  • an owner (who owns it)
  • a group (which group it belongs to)
  • permissions (what actions are allowed)

If your user account does not have permission to create files in a directory, Ubuntu will block it.

For example, system directories like these usually require administrator privileges:

  • /etc
  • /usr
  • /var

So if you try to create a file directly under /etc as a normal user, you may get an error.

7.2 How to Check Permissions with ls -l

When you see a permission error, the first thing to do is check the file/directory permissions.

The most common command for this is ls -l.

ls -l

Example output:

-rw-r--r-- 1 user user  120 Jan 24 10:30 memo.txt

This line includes important information:

  • -rw-r--r--: permissions
  • user user: owner and group

For directories, you might see something like:

drwxr-xr-x 2 user user 4096 Jan 24 10:20 Documents

The leading character tells you what it is:

  • - = file
  • d = directory

So you can quickly tell whether you’re dealing with a file or a directory.

7.3 The Minimum Permission Knowledge You Need (r / w / x)

Linux permissions look complicated, but the basics are simple once you break them down.

The permission letters mean:

  • r = read (can view content)
  • w = write (can edit/create/delete)
  • x = execute (can run / can enter directory)

And they are applied to three categories:

  • owner (user)
  • group
  • others (everyone else)

So a permission string like this:

-rw-r--r--

Can be read as:

  • owner: rw- (read/write allowed)
  • group: r-- (read only)
  • others: r-- (read only)

This is enough knowledge to understand most permission issues you’ll encounter as a beginner.

7.4 Fix Permission Issues Safely (Use the Right Directory, Avoid Random sudo)

When you see “Permission denied,” beginners often try this immediately:

sudo touch something

This can work, but using sudo without understanding can create bigger problems later (wrong ownership, accidental system edits).

So here’s a safer beginner approach:

  1. Create files under your home directory whenever possible
  2. If you must edit system files, use sudo only for that specific task

For example, editing a file under /etc is typically done like this:

sudo nano /etc/example.conf

This is safer than creating random files as root in unknown locations.

7.5 A Common Trap: Files Created with sudo Become “Owned by root”

If you create or edit a file with sudo, it may become owned by root.

Example:

sudo touch myfile.txt

If you check it with ls -l, you might see:

-rw-r--r-- 1 root root 0 Jan 24 11:00 myfile.txt

This means your normal user may not be able to edit it freely later.

If you need to fix ownership (for files under your home directory), you can use chown:

sudo chown $USER:$USER myfile.txt

Important: Don’t randomly change ownership of system files under /etc or /usr.
Use this mainly for files that should belong to your user account (especially inside ~).

8. Creating Executable Files (Shell Scripts) and Setting Permissions

On Ubuntu, you may want to create a file and then “run it.”
A typical example is a shell script (.sh file).

But many beginners create a script and then hit this issue:

“I created the file, but I can’t execute it.”

This happens because on Ubuntu, execution depends on permissions (the x flag).

8.1 Create a Simple Script File (Example)

First, create a script file. Here’s a quick example using heredoc:

cat << 'EOF' > hello.sh
#!/bin/bash
echo "Hello from Ubuntu!"
EOF

Now you have a file named hello.sh.

At this point, it exists, but it may not be executable yet.

8.2 Make It Executable with chmod +x

To run a script file directly, you need to add execute permission.

Use chmod +x like this:

chmod +x hello.sh

Now you can run it with:

./hello.sh

Expected output:

Hello from Ubuntu!

This is a key Ubuntu concept:

A file can exist, but it won’t run unless it has execute permission (x).

8.3 Why You Need ./ to Run It (Beginner Explanation)

Beginners often wonder why they can’t run a script like this:

hello.sh

And why Ubuntu requires this:

./hello.sh

The reason is that Ubuntu doesn’t automatically search the current directory (.) for commands, for security reasons.

So ./ means:

  • “Run the file in the current directory”

This prevents accidentally running a malicious script with the same name as a system command.

8.4 Safer Script Creation: Use a Scripts Folder

If you start writing scripts often, it’s convenient to create a dedicated folder.

mkdir -p ~/scripts

Then store scripts there:

mv hello.sh ~/scripts/

This keeps your home directory clean and makes scripts easier to manage.

9. Useful Commands to Confirm File Creation (ls / file / cat / stat)

After creating a file, it’s useful to confirm that:

  • It exists
  • It’s the right type
  • It contains the correct content
  • Its permissions are correct

Here are the most useful confirmation commands.

9.1 Confirm Existence with ls and ls -l

The most basic check is ls.

ls

If you want to check details like permissions and timestamps, use ls -l:

ls -l memo.txt

This shows ownership, permissions, size, and last modified time.

9.2 Check the File Type with file

If you’re not sure what a file actually is, use the file command.

file memo.txt

Example output:

memo.txt: ASCII text

This can be very helpful when dealing with files that have no extension.

9.3 View Contents with cat and less

To quickly display the contents of a file, use cat:

cat memo.txt

If the file is long, less is easier to read:

less memo.txt

In less, you can scroll and quit with q.

9.4 Check Detailed Metadata with stat

If you want more detailed information (timestamps, inode, etc.), use stat.

stat memo.txt

This is especially useful when you’re debugging “why a file looks updated” or “why something isn’t working.”

10. Summary: Best Ways to Create Files in Ubuntu (Beginner Checklist)

Finally, let’s summarize the most useful ways to create files in Ubuntu.

10.1 Recommended Methods by Purpose

  • Create an empty file quickly: touch file.txt
  • Create a file with one line: echo "text" > file.txt
  • Append safely: echo "text" >> file.txt
  • Create multi-line files: heredoc (cat << 'EOF' > file)
  • Create with an editor: nano file.txt or GUI editor
  • Create from right-click: Templates folder

If you remember these, you can handle most “create a file” situations on Ubuntu without stress.

10.2 Beginner-Safe Workflow (Avoid Mistakes)

As a beginner, this workflow is the safest and most practical:

  1. Check where you are (pwd)
  2. Create a file (touch or editor)
  3. Confirm it exists (ls)
  4. If needed, check permissions (ls -l)

Once you’re comfortable, you can start using redirection and heredoc for speed.

10.3 Final Advice: Don’t Fear the Terminal—Use It Step by Step

Ubuntu is powerful because it gives you both GUI and terminal options.
You don’t have to master everything at once.

Start with:

  • touch for empty files
  • GUI editor for writing content
  • Templates for right-click file creation

And when you’re ready, add redirection and heredoc for faster work.

With these tools, you’ll be able to create files smoothly on Ubuntu—whether you’re a beginner or moving toward more practical tasks.