Creating and Removing Files: A Guide to Linux File Manipulation
Master essential file manipulation in Linux. Learn how to create files with touch, safely remove files with rm, and manage directories with rmdir.

Previously in this course, we used Project Kickoff: Provisioning Web Server Directories to scaffold the structure for our hardened web server. Now that we have our directories in place, we need the ability to create and remove files within them to manage our configuration assets and logs.
Effective file manipulation is a core skill for any DevOps engineer. Whether you are creating a placeholder index file or deleting a temporary log file that is consuming disk space, these commands are your primary tools.
Creating Files with the touch Command
In Linux, the touch command is the standard way to create an empty file. While it was originally designed to update the access and modification timestamps of existing files, its most common use in automation and project management is simply to create a new, zero-byte file if it doesn't already exist.
If you are just getting started with your project, you might want to create a placeholder configuration file.
Bash# Navigate to your project directory cd ~/web-server/config # Create an empty configuration file touch server.conf
If you run ls -l (as covered in The ls Command: Listing and Inspecting Files in Linux), you will see the file server.conf listed with a size of 0 bytes. touch is non-destructive; if you run it on an existing file, it simply updates the timestamp rather than overwriting your content.
Removing Files with rm

When you need to clean up temporary files or remove deprecated configurations, use the rm (remove) command. This command is powerful and, by default, permanent—there is no "trash bin" in the CLI.
To remove a single file:
Bashrm temp_log.txt
To remove multiple files at once, you can pass multiple arguments:
Bashrm file1.txt file2.txt
The Power of Flags
The rm command is often used with flags to make operations safer or more aggressive:
-i(interactive): Prompts you before removing every file. Use this if you are hesitant about what you are deleting.-f(force): Ignores non-existent files and never prompts for confirmation. Use this carefully, especially when scripting.
Removing Directories with rmdir
The rmdir command is designed specifically for removing empty directories. It is a safety-first command: if the directory contains even a single file, rmdir will refuse to delete it.
Bash# This will only work if 'logs' is completely empty rmdir logs
If you try to remove a directory that contains files, you will receive an error: rmdir: failed to remove 'logs': Directory not empty. This serves as a built-in safety net to prevent you from accidentally deleting project data.
Comparison: Deleting Objects
| Command | Target | Behavior |
|---|---|---|
touch | Files | Creates a new file or updates timestamps |
rm | Files/Directories | Deletes files; can delete directories with -r |
rmdir | Directories | Only removes empty directories |
Hands-on Exercise
Let’s apply this to our web server project:
- Navigate to your
~/web-server/logsdirectory. - Use
touchto create a file namedaccess.log. - Use
lsto verify it exists. - Use
rmto deleteaccess.log. - Navigate back to
~/web-serverand usermdirto remove yourlogsdirectory (ensure it is empty first!).
Common Pitfalls
- The "Recursive" Danger: You might be tempted to use
rm -rfto delete directories. Be extremely careful; the-r(recursive) flag tellsrmto delete the directory and everything inside it, including subdirectories. Always double-check your path before hitting enter. - Permissions: You may encounter a "Permission denied" error if you try to delete files created by another user or the root account. We will cover how to manage these permissions in upcoming lessons.
- Wildcard Misuse: Using
rm *is a common way to empty a directory, but if you are in the wrong folder (like/), you can accidentally delete system files. Always verify your location withpwdbefore using wildcards.
Recap

You now know how to create empty files with touch, remove unwanted files with rm, and safely remove empty directory structures with rmdir. These commands allow you to maintain a clean and organized project environment as you build out your server.
Up next: We will learn how to duplicate and relocate your data using the cp and mv commands.
Work with me

VPS Server Setup, Deployment & Hardening
Get your app live on a fast, secure server — properly configured, hardened, and deployment-ready. No more wrestling with the command line.

Custom Email & File Storage System on Cloudflare (Google Workspace Alternative)
Your own private email + file storage suite on your domain — unlimited mailboxes, no per-seat fees. A self-owned Google Workspace alternative for a flat ~$5/month.

