After setting up a Cisco router, many administrators don't upgrade the IOS or access files on the Flash drive for quite a while. However, that doesn't mean there won't come a time when you need to manipulate the files on the Flash drive.
Working with the files and directories on the Cisco IOS file system (Cisco IFS) involves using the same types of commands as when manipulating files in Windows from the DOS command prompt. These commands include copy, dir, and format.
Here are some of the common uses of these commands:
- Back up the IOS before an upgrade.
- Perform an upgrade.
- Back up the configuration file before making changes.
- View text files on disk (such as a backup configuration file).
- Restore the Cisco IOS to a router.
Let's look at some of the Cisco IFS commands you need to know. By keeping some of the more commonly used commands in mind when upgrading and moving files to and from network devices, you can save time and perhaps even prevent a disaster.
The dir command shows files in a directory, and the default directory is usually the Flash file system. So, entering dir displays the directory of flash:/ by default.
You can also specify which directory you want to view, or you can use the all-filesystemsoption. You can even use the /recursive switch if you want to view files in subdirectories.
Here's an example:
Router# dir Directory of flash:/ 1 -rw- 15183868
c2600-ik9o3s3-mz.122-15.T9.bin 16777216 bytes total (1592488 bytes free) Router#
While most people are familiar with the general copy command, it involves a little more than just copying files from one place to another on a router or switch. In fact, this command is critically important to copying files to and from the router.
For example, to upgrade the IOS on a router, you must copy the new IOS from either the network or from a locally attached console port (via something like xmodem). You can also use the copy command to back up the configuration on both the router and over the network, as well as to restore the configuration from the network back to the router.
When using the copy command, you can use standard URL format to identify both the source and destination. Here's an example of what the URL path looks like for a network destination:
Below is an example of what the URL path looks like for a local file system. In this example, the path to the startup-config for the router is nvram:startup-config.
For example, you could back up a startup-configuration to a TFTP server's directory called router1, with an IP address of 184.108.40.206, using this same URL structure. Here's what it would look like:
Copy nvram:startup-configuration tftp://220.127.116.11/router1/startup-backup-2-8-2006
The show file command displays information about a specified file or file system. I consider this a "little-known" command because it typically doesn't get a lot of use.
The show file command's most useful options are show file information, which displays information about a specified file, and show file systems, which displays information about the file systems. Here's an example:
Router# show file systems File Systems: Size(b) Free(b) Type Flags Prefixes 29688 28899 nvram rw nvram: - - opaque rw system: - - opaque rw null: - - opaque ro xmodem: - - opaque ro ymodem: - - network rw tftp: * 16777216 1592488 flash rw flash: - - network rw rcp: - - network rw pram: - - network rw ftp: - - network rw scp: Router#
The more command shows a text file. This command works just like it does in Linux—it allows you to view a file on a disk. In the case of the Cisco IOS, you can use this command to view a text file, such as your configuration file or a saved backup configuration file. Here's an example:
Router# more nvram:startup-config
This command does just as it implies—it deletes files. There's really nothing special about this command, except for one thing: Depending on the type of router, deleting a file may not actually free up the file space the file was using. To reclaim the space the deleted files were using, you may need to use the squeeze command.
erase or format
Depending on the type of memory you're using, you can use either the erase or format command to wipe out the Flash drive. The erase command is the more common command used.
When copying files, you must be very careful to answer no to the question of whether you want to erase the file system. Here's an example:
Router# copy running-config flash:test Destination filename [test]? Erase flash: before copying? [confirm]
If you just press [Enter] and accept the default answer, you'll delete the IOS file when trying to back up your router's configuration to Flash.
cd and pwd
You can use the cd command to change directories, which works the same way in DOS and Linux. This command changes the directory to whichever directory you specify. You can use the pwd command to print the working directory, which also works the same way in Linux.
Let's look at an example. Notice that using the dir command displays the new working directory—the nvram file system—instead of the Flash default.
Router# cd nvram: Router# pwd nvram:/ Router# dir Directory of nvram:/ 27 -rw- 0
startup-config 28 ---- 0 private-config 29688 bytes total (29636 bytes free) Router#
mkdir and rmdir
Some routers and switches offer the ability to create and delete directories. You can use the mkdir command to create a directory, and the rmdir command will remove a specified directory. Obviously, you would need to use the cd and pwd commands to change into these directories.
For more information on how to use these commands, check out Cisco's Using the Cisco IOS Integrated File System documentation.
Miss a column?
Check out the Cisco Routers and Switches Archive, and catch up on David Davis' most recent columns.
Want to learn more about router and switch management? Automatically sign up for our free Cisco Routers and Switches newsletter, delivered each Friday!
David Davis has worked in the IT industry for 12 years and holds several certifications, including CCIE, MCSE+I, CISSP, CCNA, CCDA, and CCNP. He currently manages a group of systems/network administrators for a privately owned retail company and performs networking/systems consulting on a part-time basis.