dir
View IOS image files in flash storage before upgrades, verify file integrity, or check available space.
Definition: dir is a Cisco IOS privileged exec command. Lists files in the specified filesystem (flash, NVRAM, USB, bootflash). Shows file names, sizes in bytes, dates, and total/free space available.
Overview
The `dir` command in Cisco IOS is a fundamental tool for examining the contents of a device's file systems, such as flash memory, NVRAM, or bootflash. This command is essential for network engineers managing Cisco routers and switches, as it provides visibility into stored files like IOS images, configurations, and logs. Understanding the file system structure is critical for tasks such as upgrading IOS, backing up configurations, or troubleshooting boot issues. The `dir` command lists file names, sizes, modification dates, and available free space, enabling engineers to verify file integrity, check for sufficient storage before upgrades, and identify unexpected files that may indicate security issues or misconfigurations.
In the broader context of network troubleshooting and configuration, the `dir` command is often the first step in verifying that the correct IOS image or configuration file is present. For example, before performing an IOS upgrade, an engineer uses `dir flash:` to confirm there is enough free space and that the new image file has been successfully copied. Similarly, when troubleshooting a device that fails to boot, checking the contents of bootflash or flash can reveal missing or corrupted files. The command is also used to list files in NVRAM, which typically stores the startup configuration; verifying its contents helps ensure that the intended configuration will load on reboot.
Compared to alternatives like `show flash:` or `show file systems`, `dir` provides a more detailed listing, including file sizes and dates, which is crucial for managing multiple files. The `show file systems` command gives an overview of available file systems and their capacities, but `dir` drills down into a specific file system's contents. In IOS, the `dir` command can be used with various file system specifiers: `flash:` for internal flash, `nvram:` for NVRAM, and `bootflash:` for the bootflash (common on newer platforms). The command is available in Privileged EXEC mode (enable mode), requiring a privilege level of 15 by default. It does not affect the running configuration and is safe to use at any time.
One important IOS behavior to note is that output from `dir` may be buffered, meaning that if the file system contains many files, the output may be truncated or require the use of the `| more` pipe to view page by page. Additionally, on some platforms, the `dir` command can take a while to complete if the file system is large or slow. The command also supports wildcards (e.g., `dir flash:*.bin`) to filter specific file types, which is useful for quickly locating IOS images. Understanding these nuances helps engineers use the command efficiently in real-world scenarios.
dir [filesystem:][/all] [path]When to Use This Command
- List IOS image files in flash before a software upgrade to verify the new image uploaded correctly
- Check available flash space before uploading a new IOS image
- Verify the startup configuration file in NVRAM
- Confirm a file copied from TFTP or USB is present
Parameters
| Parameter | Syntax | Description |
|---|---|---|
| filesystem: | flash: | nvram: | bootflash: | Specifies the target file system to list. Common values are 'flash:' for internal flash memory, 'nvram:' for non-volatile RAM (stores startup-config), and 'bootflash:' for bootflash (used on some platforms like Catalyst switches). Omitting the filesystem defaults to 'flash:' on most platforms. A common mistake is using the wrong colon or forgetting the colon, which results in an error. |
Command Examples
List flash contents
Router# dir flash:
Directory of flash:/
1 -rw- 45389768 Oct 1 2025 00:00:00 +00:00 c2900-universalk9-mz.SPA.155-3.M4a.bin
2 -rw- 1899 Oct 1 2025 00:00:04 +00:00 startup-config.bak
258359296 bytes total (212969528 bytes free)Understanding the Output
Columns: index, permissions (-rw- = read-write), size in bytes, date/time, filename. Last two lines show total flash size and free space. Files beginning with . are hidden system files.
IOS image files are large (.bin extension, typically 50-100 MB for older platforms).
Configuration Scenarios
Verify IOS Image and Free Space Before Upgrade
A network engineer needs to upgrade the IOS on a Cisco 4321 router. Before copying the new image, they must verify that the flash file system has enough free space and that the current image is present.
Topology
R1 (Cisco 4321) with flash: file systemSteps
- 1.Step 1: Enter privileged EXEC mode: Router> enable
- 2.Step 2: List contents of flash: Router# dir flash:
- 3.Step 3: Note the free space reported at the end of the output (e.g., '12345678 bytes free').
- 4.Step 4: Check if the new image file (e.g., 'c4300-universalk9.16.09.05.bin') is already present.
- 5.Step 5: If free space is insufficient, delete unnecessary files using 'delete flash:filename'.
! No configuration changes are made; this is a verification step. Router# dir flash:
Verify: Expected output shows file listing with sizes and dates, ending with 'bytes total (xxx bytes free)'. For example: Directory of flash:/ 1 -rw- 12345678 Jan 1 2025 12:00:00 +00:00 c4300-universalk9.16.09.05.bin 2 -rw- 1234 Jan 1 2025 12:00:00 +00:00 startup-config 123456789 bytes total (111111111 bytes free)
Watch out: A common mistake is forgetting to include the colon after the filesystem name (e.g., 'dir flash' instead of 'dir flash:'), which results in an '% Invalid input detected' error.
Check NVRAM Contents for Startup Configuration
A router is booting with unexpected settings. The engineer suspects the startup configuration in NVRAM may be corrupted or missing. They use 'dir nvram:' to verify the presence and size of the startup-config file.
Topology
R2 (Cisco 4331) with nvram: file systemSteps
- 1.Step 1: Enter privileged EXEC mode: Router> enable
- 2.Step 2: List contents of NVRAM: Router# dir nvram:
- 3.Step 3: Look for the 'startup-config' file. Note its size (should be non-zero).
- 4.Step 4: If the file is missing or size is 0, the router will boot with factory defaults.
- 5.Step 5: To restore, copy a backup configuration to NVRAM using 'copy tftp: nvram:startup-config'.
! No configuration changes; verification only. Router# dir nvram:
Verify: Expected output shows files in NVRAM, typically including 'startup-config'. Example: Directory of nvram:/ 1 -rw- 1234 Jan 1 2025 12:00:00 +00:00 startup-config 32768 bytes total (31534 bytes free)
Watch out: NVRAM is often small (e.g., 32KB). If the startup-config is too large, it may be truncated. Always verify the file size matches expectations.
Troubleshooting with This Command
When troubleshooting file system issues, the `dir` command is invaluable for diagnosing problems related to storage, file corruption, or missing files. Healthy output from `dir flash:` should list files with reasonable sizes and dates, and end with a free space value that is not critically low. Problem indicators include: files with size 0 (indicating corruption or incomplete transfer), missing critical files like the IOS image or startup-config, or a free space value that is very small (e.g., less than 10% of total). For example, if `dir flash:` shows an IOS image file with size 0, the image is likely corrupted and the device may fail to boot. Similarly, if `dir nvram:` shows no startup-config file, the router will boot to the initial configuration dialog.
A step-by-step diagnostic flow for a router that fails to boot might be: 1) Connect via console and observe boot messages. 2) If the router drops to ROMMON mode, use `dir flash:` to list files. 3) If the IOS image is missing or corrupted, you may need to recover via TFTP or XMODEM. 4) If the image is present but the router still fails, check the boot variable with `show boot`. 5) Use `dir nvram:` to verify startup-config; if missing, the router may load default config. 6) Correlate with `show file systems` to see all available file systems and their capacities.
Specific fields to focus on: the file size (in bytes) and the date/time stamp. A file with a date far in the past may indicate an old image that should be updated. The free space value is critical before any copy operation. If free space is insufficient, use `delete` or `squeeze` to reclaim space. The `dir` command can also be used with the `| include` filter to quickly find specific files, e.g., `dir flash: | include .bin` to list only IOS images. Correlating `dir` output with `show version` helps confirm which image is currently running versus what is stored. For example, if `show version` indicates a different image than the one in flash, the boot variable may need adjustment.
Common symptoms that `dir` helps diagnose include: 'No such file or directory' errors during boot, 'Unable to open file' messages when copying, or 'Insufficient space' errors. By regularly checking file system contents, engineers can preemptively manage storage and ensure critical files are intact.
CCNA Exam Tips
CCNA exam: know that dir flash: lists flash contents, dir nvram: shows NVRAM files (startup-config)
Use show boot to see which file is configured to boot
To delete a file: delete flash:filename
Always check free space before copying a new IOS image to avoid a partial upload
Common Mistakes
Forgetting the colon after filesystem name (dir flash not dir flash:)
Not checking free space before uploading — a partial IOS image in flash can prevent the router from booting
Confusing dir (filesystem listing) with show flash (also shows flash contents on some platforms)
dir vs reload
Both dir and reload are privileged EXEC commands used during system maintenance, but dir inspects file storage while reload triggers a device restart.
| Aspect | dir | reload |
|---|---|---|
| Purpose | List files in a filesystem | Restart the device |
| Effect on System | Read-only, no state change | Causes device reboot, disrupts traffic |
| Safety | Safe, can be run at any time | Destructive, requires confirmation or scheduling |
| Dependencies | Filesystem must be accessible | Requires valid boot image and startup config |
| Typical Use | Check free space or locate IOS files | Apply config changes or load new IOS |
Use dir when you need to verify available storage or list files in flash or NVRAM.
Use reload when you need to restart the device to apply configuration changes or load a new IOS image.
Platform Notes
In IOS-XE (e.g., on Catalyst 9000 switches), the `dir` command syntax is identical, but the file system names may differ. For example, on some IOS-XE platforms, the default flash is accessed via `flash:` or `bootflash:`. Additionally, IOS-XE often uses a more complex file system structure with multiple partitions; `dir` can be used on each partition.
The output format is similar but may include additional fields like file permissions. For NX-OS (e.g., Nexus switches), the equivalent command is `dir` as well, but the file system names are different, such as `bootflash:` or `volatile:`. On NX-OS, the command also supports options like `dir bootflash:` and `dir volatile:`.
The output format is slightly different, with columns for permissions, links, owner, group, size, date, and name. For ASA firewalls, the equivalent command is `dir flash:` or `dir disk0:` (for internal flash). ASA uses a similar syntax but with file systems like `flash:` or `disk0:`.
In IOS-XR (e.g., on ASR 9000), the `dir` command is also available, but the file system names follow a different convention, such as `harddisk:` or `disk0:`. The output format in IOS-XR includes file permissions, links, owner, group, size, date, and name, similar to Unix. Behavior differences across IOS versions: In older IOS 12.x, the `dir` command may not support wildcards as extensively as in 15.x or 16.x.
Also, the output format in 12.x may be slightly different (e.g., no date column). In IOS 15.x and later, the output includes a date and time column, which is helpful for tracking file ages. Always check the specific platform documentation for exact file system names and options.
Related Commands
reload
Restarts the Cisco device, loading the IOS image specified by show boot and the startup configuration from NVRAM. Can be scheduled for a future time using 'reload in' or 'reload at'.
show boot
Displays the current boot system configuration including the IOS image file the router will load on next reload, the configuration register setting, and BOOT environment variable.
show inventory
Displays hardware inventory including chassis, modules, power supplies, and fan trays with their product IDs (PIDs), version IDs (VIDs), and serial numbers.
Practice for the CCNA 200-301
Test your knowledge with practice questions covering all CCNA 200-301 exam domains.
Practice CCNA 200-301 Questions