02 of 10 — Terminal Mastery
A practical guide to managing files and directories using Windows PowerShell, macOS, and Linux terminals.

Imagine you're working on a React project.

You need to create a new folder, move configuration files, rename directories, remove temporary files, and organize your project structure.

You could do all of this using File Explorer or Finder.

But what if you could accomplish the same tasks directly from your terminal?

That's exactly what we're going to learn in this article.

In the previous chapter, we explored what a terminal is, how shells work, and how to execute our first commands.

Now it's time to develop one of the most important command-line skills: filesystem navigation and management.

By the end of this article, you'll know how to:

  • Navigate between directories.
  • Understand absolute and relative paths.
  • Create files and directories.
  • Copy and move files.
  • Rename files and folders.
  • Delete files safely.
  • Find and work with hidden files.
  • Use wildcards to manage multiple files.

We'll cover Windows PowerShell, macOS Zsh, and Linux Bash throughout the article.

Let's get started.

1. Understanding the Filesystem

Before executing commands, let's understand how your computer organizes files.

A filesystem is the structure an operating system uses to store and organize data.

Most filesystems are organized hierarchically.

Think of it as a tree:

/ ├── home/ │ └── developer/ │ ├── Documents/ │ ├── Downloads/ │ └── Projects/ │ ├── react-app/ │ └── node-api/ │ ├── etc/ ├── var/ └── usr/ 

This is a simplified example of a Linux filesystem.

Directories can contain files and other directories. Those directories can contain even more directories.

This creates a hierarchical structure.

Windows Filesystem

Windows commonly uses drive letters to identify storage devices.

For example:

C:\ ├── Users\ │ └── Developer\ │ ├── Documents\ │ ├── Downloads\ │ └── Projects\ │ └── react-app\ │ ├── Program Files\ └── Windows\ 

macOS Filesystem

macOS uses a Unix-style directory hierarchy.

A typical user's home directory looks like this:

/ ├── Applications/ ├── System/ ├── Library/ └── Users/ └── developer/ ├── Desktop/ ├── Documents/ ├── Downloads/ └── Projects/ 

Linux Filesystem

Linux also uses a Unix-style hierarchy.

Some important directories include:

Directory Purpose
/ Filesystem root
/home Regular users' home directories
/root Root user's home directory
/etc System configuration files
/var Variable data and logs
/tmp Temporary files
/usr Userland applications and resources

Understanding these structures makes navigating the terminal much easier.

2. Understanding Paths

A path tells your operating system where a file or directory is located.

There are two fundamental types of paths.

Absolute Paths

An absolute path specifies a location from the filesystem's root or an equivalent starting point.

Examples:

Windows:

C:\Users\Developer\Documents\Projects 

macOS:

/Users/developer/Documents/Projects 

Linux:

/home/developer/Documents/Projects 

An absolute path doesn't depend on your current working directory.

You can reference the same location from almost anywhere.

Relative Paths

A relative path describes a location based on your current working directory.

Imagine your current location is:

/home/developer 

And you want to access:

/home/developer/Projects/react-app 

You can simply use:

Projects/react-app 

That's a relative path.

Relative paths are particularly useful when working inside software projects.

Three Special Path References

There are three important references you should recognize.

Current directory:

. 

Parent directory:

.. 

Home directory:

~ 

The ~ shortcut is commonly supported by Bash and Zsh. PowerShell also supports it as a home-directory shortcut.

For example:

cd .. 

Moves one directory up.

cd ~ 

Moves to your home directory.

cd . 

Keeps you in the current directory.

These references will appear frequently throughout your terminal journey.

3. Navigating Between Directories

Let's start with the command you'll probably use more than any other navigation command.

The cd Command

cd stands for Change Directory.

It allows you to move from one directory to another.

Windows PowerShell:

cd Documents 

macOS / Linux:

cd Documents 

The command is the same across these environments.

To move into a nested directory:

cd Projects/react-app 

On Windows, PowerShell also accepts forward slashes in paths.

You can use Windows-style separators too:

cd Projects\react-app 

Move One Directory Up

Use ..:

cd .. 

For example, if you're currently inside:

/home/developer/Projects/react-app 

After executing cd .., you'll be in:

/home/developer/Projects 

Move Two Directories Up

You can combine parent-directory references:

cd ../.. 

This moves two levels up.

Return to Your Home Directory

PowerShell:

cd ~ 

macOS / Linux:

cd ~ 

Return to the Previous Directory

Bash and Zsh provide a useful shortcut:

cd - 

This switches to your previous working directory.

PowerShell also supports cd - through its location stack and navigation behavior in common interactive usage, but for explicit directory-stack operations, use Push-Location and Pop-Location.

Check Your Current Location

Whenever you're unsure where you are, use:

PowerShell:

Get-Location 

macOS / Linux:

pwd 

Knowing your current directory prevents many common mistakes.

4. Listing Files and Directories

How do you know what's inside your current directory?

You need a command that displays its contents.

Windows PowerShell

Get-ChildItem 

Its common alias is:

ls 

You can also use:

dir 

macOS / Linux

ls 

To display detailed information:

ls -l 

To include hidden files:

ls -a 

To combine both:

ls -la 

A typical output might look like:

drwxr-xr-x 5 developer developer 4096 Nov 15 10:20 Projects -rw-r--r-- 1 developer developer 512 Nov 15 10:15 notes.txt 

Let's understand some of this output:

  • d indicates a directory.
  • - indicates a regular file.
  • r means read permission.
  • w means write permission.
  • x means execute permission.
  • The number represents the link count.
  • The owner and group identify file ownership.
  • The size indicates the file size in bytes.
  • The date indicates the last modification time.

We'll explore permissions in Article 05.

Listing Files in Another Directory

You don't need to navigate into a directory just to inspect it.

PowerShell:

Get-ChildItem Documents 

macOS / Linux:

ls Documents 

You can also provide an absolute path.

ls /home/developer/Documents 

5. Creating Directories

Let's create our first directory.

The mkdir command stands for Make Directory.

Windows PowerShell:

mkdir my-project 

macOS / Linux:

mkdir my-project 

Both commands create a directory named my-project in your current location.

Creating Nested Directories

What if you want to create several directories at once?

For example:

Projects/ └── frontend/ └── react-app/ 

On macOS and Linux:

mkdir -p Projects/frontend/react-app 

The -p option creates missing parent directories as needed.

In PowerShell, you can use:

New-Item -ItemType Directory -Force -Path "Projects/frontend/react-app" 

You can also use mkdir with a nested path when the parent directory already exists.

Creating Multiple Directories

On macOS and Linux:

mkdir project-a project-b project-c 

In PowerShell:

mkdir project-a, project-b, project-c 

This creates three directories in your current location.

6. Creating Files

Directories organize files. But how do you create files directly from the terminal?

The answer depends on your shell.

Windows PowerShell

Use New-Item:

New-Item -ItemType File -Name "index.html" 

Create a JavaScript file:

New-Item -ItemType File -Name "app.js" 

You can also use the ni alias:

ni index.html -ItemType File 

macOS / Linux

Use touch:

touch index.html 

Create another file:

touch app.js 

You can create multiple files:

touch index.html style.css app.js 

Important: touch creates an empty file if it doesn't exist. If the file already exists, it updates its access and modification timestamps rather than deleting its contents.

Create a File with Initial Content

In PowerShell:

"Hello, Terminal!" | Set-Content hello.txt 

In Bash or Zsh:

echo "Hello, Terminal!" > hello.txt 

The > operator redirects output into a file.

If the file already exists, its previous contents are overwritten.

We'll explore redirection in detail in Article 04.

7. Copying Files and Directories

Sometimes you need to duplicate files without removing the original.

That's what copying is for.

Copying a File

Windows PowerShell:

Copy-Item app.js backup.js 

macOS / Linux:

cp app.js backup.js 

This creates a copy named backup.js.

Copying a File into Another Directory

PowerShell:

Copy-Item app.js Documents/ 

macOS / Linux:

cp app.js Documents/ 

The original file remains in its original location.

Copying Directories

For PowerShell:

Copy-Item project project-backup -Recurse 

For macOS / Linux:

cp -r project project-backup 

The recursive option tells the command to include the directory's contents.

Be careful: Copying large directories can consume significant disk space. Always verify your destination before executing recursive copy commands.

8. Moving and Renaming Files

Moving and renaming are closely related operations.

Moving a File

PowerShell:

Move-Item app.js Documents/ 

macOS / Linux:

mv app.js Documents/ 

This moves app.js into the Documents directory.

Renaming a File

You can also use the same commands to rename files.

PowerShell:

Rename-Item app.js main.js 

macOS / Linux:

mv app.js main.js 

The original file is now named main.js.

Renaming a Directory

PowerShell:

Rename-Item old-project new-project 

macOS / Linux:

mv old-project new-project 

Moving and Renaming at the Same Time

You can move a file and give it a new name in one operation.

mv app.js Documents/main.js 

In PowerShell:

Move-Item app.js Documents/main.js 

This moves the file into Documents and renames it to main.js.

9. Deleting Files and Directories

Deletion is one area where you should be especially careful.

Some terminal commands can permanently remove data without sending it to the Recycle Bin or Trash.

Always double-check the target before executing a deletion command.

Deleting a File

Windows PowerShell:

Remove-Item old-file.txt 

macOS / Linux:

rm old-file.txt 

Deleting an Empty Directory

PowerShell:

Remove-Item empty-folder 

macOS / Linux:

rmdir empty-folder 

The Unix rmdir command only removes empty directories.

Deleting a Directory and Its Contents

PowerShell:

Remove-Item old-project -Recurse 

macOS / Linux:

rm -r old-project 

The recursive option removes the directory and its contents.

A Critical Safety Warning

You may encounter this command online:

rm -rf some-directory 

Let's break it down:

  • rm removes files and directories.
  • -r recursively removes directory contents.
  • -f forces removal without interactive confirmation for many situations.

This command can permanently destroy data.

Never execute commands like this without understanding their target and consequences.

Also, avoid copying destructive commands from unknown websites or tutorials.

A useful habit is to inspect the target first:

ls -la some-directory 

In PowerShell:

Get-ChildItem some-directory -Force 

Then decide whether deletion is actually necessary.

10. Working with Hidden Files

Not every file appears in a normal directory listing.

Operating systems and applications often use hidden files to store configuration and metadata.

For example, a typical JavaScript project might contain:

my-project/ ├── src/ ├── public/ ├── package.json ├── package-lock.json ├── .gitignore ├── .env └── .editorconfig 

Files beginning with a dot are commonly treated as hidden files on Unix-like systems.

Examples include:

  • .gitignore
  • .env
  • .bashrc
  • .zshrc
  • .editorconfig

Show Hidden Files on macOS / Linux

ls -la 

Show Hidden Files in PowerShell

Get-ChildItem -Force 

Show Hidden Files in Windows CMD

dir /a 

An important distinction:

On Unix-like systems, a leading dot is a naming convention for hidden files.

On Windows, hidden files generally have a filesystem attribute.

These are different mechanisms.

Developer tip: If you're working with React, Node.js, or Git, learning to inspect hidden files is essential. Many important configuration files begin with a dot.

11. Using Wildcards

Wildcards allow you to match multiple files using patterns.

They become incredibly useful when managing large directories.

Two common wildcard characters are:

  • * matches zero or more characters.
  • ? matches one character in many common command-line tools.

Example: List All JavaScript Files

macOS / Linux:

ls *.js 

PowerShell:

Get-ChildItem *.js 

Example: Copy All CSS Files

macOS / Linux:

cp *.css backup/ 

PowerShell:

Copy-Item *.css backup/ 

Example: List Files Starting with "app"

ls app* 

This can match:

app.js app.css application.json 

Wildcard behavior depends on the shell and command being used. PowerShell also has its own wildcard handling, which differs from Bash filename expansion.

Always test a pattern by listing its matches before using it in a destructive operation.

12. Practical Project: Build a Directory Structure

Let's combine everything we've learned.

Imagine you're starting a new frontend project.

You want this structure:

terminal-practice/ ├── src/ │ ├── components/ │ ├── pages/ │ └── styles/ │ ├── public/ │ └── images/ │ ├── docs/ │ ├── index.html ├── app.js └── README.md 

Let's build it.

Step 1: Create the Main Directory

PowerShell:

mkdir terminal-practice cd terminal-practice 

macOS / Linux:

mkdir terminal-practice cd terminal-practice 

Step 2: Create Nested Directories

PowerShell:

mkdir src, public, docs mkdir src/components, src/pages, src/styles, public/images 

macOS / Linux:

mkdir -p src/components src/pages src/styles public/images docs 

Step 3: Create Files

PowerShell:

New-Item -ItemType File -Name index.html New-Item -ItemType File -Name app.js New-Item -ItemType File -Name README.md 

macOS / Linux:

touch index.html app.js README.md 

Step 4: Verify the Structure

PowerShell:

Get-ChildItem -Recurse 

macOS / Linux:

find . -print 

You should now have a directory structure similar to the one shown above.

Congratulations! You've just created a small project structure entirely from the terminal.

13. Common Mistakes Beginners Should Avoid

Here are some mistakes that can cause unnecessary frustration.

1. Forgetting quotation marks around paths with spaces

Incorrect:

cd My Projects 

Correct:

cd "My Projects" 

2. Confusing absolute and relative paths

A relative path depends on your current location. An absolute path doesn't.

Check your location before executing commands.

3. Deleting files without checking the target

Especially when using recursive deletion commands.

4. Assuming commands behave identically across shells

PowerShell, CMD, Bash, and Zsh have different syntax and features.

5. Forgetting that filenames can be case-sensitive

A filename that works on your Windows machine may behave differently on a Linux server.

6. Running commands from the wrong directory

A simple pwd or Get-Location can prevent mistakes.

14. Practice Challenges

It's time to test your knowledge.

Try completing these tasks without looking at the solutions.

Challenge 1: Directory Navigation

  1. Open your terminal.
  2. Navigate to your home directory.
  3. Create a folder named terminal-lab.
  4. Enter that directory.
  5. Display its current location.

Challenge 2: File Management

Inside terminal-lab:

  1. Create three files: index.html, style.css, and app.js.
  2. Create a directory named backup.
  3. Copy app.js into backup.
  4. Rename the original app.js to main.js.
  5. List all files and directories.

Challenge 3: Nested Directories

Create the following structure:

terminal-lab/ ├── frontend/ │ ├── components/ │ └── pages/ │ ├── backend/ │ ├── routes/ │ └── controllers/ │ └── docs/ 

Use as few commands as possible.

Challenge 4: Hidden Files

  1. Create a file named .env.
  2. List the directory normally.
  3. List it again with hidden files included.
  4. Compare the results.

Challenge 5: Safe Cleanup

  1. Create a directory called temporary.
  2. Create a file inside it.
  3. Inspect the directory contents.
  4. Remove the directory and its contents.

Remember to verify the target before deletion.

Quick Command Reference

Here's a compact reference you can save for later.

Operation PowerShell macOS / Linux
Current location Get-Location pwd
List files Get-ChildItem ls
Show hidden files Get-ChildItem -Force ls -la
Change directory cd cd
Home directory cd ~ cd ~
Create directory mkdir mkdir
Create file New-Item touch
Copy file Copy-Item cp
Move file Move-Item mv
Rename file Rename-Item mv
Delete file Remove-Item rm
Remove directory Remove-Item -Recurse rm -r
List recursively Get-ChildItem -Recurse find . -print

Note: These are common equivalents, not perfectly interchangeable commands. Their options, defaults, and behaviors can differ.

What's Next?

You've learned how to navigate directories, manage files, create project structures, and work with hidden files.

But there's another important question:

What if you have thousands of files and need to find one specific file or search for a particular piece of text?

That's where searching and filtering become essential.

In Article 03, we'll explore:

  • Finding files by name.
  • Searching inside files.
  • Reading file contents.
  • Filtering command output.
  • Using find, grep, and PowerShell's Select-String.
  • Searching through real development projects.

Next Article: Searching, Reading and Managing Files from the Terminal

Final Thoughts

The filesystem is the foundation of almost everything you do in a development environment.

Once you understand how paths, directories, and file operations work, the terminal becomes much less intimidating.

You don't need to memorize every command today.

Practice the basics, experiment in a safe directory, and gradually build confidence.

Remember:

A developer who understands the filesystem can work efficiently on almost any operating system.

Happy coding!

---nced Terminal Workflows and Troubleshooting