Create or Edit a File on Cisco IOS Flash

There is always the option to edit a file locally on your computer in notepad++ and then upload it to Cisco device.

With this trick, you can write or edit a file from Flash memory directly from Cisco IOS console. If you need it for whatever reason, maybe to change something in the config file or something else, this is the way to do it.

I was using if for my next article lab where I needed a file on the flash with at least 1600 bytes so I can pull it from neighbouring router with HTTP and check some details in new TCP connection. It was faster to just create the file directly on the router flash and not creating it on my laptop and then transferring it with FTP or TFTP.

I used Cisco IOS Tcl shell which is available on Cisco devices to allow running Tcl scripts and commands directly from the Cisco IOS CLI prompt. I think that this is the only way of changing text files from Cisco console, correct me in the comments if you know of something else.

Next example will create a text file named test.txt, put some words inside and save the file on Cisco device flash.

R2#tclsh
R2(tcl)#puts [open "flash:test.txt" w+] {
+>(tcl)#With this trick, you can write or edit a file
+>(tcl)#from Flash memory directly from Cisco IOS console. 
+>(tcl)#} 
R2(tcl)#tclquit

Or just copy-paste the stuff below when in Privileged EXEC mode:

tclsh
puts [open "flash:test.txt" w+] {
With this trick, you can write or edit a file 
from Flash memory directly from Cisco IOS console. 
}
tclquit

We then check if the new file is in the flash:

R2#dir flash:
Directory of flash0:/

1 drw- 0 Jan 30 2013 00:00:00 +00:00 boot
 264 drw- 0 Oct 14 2013 00:00:00 +00:00 config
 267 -rw- 126335008 Mar 21 2014 00:00:00 +00:00 vios-adventerprisek9-m
 270 -rw- 524288 May 6 2014 21:55:20 +00:00 nvram
 271 -rw- 199 Feb 28 2018 14:43:40 +00:00 e1000_bia.txt
 272 -rw- 100 Mar 1 2018 09:20:50 +00:00 test.txt

2142715904 bytes total (2011242496 bytes free)

And we can even use more command to read the content of the file on the console:

R2#more test.txt
With this trick, you can write or edit a file
from Flash memory directly from Cisco IOS console.
R2#

9 Comments

  1. RG September 13, 2019
  2. Dave R Dougher May 18, 2020
  3. Ecze May 26, 2020
  4. Dave R Dougher May 27, 2020
  5. Dave R Dougher May 27, 2020
  6. Hannon August 4, 2021
  7. Alejandro August 13, 2021
  8. Andrew Woolman August 25, 2021
  9. Dan June 24, 2022

Leave a Reply