Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

editing .conf files from CLI

New to Debian (Or Linux in general)? Ask your questions here!
Post Reply
Message
Author
slowmotion
Posts: 13
Joined: 2010-07-18 15:02

editing .conf files from CLI

#1 Post by slowmotion »

hello
i was wondering how can i edit a .conf file using the debian CLI
i tried doing it by accessing to the file graphically, but it wouldn't allow me to do changes on it, since i should have access as root
so i'm root on CLI, but the problem is i don't know how to edit the file from there (by "edit the file" i mean insert configuration lines in it)
anyone can help?
thanks

User avatar
roseway
Posts: 1528
Joined: 2007-12-31 22:50
Location: Kent, UK
Has thanked: 3 times
Been thanked: 4 times

Re: editing .conf files from CLI

#2 Post by roseway »

Many different ways, but the CLI editor nano is easy to use and does the job very well.

nano <filename>
Eric

slowmotion
Posts: 13
Joined: 2010-07-18 15:02

Re: editing .conf files from CLI

#3 Post by slowmotion »

thanks a lot
i also encountered something called "gedit <filename>", it opens the file in graphic mode, but with root privileges (if executed as root)

User avatar
nadir
Posts: 5961
Joined: 2009-10-05 22:06
Location: away

Re: editing .conf files from CLI

#4 Post by nadir »

gedit is a gui-editor.
To start it as you you will have to open it with gksu:

Code: Select all

gksu gedit <filename>
Or

Code: Select all

gksu gedit 
and open the file from the menu-bar. You might also do both commands from a command-prompt.

There is a howto about opening gui-apps as root in the how-to-section (by craigevil). I will add the link in a sec.
Voila, i am back:
http://forums.debian.net/viewtopic.php?f=16&t=53366
"I am not fine with it, so there is nothing for me to do but stand aside." M.D.

User avatar
Telemachus
Posts: 4574
Joined: 2006-12-25 15:53
Been thanked: 2 times

Re: editing .conf files from CLI

#5 Post by Telemachus »

If it's an important file (this is a general tip, not just for .conf files), and you are not very comfortable with the CLI, you should always make a backup first.

Here's one way to do that:

Code: Select all

cp -v /path/to/file.conf ~/file.conf-$(date "+%Y-%m-%d")
That makes a copy of the file with a simple datestamp in your home directory. After you make the copy, you can switch to root (if needed) and edit however you like. If things go very wrong, you still have the backup.
"We have not been faced with the need to satisfy someone else's requirements, and for this freedom we are grateful."
Dennis Ritchie and Ken Thompson, The UNIX Time-Sharing System

slowmotion
Posts: 13
Joined: 2010-07-18 15:02

Re: editing .conf files from CLI

#6 Post by slowmotion »

thank you nadir and telemachus

User avatar
Telemachus
Posts: 4574
Joined: 2006-12-25 15:53
Been thanked: 2 times

Re: editing .conf files from CLI

#7 Post by Telemachus »

You're welcome. Now that I think of it, I just wrote up a more detailed walk-through of this kind of thing in another thread. Check that out if you think it may help. For what it's worth, I think every Debian user should have at least a basic comfort level editing files in the CLI, just in case something ever happens and you can't get at the GUI. But there's certainly nothing wrong with using Gedit for most of your work.
"We have not been faced with the need to satisfy someone else's requirements, and for this freedom we are grateful."
Dennis Ritchie and Ken Thompson, The UNIX Time-Sharing System

jollysnowman
Posts: 134
Joined: 2009-08-29 19:42
Location: Austin, TX

Re: editing .conf files from CLI

#8 Post by jollysnowman »

Telemachus wrote:But there's certainly nothing wrong with using Gedit for most of your work.
::looks down in guilt::

I just like the syntax highlighting...

User avatar
Telemachus
Posts: 4574
Joined: 2006-12-25 15:53
Been thanked: 2 times

Re: editing .conf files from CLI

#9 Post by Telemachus »

jollysnowman wrote:
Telemachus wrote:But there's certainly nothing wrong with using Gedit for most of your work.
::looks down in guilt::

I just like the syntax highlighting...
Hmm. Vim and Emacs do that, no? (In the terminal, too. And in a modern terminal, you can usually get 256 color support as well.)
"We have not been faced with the need to satisfy someone else's requirements, and for this freedom we are grateful."
Dennis Ritchie and Ken Thompson, The UNIX Time-Sharing System

jollysnowman
Posts: 134
Joined: 2009-08-29 19:42
Location: Austin, TX

Re: editing .conf files from CLI

#10 Post by jollysnowman »

vim can do that? I guess I never bothered to look into it. And I never got used to emacs; I learned vi first and the emacs commands just felt unnatural.

User avatar
AMLJ
Posts: 973
Joined: 2009-03-18 07:40
Location: Mierlo, Netherlands
Contact:

Re: editing .conf files from CLI

#11 Post by AMLJ »

I love Vim, very cool one! :)
I suggest you use it!
AMLJ**0-1-47

User avatar
nadir
Posts: 5961
Joined: 2009-10-05 22:06
Location: away

Re: editing .conf files from CLI

#12 Post by nadir »

jollysnowman wrote:vim can do that? I guess I never bothered to look into it. And I never got used to emacs; I learned vi first and the emacs commands just felt unnatural.
Image
http://a.imageshack.us/img821/5853/editorshigh.png
left side: gedit. Top: gedit itself. Bottom: embedded-terminal in gedit with vim.
right site: terminal. Top: nano. Bottom: the missing emacs.
The question is not: which one has highlighting, but is there any editor out there without it?

Those commands:
http://forums.debian.net/viewtopic.php? ... 15#p309829
should get you going.

Two links:
http://www.swaroopch.com/notes/Vim
ftp://ftp.vim.org/pub/vim/doc/book/vimbook-OPL.pdf

I like gedit too.
"I am not fine with it, so there is nothing for me to do but stand aside." M.D.

Post Reply