How to delete files without breaking your site
The habits that keep a clean-up from turning into an outage, and what to do before deleting anything you cannot immediately identify.
Deleting files is the one file management task with no undo by default, which makes it the one worth slowing down for. This guide is less about the mechanics of deleting a file — that part is a right-click and a confirmation in any file manager or FTP client — and more about the habits that stop a routine clean-up from taking down part of a working site.
This is the single most important piece of advice in this article. Before removing more than a couple of files at once, make sure you have a recent backup of the account, or at minimum download a copy of the files you are about to delete. A deletion mistake is instantly recoverable with a backup and can be genuinely unrecoverable without one.
Work out what a file actually does before removing it
An unfamiliar file name is not the same as an unused file. Before deleting anything you did not put there yourself and do not immediately recognise, check whether it is referenced elsewhere:
- Search your site's code for its name. Many file managers include a search-in-files option, or you can use an FTP client to download and search a folder locally.
- Check whether it belongs to an installed application. Themes, plugins and modules for platforms like WordPress often include files with generic-looking names that are still actively used.
- When in doubt, rename rather than delete. Adding
.disabledor similar to the end of a file name stops it from being used the same way deleting it would, but keeps it recoverable in seconds if something breaks.
Delete in small batches, not all at once
If you are clearing out a folder with many files you believe are unused, remove a handful at a time and check the site after each batch rather than selecting everything and deleting it in one action. This turns a difficult question — "which of these forty files caused the problem?" — into an easy one, because you already know it was one of the last five you removed.
Know whether your file manager uses a trash folder
Some control panel file managers move deleted items into a trash or recycle folder rather than removing them from the server immediately, giving you a short window to restore something deleted by mistake. Others delete permanently and immediately, with no equivalent step. Check which behaviour your file manager has before relying on being able to undo a deletion — if it deletes immediately, treat every deletion as final from the moment you confirm it.
Unlike some browser-based file managers, deleting a file through an FTP client typically removes it straight away with no trash folder involved. Be more cautious deleting over FTP than you might be in a file manager that offers a safety net.
Deleting a whole folder is different from deleting a file
Removing a folder removes everything inside it in one action, including subfolders you may have forgotten were there. Before deleting a folder rather than an individual file, open it first and glance through its contents — a folder named after an old project can still contain something that turns out to be referenced elsewhere, and a folder delete gives you no per-file confirmation along the way to catch that.
Adding -old or similar to a folder name and leaving it in place for a week achieves almost the same tidiness as deleting it outright, while still being fully recoverable if something on the site turns out to depend on it. Only delete it outright once you are confident nothing broke.
Multi-selecting files in an FTP client
Most FTP clients let you select several files with Ctrl-click or Shift-click and delete them together, which is convenient but also the easiest way to remove more than you meant to with a single confirmation click. Double-check the selected count shown in the client, not just the highlighted rows, before confirming a multi-file delete — it is easy to include one extra row by accident when scrolling a long list.
Files that are safe to remove
| Usually safe to delete | Check carefully first |
|---|---|
| Old backup archives you have already restored and confirmed | Any configuration file — .htaccess, wp-config.php, and similar |
| Temporary files left over from a completed migration | Anything inside a theme or plugin folder for an active application |
| Duplicate copies you made yourself and no longer need | Files with generic names such as index.php or functions.php |
| Log files older than you need to keep for troubleshooting | Anything you did not create and cannot identify the purpose of |
If you delete the wrong thing
Stop making further changes and check your options immediately rather than trying to recreate the file from memory. If your account has automatic backups, most control panels let you browse a recent backup and pull a single file out of it without restoring the whole account. Our guide to getting back a file you overwrote covers the same recovery routes for a file that was deleted rather than edited, and our support team can check whether a server-side backup exists for your account if you are not sure.
Related reading
Where to look immediately after overwriting a file by mistake, in the order most likely to get it back without restoring anything you did not need to.
How to free up disk space on your accountWhere disk space actually goes on a typical hosting account, and what to clear before assuming you need a bigger plan.
How to back up your websiteFiles and database, taken together, kept somewhere other than the account they protect — here are three ways to manage both.
FTP, FTPS and SFTP: which to useThree protocols with confusingly similar names, one of which sends your password in the open. Here is what actually separates them.