M08 - File Operations: Create and Edit
File Operations: Create and Edit
Create folders and files from the terminal, write simple text safely, and make small edits without relying on a full GUI workflow.
- Create folders and files from the terminal.
- Write new content or append a line safely.
- Make a small text edit using a terminal-friendly workflow.
Why This Matters
Most CLI work is not dramatic. It is small, careful changes:
- create a working folder
- add a config file
- write one line to a log or notes file
- make a simple text change on a machine that has no desktop environment
This module stays with those real tasks. We are not trying to master every editor. We are building safe first habits.
1. Create Folders
The terminal is often the fastest way to create a clean structure.
Create one folder
mkdir Project
Create a nested structure
mkdir -Force Project\docs\notes
Create one folder
mkdir Project
Create a nested structure
mkdir -p Project/docs/notes
Use nested creation when you already know the structure you want.
2. Create Empty Files
Sometimes you want the file to exist first, then fill it in later.
New-Item -ItemType File -Path .\notes.txt
touch ./notes.txt
This is common for placeholders, logs, and simple config files.
3. Write or Append Text
You do not always need a full editor. Sometimes one command is enough.
Replace the file contents
Set-Content -Path .\notes.txt -Value “first line”
Add a new line at the end
Add-Content -Path .\notes.txt -Value “second line”
PowerShell also supports redirection, but Set-Content and Add-Content are easier for beginners to read.
Replace the file contents
echo “first line” > ./notes.txt
Add a new line at the end
echo “second line” >> ./notes.txt
One Critical Difference
> replaces the file. >> adds to the end. If you are not completely sure which one you need, stop and check the file first.
4. Make a Small Edit
For a short change, use the simplest tool that is available on the system you are on.
notepad .\notes.txt
On Windows, launching Notepad from the terminal is still a valid CLI workflow. It is often the most practical choice for a beginner.
nano ./notes.txt
Save: Ctrl+O, then Enter
Exit: Ctrl+X
nano is enough for this stage. You do not need vim yet.
The goal is not to prove you are advanced. The goal is to make the change correctly.
A Safe Practice Loop
Try this in a practice folder:
- Create a folder called
sandbox. - Create a file called
todo.txt. - Write one line into it.
- Append one more line.
- Read the file back to confirm the result.
If that feels easy, you are learning the right thing.
What to Ignore for Now
- advanced shell redirection tricks
vimcommands and modal editing- editing system files in
/etcor other privileged locations
Those are real topics, but they are not required for your first reliable workflow.
Before You Move On
You are ready for the next module when you can:
- create a folder tree
- create a new file
- replace file contents on purpose
- append a second line on purpose
Next, we add the operations that require more care: copy, move, rename, delete, and archive.