Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there a way to edit a file if there are no vi, vim, joe, mcedit? In another words is there a way to edit a file using just the shell commands?

share|improve this question
    
You don't even have the nano binary on your system? :S –  Breakthrough Aug 20 '12 at 19:25
1  
I don't have nano, either! –  Eduard Florinescu Aug 20 '12 at 19:26
    
Its a router, but also I've seen also a custom gateway in this situation :) –  Eduard Florinescu Aug 20 '12 at 19:32
    
Are you on DD-WRT? –  Breakthrough Aug 20 '12 at 19:34
1  
This also happened to me, in docker.. It is very minimalistic. Now how the heck do i do something like that. The VM is ephemeral, i cannot ssh nor ftp, i have to use redirection and hacks like sed to change some files. It was a great challenge. See how reliant we are on editors :P –  matejkramny Jun 26 at 21:33
show 3 more comments

4 Answers

up vote 6 down vote accepted

In that instance, I'd try transferring files out and editing them on another computer, then transfer them back. If you have ssh, you should have scp (I hope), so you should be able to push files in and out. If not, you can also look for ftp to transfer files in and out.

If not, then I think your best option is to try and make use of cat, grep, sed, echo, and I/O redirection (especially append with >>). And lots of temporary files.

Though if you have access to perl (or something similar), you can run it with no arguments and it will let you input a script source from standard input. Once you press ctrl+d, it can then run the script. You could use that method to create a file. It would be more powerful than hacking something on the command line as I mentioned before.

share|improve this answer
    
no sshd but I have telnetd –  Eduard Florinescu Aug 20 '12 at 19:37
    
Then can you ftp? –  Ben Richards Aug 20 '12 at 19:38
    
I can use cat, grep, echo, and I/O redirection (especially append with >>) but no sed –  Eduard Florinescu Aug 20 '12 at 19:42
1  
Ftp works :) now I need to see where on this router do I have something that is writable. –  Eduard Florinescu Aug 20 '12 at 19:50
3  
If you are connected to your device via telnet, I'd seriously think about just catting the file to the terminal (with a sufficiently large backscroll buffer), copy/pasting the entire thing into a local editor, making your changes, and then whipping up something that will turn that into a series of echo commands that will write a replacement file. –  afrazier Aug 20 '12 at 19:50
show 3 more comments

I imagine you could do what you need with grep and perl - look for the line you want with grep, edit that line with perl (perl can act like a big replacement for sed) and then confirm you didn't make more changes than you intended by doing diff filename filename.new. If so, make the changes permanent - mv filename.new filename

share|improve this answer
add comment

Did you wipe out /bin or something? Otherwise maybe you could hack something together with the text utilities in the GNU Coreutils that should be standard on a linux system.

share|improve this answer
add comment

Assuming you're SSH'ing into your router, you can also use various utilities to transfer the file back and fourth to your computer/router. You can download a copy on your PC, modify it, and then SSH it back to the router via SFTP (see Putty or WinSCP if you're a Windows user).

If you're using a custom firmware on the router/gateway, however, you may be in luck. There are various Optware packages containing simple (and small) text editors. Depending on your needs, you could get the nano package, or just go for busybox which contains vi.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.