Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Editing Text Files In the Shell Environment - How??? 4

Status
Not open for further replies.

kjv1611

New member
Jul 9, 2003
10,758
0
0
US
I tried tying together a couple of different tutorials for setting up Ubuntu 7.04 Server Edition for primarily a home file server.

But there is one hurdle that I just cannot seem to get past. That is editing the text files.

Every walk-through that I've gone into tells how to get into each text file to edit, but it does not tell you how you are supposed to then save and close the edited text file, nor how best to navigate and edit. If I could get some basic information from somewhere on how to edit the text files within nothing but Shell, I think I'd be well on my way.

Does anyone have any links or suggestions along these lines?

I need to know what command or key combinations you can enter while in the text document to do different things.

Also, it seems that some key combinations do some strange things - such as Alt + F2, Alt + F4, etc. It seems that sometimes, one of those will take me back to the server login, and another will go to a previous screen, and yet another will go to yet another screen. And I've no idea as to why or how.

And I've tried all sorts of key combinations to figure out how to change between edit modes, etc, but they don't seem to stay the same, so I'm basically just pecking at my keyboard to no avail.

The walk-throughs that I am using are rat I don't know if I'm just that dense, or what the situation is.

My only previous experience of working with the Shell environment was when I actually setup a Windows share on a laptop using the live CD of Ubuntu 6 in order to backup the files from that computer to my "main computer" over my home network. That was a pretty neat experience, but it was MUCH easier to operate within the Shell.

Now, honestly, because my experience with Linux is so limited, I don't think I can find too basic of learning materials or advice right now.

--

"If to err is human, then I must be some kind of human!" -Me
 
Having been forced to use vi/vim, you can easily modify text files. I haven't learned the intricacies of it (unless you are a die-hard unixphile -- sorry folks.. it is butt ugly)
Start your file as follows;

$ vi <filename>

Once in vi, press the I key to insert and you will be able to make your changes.
When you are ready to save the file press <ESC> followed by : and then wq (write/quit)

I used to use pico which was for my tastes pretty good, but it seems to have disappared from the later distros.

Hope this helps
 
Alt + [F1 to F6] switches you over from one virtual console to another. Alt + F7 brings you to X if a session is already started.

Most editing will be done via the vi or vim editor. Now for a quick vi/vim tutorial. In vi/vim you will have 2 modes - edit & command. When you first enter into vi/vim, you will be in command mode. To go into edit mode, press either a (append) or i (insert). To return to command mode just press the esc key. In command mode:
dd - delete line
cc - cut line
yy - copy line
p - paste
x - delete character at cursor
u - undo
:w - save file
:w! - force save
:q - quit editor
:q! - force quit

Entering a number before some commands act to repeat the command. i.e.
4dd - delete 4 lines
5x - delete 5 characters
20cc - cut 20 lines

This should get you going for now but I suggest you read up on the vi/vim manual for more information.

--== Anything can go wrong. It's just a matter of how far wrong it will go till people think its right. ==--
 
Which editor are you using? There are several terminal-based editors available, the most popular being versions of vi and emacs (both quite complex) and basic ones like pico and nano. I use vim, an enhanced version of vi. Each one has its own way of working, so we can't discuss specific editing commands until you have decided which one to use.
 
I thought I was giving the first reply, but the other 3 beat me to it!
 
Okay, I'm going through all your advice/info right now. But, based on the first post, I want to specify (sorry I didn't so far):

I was using the vi editor apparently, because this is the command I am using to view/edit the text:
Code:
sudo vi /etc/network/interfaces

I hope that helps a little as far as understanding my question...

And I think I have this much understanding so far, as far as what that command is saying:
sudo - run the process as another user (root in my case, and I'm guessing most cases?

vi - choosing the editor

/etc/network/interfaces/ - I suppse this is choosing the text file - the file location and name, with the last one - "interfaces" in this case- being the file name...

As far as the second post:
Having been forced to use vi/vim, you can easily modify text files. I haven't learned the intricacies of it (unless you are a die-hard unixphile -- sorry folks.. it is butt ugly)
Yeah, that has been my experience with it so far. At least I know I'm not alone. [wink]

I'll try some of this HOPEFULLY tonight. If I do not get around to it - which is highly possible - then I may not be able to get to it again until the end of this week. Either way, I'll post ASAP.

--

"If to err is human, then I must be some kind of human!" -Me
 
Oh, and thanks for the links, and short references here in the thread. This will hopefully get me going just perfectly! So far from what I can read here, it will make a big difference.

--

"If to err is human, then I must be some kind of human!" -Me
 
One question I just thought of - based on looking at the in depth list from [blue]zeland[/blue]:

Is there any limit to using multiple commands at the same time?

In other words, I can do this to save:

If in edit mode, I press <Esc>, then type:
:w!:q!
one one line...

Or would I type:
:w!q!

I'm thinking the second one, going by what [blue]itsp1965 [/blue]said.

--

"If to err is human, then I must be some kind of human!" -Me
 
Just type :wq or the equivalent shortcut command ZZ .
The exclamation marks are only needed when you need to override any objections the editor may have.
 
There are also other editors such as 'pico' which has some visual heritage back to MS DOS (lots of CTRL- keystrokes)

If you're in Gnome or KDE there are tons of "human" oriented editors that work like applications with menus and such...

Did I mention 'sed/awk'?? LOL!!!!!

D.E.R. Management - IT Project Management Consulting
 
Thanks, geirendre, I'll take a look at that for sure as well.

--

"If to err is human, then I must be some kind of human!" -Me
 
I don't like the vi comes with the ubuntu 7.04, or other debian.

Try this
sudo apt-get install vim
sudo update-alternatives --config editor

and select option 4.
Now do another vi. now it's easy like a redhat vi. no?
:)

just remember press esc and type q to exit or w to save
so wq! is force save then quit.

and to edit press insert key, or press it twice to "replace
 
Thanks, sillyVM.

For now, I've just gone with Mandriva for the setup, as it recognized the BIOS RAID for my system drive with MUCH less headache than Ubuntu 7.04 has. So, once I got in, I have just been using Konsole mostly for any work in Shell, and I haven't really had to edit any text files directly, as I've only run some commands in Konsole. Otherwise, I've used some GUI tools for configuring varying options. Oh, and I've decided just to not worry about setting up a static IP just yet. I'll just wait and see, and only do that if I have to. [smile]

Slowly but surely, I'm working my way through this whole adventure!

Oh, and before I forget, I might end up putting Ubuntu on there as well, sort of as a dual-boot setup, so that I can try both, and learn both that way over time. Of course, I just want to get all the basics working with Mandriva, and ONLY THEN will I mess with anything else for now.

--

"If to err is human, then I must be some kind of human!" -Me
 
Sounds good. As much as I like ubuntu, I don't like the fact it didn't boot off my hardware raid. Also the video card driver is such a hassle. So I still use windoze for desktop.

But the server has worked out well for me.
 
My plans are (so far) to get it working as a desktop/server combination so that I can:
#1: have a file server (as well as eventually mysql, web, and ftp server)
#2: I can remote in from the Windows machine, and tinker around in the desktop portion of it, and use that as a further learning tool.

But I've got to get #1 finished first! [wink]

--

"If to err is human, then I must be some kind of human!" -Me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top