PDA

View Full Version : How do I edit files in the terminal?



edkilp
14th July 2004, 04:57 PM
Hi, all. I needed to make a couple changes in a file requiring root privelages. I was logged in on my non-root account. I tried to figure out how to edit my grub.conf file as root in the terminal, but I couldn't figure it out. I ended up logging out, back in as root, edit file, log out again and back in as me. I know there's a better way to do this. Can someone please give me the proper command for editing files in the shell? Thanks
ed

Varkk
14th July 2004, 04:59 PM
use "su" to become root this will only apply to the current terminal session. use exit to return to your user session.

topazz
14th July 2004, 05:08 PM
Open the Terminal window, type su - to become root, type your password then type gedit /etc/grub.conf to open grub.conf in the text editor. If you prefer another text editor type in its name instead of gedit.

When you have finished with the terminal window type exit twice to close the window.

Optimistic
14th July 2004, 06:11 PM
You could also use vi /etc/grub.conf after you log in as root in the terminal. vi is pretty nice and really simple. You might have to press the insert key so that you can edit the document, after you edit hit escape and type :wq. That's a : then a w for write and a q for quit. *Puff*, your back in the terminal and the changes were saved. I also like Midnight Commander to edit text in a terminal, you can get it here: http://www.ibiblio.org/mc/

topazz
14th July 2004, 06:41 PM
You could also use vi /etc/grub.conf after you log in as root in the terminal. vi is pretty nice and really simple. You might have to press the insert key so that you can edit the document, after you edit hit escape and type :wq. That's a : then a w for write and a q for quit. *Puff*, your back in the terminal and the changes were saved. I also like Midnight Commander to edit text in a terminal, you can get it here: http://www.ibiblio.org/mc/

I have not used Vi before as I have heard it was for more "advanced" users, which I most certainly am not. ;)

It is interesting how the grub.conf file appears in the Console for editing rather than opening the text editor like gedit does.

Regarding the ":wq" - I can understand the "q" part, but what does the "w" do? Is that the "save" command? I could quit Vi without using the "w", but I did not edit the document.

Optimistic
14th July 2004, 06:49 PM
Yep, the "w" writes the edited document, i.e., it saves it with the changes you made.

topazz
14th July 2004, 06:52 PM
Thanks for that, I will have to add it to my (expansive!) notes. :)

AliOop
14th July 2004, 07:08 PM
If I may add my two cents. Use gedit as your text editor. It's the easiest to use in my opinion. Which translates into "GUI" front end. When you get a message like 'not a directory" that means you need a editor. Gedit is the way to go for now. It's simple and with the gui front end easy to understand. Wait until later for the geek's choice like vi, emac, pico, joe and the others. No offense to the fans of those editors but for what most folks do, you can't beat gedit. When you first bring up a terminal you'll notice a $ sign. You are the "local user". With SU and you root password you'll notice that change to the #. You are now the Admin/Superuser. Now you can do all kinds of things including wrecking your system.
So be careful.

imdeemvp
14th July 2004, 07:35 PM
i agree with AliOop.....gedit is the easiest editor....learn to use and stick to it :D

Harryc
15th July 2004, 12:10 AM
Gedit is good and I use it, but you really need to learn to use another editor(like vi) in case X is not up. You may not understand what this means now, but you will someday when your machine won't boot :).

edkilp
15th July 2004, 12:19 AM
Thanks, guys. I appreciate the help.
ed

sailor
15th July 2004, 04:20 AM
ok my 2 cents then...use Midnight Commander...it has a file manager (much like Norrton Commander) and file editor...all runs in terminal...makes it easier to find files if you don't know the exact location...plus all the permmission tools...untar...open rpms...etc

type mc in terminal....it is included on the FC2 disks