Networking

The 10 Cisco IOS Router file management commands you must know

David Davis goes over the Cisco IOS commands you must know to manipulate files on your Cisco router flash, nvram, or other filesystems, allowing you to back up your configuration, upgrade your router, or just maintain the IOS file system.

Just like a Windows or Linux operating system, the Cisco IOS has its own list of commands to manipulate files, very similar to DOS/Windows commands. These files could be your IOS router operating system, configuration file, or other type of IOS file. Knowing these file commands is a critical requirement for any Cisco admin.

Let's look at 10 Cisco IOS file management commands you must know.

#1 dir

This shows a directory list of files on a filesystem. To see the options, type dir ?

Router#dir ?
  /all             List all files
  /recursive       List files recursively
  all-filesystems  List files on all filesystems
  archive:         Directory or file name
  cns:             Directory or file name
  flash:           Directory or file name
  null:            Directory or file name
  nvram:           Directory or file name
  system:          Directory or file name
  tar:             Directory or file name
  tmpsys:          Directory or file name
  xmodem:          Directory or file name
  ymodem:          Directory or file name
  <cr>
Router#
You can think of each of these filesystems almost like disk drives in DOS, where you have to put a colon after the name. So, the nvram is called nvram:. The default is to show a directory of the router's flash as your default current directory is flash:
Router# dir
Directory of flash:/
    2  -rwx    18929780  Aug 29 2006 15:49:57 +00:00  c870-advipservicesk9-mz.124-15.T5.bin
    3  -rwx        2143  Aug 29 2006 16:42:14 +00:00  running-config
23482368 bytes total (4544512 bytes free)
Router#

Every router will have at least flash memory and nvram (non-volatile random access memory).

#2 cd

Change directory: Use cd to change your current directory to a different device or subdirectory on that device. In the following, when I change my directory to the nvram: filesystem and do a dir, I get a list of nvram. I could also cd to a subdirectory after I have created a directory with mkdir.

Router#cd nvram:
Router#dir
Directory of nvram:/
  126  -rw-        2143                    <no date>  startup-config
  127  ----           5                    <no date>  private-config
  128  -rw-        2143                    <no date>  underlying-config
    1  ----          49                    <no date>  persistent-data
    2  -rw-           0                    <no date>  ifIndex-table
131072 bytes total (116584 bytes free)
Router#
#3 copy

This is used to copy the IOS or a config file from and to somewhere. You would use this to copy the router's configuration off the router to a TFTP server or just make a local backup of it on the router. You would also use the copy command to upgrade the router with a new IOS from a TFTP server.

Here, I am making a local backup of the router's running configuration:

Router#copy running-config davids-backup-before-upgrade
Destination filename [davids-backup-before-upgrade]?
2181 bytes copied in 3.052 secs (715 bytes/sec)
Router#
#4 delete and rm Very simply, you will use delete to delete files and rm to remove folders/directories. Here, I use delete to delete the backup of my config that I just created:
Router#delete davids-backup-before-upgrade
Delete filename [davids-backup-before-upgrade]?
Delete flash:/davids-backup-before-upgrade? [confirm]
Router#
#5 show flash This is used to show the files in your flash. The command show flash is similar to dir flash: but it provides a little more information on the size and type of flash memory in your router.
Router#show flash
24576K bytes of processor board System flash (Intel Strataflash)
Directory of flash:/
    2  -rwx    18929780  Aug 29 2006 15:49:57 +00:00  c870-advipservicesk9-mz.124-15.T5.bin
    3  -rwx        2181   Oct 4 2006 04:03:00 +00:00  mybackup-today
23482368 bytes total (4544512 bytes free)
Router#
#6 erase and format

It can be a bit confusing why you would erase one type of filesystem, but format another. What you really need to know is that you format flash devices and erase nvram. There are other types of filesystems, and you may erase or format them, depending on their type. The erase command is most used when you want to wipe out the router's configuration and start with a default configuration. This is done with erase startup-configuration.

Router# erase ?
  /all                       Erase all files(in NVRAM)
  /no-squeeze-reserve-space  Do not reserve space for squeeze operation
  flash:                     Filesystem to be erased
  nvram:                     Filesystem to be erased
  startup-config             Erase contents of configuration memory
Router# format ?
  flash:  Filesystem to be formatted
Router#
#7 more This shows a text / configuration file. Let's say that you want to view a backup configuration file that you created. Just use the more command to view it:
Router# more my-backup-config
!
version 12.4
parser config cache interface
parser config interface
{config truncated}
#8 verify

This is used to verify the checksum or compute a MD5 signature for a file.

Router#verify flash:c870-advipservicesk9-mz.124-15.T5.bin
Verifying file integrity of flash:c870-advipservicesk9-mz.124-15.T5.bin.......{truncated}............ Done!
Embedded Hash   MD5 : CA8AEC573B197AEC6BD5892DE23C4754
Computed Hash   MD5 : CA8AEC573B197AEC6BD5892DE23C4754
CCO Hash        MD5 : 9D39672246853C0F31533B6BCB21DFE5
Embedded hash verification successful.
File system hash verification failed for file flash:c870-advipservicesk9-mz.124-15.T5.bin(No such file or directory).
Router#
#9 mkdir

Just like in DOS, you use mkdir to create a directory/folder. I would do this to perhaps create an archive folder for backup configurations or old IOS files.

Router# mkdir backup-configs
Create directory filename [backup-configs]?
Created dir flash:backup-configs
Router#
#10 fsck

FAT filesystem check is typically used to check your flash filesystem integrity. You may do this if you have experienced some corruption of your IOS files in flash.

Router# fsck
Fsck operation may take a while. Continue? [confirm]
.....{truncated}.......
Fsck of flash: complete
Router#

While there are so many reasons to use file system commands like these, if I had to select three of the most practical uses for some of the commands listed above, here is my list:

  1. Navigating the Cisco IOS filesystems -- knowing what configuration files and what IOS files are on the router, perhaps before performing an upgrade.
  2. Back up your configuration to the local router or off to a TFTP server, again, perhaps before a backup
  3. Performing an upgrade of the Cisco IOS by copying the IOS from a TFTP server to the router.

It's very important to understand IOS file management commands, what those commands are, and how you can use them in the real world. You don't want to be stumbling to restore your IOS when the primary IOS is corrupt!

Need help configuring, administering, supporting, and optimizing network infrastructure? Then turn to our free Network Administration NetNote. Automatically sign up today!

12 comments
rwhybrow
rwhybrow

I am so impressed with this Daily Digest, its great to get practical tips like these.

career
career

On some older models, you had to use the "squeeze" command to actually delete files after the "delete" command.

arunn2009
arunn2009

i was join ccna.. so advice me. how to learn networking.. i dont know.. so guide me. mail: arunn2009@gmail.com

johnnyjeanmarc
johnnyjeanmarc

Very Interessing !!! Thanks a lot Mr. David, I do really appreciate because you teach us News in every Post. Thanks Again, Cheers.

nwgarner
nwgarner

Also, you can partition disks, they must be formatted after partitioning. Example: SUP720-3BXL#partition disk1: 2 60 62 Partitioning will destroy all data in "disk1:". Continue? [confirm] Primary Partition created...Size 60 MB Extended Partition created...Size 62 MB Drive communication & 1st Sector Write OK... Extended Partition entry 1 created...Size 62 MB Extended Partition Table 1 Write OK... Partition of disk1: complete SUP720-3BXL#format disk1:0: Format operation may take a while. Continue? [confirm] Format operation will destroy all data in "disk1:0:". Continue? [confirm] Writing Monlib sectors.... Monlib write complete Format: All system sectors written. OK... Format: Total sectors in formatted partition: 122848 Format: Total bytes in formatted partition: 62898176 Format: Operation completed successfully. Format of disk1:0: complete SUP720-3BXL#format disk1:1: Format operation may take a while. Continue? [confirm] Format operation will destroy all data in "disk1:1:". Continue? [confirm] Format: All system sectors written. OK... Format: Total sectors in formatted partition: 127456 Format: Total bytes in formatted partition: 65257472 Format: Operation completed successfully. Format of disk1:1: complete SUP720-3BXL#dir disk1:0: Directory of disk1:0:/ No files in directory 62742528 bytes total (62742528 bytes free) SUP720-3BXL#

em_er
em_er

mkdir, right really helpful but only in new HW. Unfortunatelly I havea lot of old stuff and there is no chance to use that usefull command

rhino777
rhino777

"Back up your configuration to the local router or off to a TFTP server, again, perhaps before a backup" backup before a backup? you crazy! ;) Good article.

nwgarner
nwgarner

That's a Supervisor 720-3BXL in a 6506 running 12.2(33)SXH4.