Courseiva
SystemPrivileged EXEC

delete [file]

Deletes a file from the device's flash memory or other storage, used to remove unwanted configuration files, IOS images, or other stored data.

Definition: delete [file] is a Cisco IOS privileged exec command. Deletes a file from the device's flash memory or other storage, used to remove unwanted configuration files, IOS images, or other stored data.

Overview

The 'delete' command in Cisco IOS is used to remove files from the device's flash memory or other storage media. This command is essential for managing storage space, especially on devices with limited flash capacity, such as routers and switches used in CCNA and CCNP labs. Deleting unwanted files—like old IOS images, configuration backups, or core dumps—frees up space for new software upgrades or prevents storage exhaustion that could cause system instability.

The command operates at the file system level, directly interacting with the storage medium (e.g., flash:, usbflash0:). It is typically executed in Privileged EXEC mode (enable mode) and requires a privilege level of 15. Unlike 'erase' which wipes entire file systems, 'delete' targets individual files.

A common workflow involves first using 'dir' to list files and verify the exact filename, then 'delete' to remove it. The command does not affect the running configuration unless the deleted file is the startup configuration (then 'copy running-config startup-config' is needed to save changes). Important IOS behavior: the command prompts for confirmation by default; this can be suppressed with the '/force' option.

Also, deleted files may be recoverable if the device supports 'undelete' (e.g., on some platforms with 'squeeze' functionality). For CCNA/CCNP candidates, mastering file management is crucial for software upgrades and disaster recovery scenarios.

Syntax·Privileged EXEC
delete [file]

When to Use This Command

  • Remove an old IOS image to free up space before upgrading to a new version.
  • Delete a backup configuration file that is no longer needed.
  • Clean up temporary files or core dumps from flash memory.
  • Remove a corrupted file that prevents the device from booting properly.

Parameters

ParameterSyntaxDescription
filefilesystem:filenameSpecifies the path and name of the file to delete. The filesystem prefix (e.g., flash:, usbflash0:) is required unless the default filesystem is set. Common mistake: omitting the colon after the filesystem name, e.g., 'flashmyfile' instead of 'flash:myfile'. Use 'dir' to confirm the exact filename and path.
/force/forceSuppresses the confirmation prompt. Useful in scripts or when deleting multiple files. Without this option, the user must respond 'yes' or 'no' to each file. Caution: using /force can lead to accidental deletion.
/recursive/recursiveDeletes a directory and all its contents recursively. Only applicable when deleting directories. Without this option, deleting a non-empty directory fails. Common mistake: forgetting to use /recursive when deleting a folder with files.

Command Examples

Delete a specific file from flash

delete flash:old-config.cfg
Delete filename [old-config.cfg]? 

The command prompts for confirmation before deletion. Typing 'yes' or pressing Enter (if default is yes) will delete the file. No output is shown after successful deletion.

Delete a file with forced confirmation

delete /force flash:unwanted-image.bin

The /force option suppresses the confirmation prompt. The file is deleted immediately with no output. Use with caution.

Understanding the Output

The delete command typically produces no output upon success, or only a confirmation prompt. If the file does not exist, an error like '%Error deleting flash:file (No such file)' appears. If the file is in use (e.g., boot image), the deletion may fail with '%Error deleting flash:file (File in use)'.

Always verify with 'dir' after deletion.

Configuration Scenarios

Delete an old IOS image to free flash space for an upgrade

A network engineer needs to upgrade the IOS on a Cisco 4321 router but the flash memory is nearly full. An older IOS image (c1100-universalk9-mz.SPA.157-3.M1.bin) must be removed to make room for the new image.

Topology

R1 (flash: 256MB) — standalone router

Steps

  1. 1.Step 1: Enter privileged EXEC mode: Router> enable
  2. 2.Step 2: List files in flash to identify the old image: Router# dir flash:
  3. 3.Step 3: Delete the old IOS image: Router# delete flash:c1100-universalk9-mz.SPA.157-3.M1.bin
  4. 4.Step 4: Confirm deletion when prompted: Delete filename [c1100-universalk9-mz.SPA.157-3.M1.bin]? [enter]
  5. 5.Step 5: Verify free space: Router# dir flash:
Configuration
! No configuration changes needed; this is a file system operation.
Router# delete flash:c1100-universalk9-mz.SPA.157-3.M1.bin
Delete filename [c1100-universalk9-mz.SPA.157-3.M1.bin]? 
Are you sure? [yes/no]: yes

Verify: Router# dir flash: | include Free Expected output: 'Free space: 150000000 bytes' (or similar, showing increased free space)

Watch out: If the IOS image is currently running, the delete will fail. Ensure the device is booted from a different image or use 'delete /force' only after confirming the image is not in use.

Delete a startup configuration backup to clean up flash

A technician has multiple backup copies of the startup configuration (startup-config.bak, startup-config.old) on flash and wants to remove them to reduce clutter.

Topology

SW1 (flash: 64MB) — standalone switch

Steps

  1. 1.Step 1: Enter privileged EXEC mode: Switch> enable
  2. 2.Step 2: List configuration files: Switch# dir flash: | include startup
  3. 3.Step 3: Delete the backup file: Switch# delete flash:startup-config.bak
  4. 4.Step 4: Confirm deletion: Delete filename [startup-config.bak]? [enter]
  5. 5.Step 5: Delete another backup: Switch# delete flash:startup-config.old
  6. 6.Step 6: Verify remaining files: Switch# dir flash: | include startup
Configuration
! No configuration changes.
Switch# delete flash:startup-config.bak
Delete filename [startup-config.bak]? 
Are you sure? [yes/no]: yes

Verify: Switch# dir flash: | include startup Expected output: 'startup-config' (only the active startup config remains)

Watch out: Deleting the active startup-config file (startup-config) will cause the device to boot with factory defaults on next reload. Always keep at least one valid copy.

Troubleshooting with This Command

The 'delete' command itself is not a troubleshooting tool, but it is often used after diagnosing storage issues. Healthy output from 'dir' shows adequate free space and expected files. Problem indicators include 'No space left on device' errors when trying to copy files, or 'File not found' when attempting to delete a file that doesn't exist.

When troubleshooting storage problems, first use 'show file systems' to list available filesystems and their capacities. Then use 'dir filesystem:' to see file sizes and free space. If flash is full, identify large files (like IOS images or core dumps) using 'dir /all' to see hidden files.

Use 'delete' to remove unnecessary files. A step-by-step diagnostic flow: 1) Check free space with 'dir flash:'. 2) If low, list files sorted by size: 'dir /size flash:'. 3) Identify candidates for deletion (old IOS, backups, core dumps). 4) Verify the file is not in use (e.g., running IOS image). 5) Delete with confirmation. 6) Recheck free space. Correlate with 'show version' to see the current IOS image name, ensuring you don't delete it.

Also, 'show flash:' provides a summary of flash usage. If a file cannot be deleted due to permissions, check if it is protected (e.g., IOS image in use). In some cases, 'squeeze' may be needed to permanently erase deleted files and recover space.

For NX-OS, the equivalent is 'delete [filesystem:]filename' with similar options. On ASA, use 'delete /noconfirm flash:filename'.

CCNA Exam Tips

1.

Remember that the delete command requires the full file path (e.g., flash:filename).

2.

The /force option is useful in scripts but dangerous in exams—know when it's appropriate.

3.

Deleting the running-config file is not possible; use 'erase startup-config' instead.

4.

CCNA may test the difference between 'delete' and 'erase' (erase is for startup-config or entire flash).

Common Mistakes

Forgetting to specify the file system (e.g., flash:) leading to 'Invalid input detected'.

Deleting the active IOS image, causing the device to fail to boot until a new image is loaded via TFTP/Xmodem.

Not verifying free space before deletion, leading to accidental deletion of important files.

delete [file] vs dir

Both 'delete [file]' and 'dir' are file management commands used in Privileged EXEC mode. They are commonly considered together because 'dir' is typically used to verify the files present before deleting them, ensuring the correct file is targeted and confirming the deletion was successful.

Aspectdelete [file]dir
Primary actionRemoves specified fileLists file contents
Effect on filesystemPermanently erases file dataNo modification, read-only
Required parameterFilename or pathOptional filesystem (default flash:)
OutputNone on success (error if not found)File list with size, date, free space
SafetyIrreversible; no confirmation by defaultSafe; no risk to data

Use delete [file] when you need to free up storage space by permanently removing a specific file such as an old IOS image or configuration backup.

Use dir when you need to inspect the contents of a filesystem, check available space, or verify the exact filename before performing a delete or copy operation.

Platform Notes

In IOS-XE (e.g., Catalyst 9000 switches), the 'delete' command syntax is identical to classic IOS, but the filesystem naming may differ (e.g., 'flash:' vs 'bootflash:'). On some IOS-XE platforms, 'delete /force' is required to remove files without prompts. The NX-OS equivalent is 'delete [filesystem:]filename' with optional '/force' and '/recursive' flags.

For example, on Nexus switches: 'delete bootflash:old_image.bin'. On ASA firewalls, the command is 'delete [/noconfirm] filesystem:filename', where '/noconfirm' suppresses prompts. ASA also supports 'delete /recursive' for directories.

In IOS-XR, the command is 'delete [location node-id] [filesystem:]filename' with options like '/force' and '/recursive'. Note that IOS-XR uses a different file system hierarchy (e.g., /disk0:/). Between IOS versions, the behavior is consistent, but older versions (12.x) may not support '/force' or '/recursive'.

Always check the specific platform documentation. For CCNA/CCNP study, practice on IOSv or IOS-XE images in GNS3/EVE-NG to understand the nuances.

Related Commands

Practice for the CCNA 200-301

Test your knowledge with practice questions covering all CCNA 200-301 exam domains.

Practice CCNA 200-301 Questions