Before working with file contents, we first need to know how to create a file in Linux.
Let’s start by creating a simple file using a safe, beginner-friendly command.
1️⃣ Creating a file
touch hello.txt
What it does:
Creates an empty file
If the file already exists, updates its timestamp
Does not add content
This is the safest way to create a file.
2️⃣ Verifying a file exists
ls -l hello.txt
Example output:
-rw-r--r--. 1 ec2-user ec2-user 0 Jan 22 04:05 hello.txt
This single line tells you everything important about the file.
3️⃣ Understanding file ownership (the two ec2-users)
Every file in Linux has two owners:
| Field | Meaning |
|---|---|
| Owner (user) | The user who owns the file |
| Group | The group that owns the file |
Owner: ec2-user
Group: ec2-user
4️⃣ Understanding permissions (-rw-r--r--)
Permissions are always checked in this order:
1 Owner
2 Group
3 Others
Breakdown:
-rw- r-- r--
│ │ └─ Others: read only
│ └─ Group: read only
└─ Owner: read & write
Meaning:
You (owner) can read and write the file
Group members can only read
Everyone else can only read
5️⃣ File type indicator
The first character shows the type:
| Symbol | Meaning |
|---|---|
- |
Regular file |
d |
Directory |
🎯 Key mental model (remember this)
Linux files always have:
An owner
A group
Permissions for owner, group, and others
This model applies to every file and directory on Linux.
Top comments (0)