Introduction to Linux: Class 3 Notes

Emacs

Emacs tutorial

We are now going to follow essentially the same process as we did for vi, only using Emacs. This will familiarize you with a number of features of the editor.

Let us start Emacs by running 'emacs testemacs'

You can immediately start typing. You will note that you can use either the arrow keys or the mouse to move the cursor. You can select text with the mouse, but it will not affect your deleting ability.

At this point, I should probably inform you that you can run Emacs from a text-based environment. You simply will not have the mouse.

Now then, let's get into some options. In Emacs, all options are prefixed with either Ctrl or Alt. In Emacs, these options are shown as C-x (for Control) or M-x (for Alt). The 'M' stands for 'Meta', which is an early modifier key that Alt replaced.

To go to the beginning of a line, press Ctrl-a. To go to the end, press Ctrl-e.

To erase a single character, you can press Ctrl-d.

To undo actions, you press Ctrl-/.

To erase an entire line, go to the beginning of the line and press Ctrl-k (for 'kill line')

You can perform a command multiple times by pressing Alt-n before hand, where n is the number of times to repeat the command.

For instance, pressing Alt-4 Ctrl-d will delete 4 characters.

Sometimes, you need to quickly navigate a large file.

Press Alt-< to go to the top of a file.

Press Alt-> to go to the end of a file.

To go to a specific line, enter "Alt-x goto-line". You will be asked what line to go to. Enter a number, and you will go there. So to go line 38, you would enter:

Alt-x goto-line <Enter>
38 <Enter>

To save a file, you enter Ctrl-x Ctrl-s.

Editor options, unlike in vi, are generally changed graphically or through customization. You can see at the top, under the "Options" menu, is an option for "Customize". This allows you to graphically customize Emacs without writing Lisp code.

Now let's delete everything. To do this, we go to the beginning of the file and set a mark:

Alt-<
Ctrl-SPACE

We now go to the end of the file:

Alt->

To erase everything from the mark to the cursor, we press Ctrl-W.

Now onto copying and pasting lines. To do this, you set a mark at the point to start the copy, move the cursor to where you want to stop the copy, and then choose to either cut or copy.

So to copy a line, we do the following:

Ctrl-a to go to the beginning of the line
Ctrl-SPACE to set a mark
Ctrl-e to go to the end of the line
Ctrl-W to cut OR Alt-W to copy

To paste the line, we move the cursor to where we want the pasting to occur, and press Ctrl-Y.

Now let's show off some of the developer-oriented features of Emacs. To quit Emacs, we press Ctrl-x, Ctrl-c. It asks if we want to save. This is pretty simple to understand: press 'y' for yes and 'n' for no. If you say no, it will ask you one more time to verify (you need to enter the word 'yes' at that point).

Anyway, let's move on to some source code. Let's create another C source file:

'emacs test.c'

You will notice a very similar occurrence to what happened in vi: we have syntax highlighting!

Let's type the following C program:

#include <stdio.h>

int main()
{
	printf("This is my main function!\n");

	return 0;
}

Similarly to before, we can search for words. Let's search for 'main' again. We press Ctrl-S to enter the search, and then type 'main'. To cycle between matches, we press Ctrl-S again. To go backwards. I can press Ctrl-r instead.

One last thing to show you on Emacs is its help system: the Emacs help system was essentially a revolution in application help. To get very simple help, you can press Ctrl-h, c, then press the command you want help on. To get a very in-depth description, press Ctrl-h, k, then the command you want help on.

For full help, you can press Ctrl-h, i.

It does need to be noted that Emacs's commands seem much longer and more complex. Remember that this is completely uncustomized: most Emacs users will make major modifications to Emacs. There is a built-in system to help with this, and many libraries available online.

To go through the official Emacs tutorial, you can press Ctrl-h, t while in Emacs.

Text Editor Conclusion

Remember that vi and Emacs can both do EXACTLY THE SAME THING. They simply take different approaches towards it. It is important to be familiar with both of these, as sometimes it is necessary to use one over the other.

Distributions

When you download and install Linux, you are installing what we call a 'distribution'. For instance, what we are using is called "Gentoo Linux". A distribution generally contains the Linux kernel (possibly modified) and a great many other packages. Many distributions also embody a particular philosophy and a particular method of installing extra packages.

Although every Linux distribution uses the same Linux, different distributions can be very different to use. At least a basic understanding of the various distros is very important to their use and the ability to recommend one or use one for a business.

Red Hat Linux

I'd like to start with Red Hat, which is one of the world's most successful Linux distros. Red Hat began in 1993, and originally offered the aptly-named Red Hat Linux distribution. This was a popular distro for both business and desktop use. As Red Hat began to focus more and more on the business side of its distribution (Red Hat Enterprise Linux), it decided to make its community distro entirely community-run, renaming it to "Fedora Core".

Red Hat's legacy does persist today. Fedora Core is a very common new-user distro, and Red Hat's package manager, called RPM (originally Red Hat Package Manager, now RPM Package Manager), is one of the most common in the Linux world today. Fedora Core uses Gnome as its default Destkop Manager, and uses the package manager yum to install new packages.

Red Hat also deserves special mention because its Enterprise version is the most common in the business world. Red Hat provides a number of sysadmin certifications for RHEL.

SuSE Linux

SuSE is another big player in the Linux market, as it is controlled by Novell. SuSE was begun as a German translation of the Slackware distro (more on this later). It was then purchased by Novell in 2003, and so it has remained since.

SuSE is also a binary-based distro which uses the RPM format. It uses a tool called YaST that manages its packages and also provides graphical applications for configuring many services, including the firewall, partitioning, and the user database.

SuSE used to use KDE as its desktop environment, but now provides a choice between Gnome and KDE.

SuSE also provides both community and business versions of the distro. The community version is free and is called openSUSE, and the paid version comes with professional support and a number of proprietary programs.

Slackware Linux

Slackware is currently the oldest still-maintained Linux distro out there. Begun in 1993, the distro quickly gained a reputation for stability, as only packages that were on a stable release (as opposed to a developer release) were included.

Slackware uses a different init style than most Linux distributions: it employs the BSD-style as opposed to the more common System V style. This means that Slackware's init system is controlled through a single file, as opposed to one of a collection of runlevels.

Slackware's package management style is also fairly minimalist: it is generally binary-based, but dependencies are unmanaged (as opposed to yum or YaST). Therefore, one has to track down dependenices on his own.

Debian GNU/Linux

Debian is one of the most well-known distros in the Linux world. It is generally commended for its stability and powerful package manager. Debian was also founded in 1993 on the basis that a distro should cater exclusively to free software. For this reason, Debian only includes in its official releases software that is released entirely under what they consider a free license. For this reason, proprietary graphics card drivers are not included, nor are many media codecs. It should be noted that this software CAN be obtained for Debian, only it is not available by default.

Debian's oft-mentioned stability is a result of the release cycle: a new stable release may not occur for many, many years. As a result, stable releases tend to contain older software, but this is software that has been heavily tested with many holes closed. The stable branch is very popular for servers, while many desktop users use the unstable or testing branch of releases. The current stable release was released in 2005, and the one before that in 2002.

Debian's package management system is binary-based as well, but is managed by a very popular and very good manager called Apt. A package installed by Apt also has all of its dependencies installed, and Apt is renowned for its enormous package selection.

Ubuntu Linux

Ubuntu deserves special mention: it is based on Debian, but is designed specifically for new users. It was started by Mark Shuttleworth, a millionaire from South Africa, but is currently maintained by a large community. It is notable for providing only a graphical interface and for allowing root access only through a method known as sudo (as opposed to su). It uses Apt for its package manager, but because its focus is usability over free software, there is better support for proprietary packages.

Gentoo Linux

Gentoo Linux is a distro based on a slightly different philosophy than most others: complete and total control. Gentoo is designed to allow the user ease in doing exactly what they want to do. To this end, very little is automated for you, and there are essentially no restrictions on packages.

Gentoo was founded in 1999, and became very popular amongst people who wanted to optimize their computers. The distro gained a reputation for speed and for requiring a certain familiarity with Linux. This was due to the fairly difficult install process (compared to other distros): you were dropped into a console and were expected to manually write all configuration files and run some scripts to set up everything on your computer.

Gentoo uses a source-based package manager called Portage, which is based on a similar concept in BSD. When a packge is installed through Portage, its source code is downloaded and compiled using optimization flags selected by the user. For this reason, packages tend to run slightly faster, but install times are significantly longer than on a binary-based distro. Like Apt and yum, Portage will manage dependencies for the user.

Conclusion

There are many, many distros out there. It is likely that any Linux user will go through many of these distros: I myself have used 7 distros to date.

The single most common question asked by users new to Linux is: "What distro should I use?" And the answer is up to you: no one can tell what approach you will like the most. As a rule, however, I generally recommend either SuSE or Ubuntu for new users: both are very well-known distros, have large communities, and, in my experience, are easy to use and configure.

Desktop Environments

I have spoken before about desktop environments. What do I mean?

Well, you've probably used the Solaris machines downstairs, and you know that they look very different from the interface we are using here. Both of these computers use X Windows to display their graphics, so where does this difference come from? It comes from the desktop environment.

What is a desktop environment? It is generally defined as a suite of applications that controls your desktop. There is the window manager, which is what actually displays your windows, moves them, etc. There are then applications that let you view the filesystem [show them Nautilus], applications that let you access the shell directly (terminals), configuration applications, etc. You also have a desktop, with icons and launchers, and other fun things. You will generally have a sound server, as well as a number of other general applications. These may include text editors, maybe a word processor, image viewers, an e-mail client, a web browser, etc.

On these computers, we are seeing a desktop environment called Gnome. Gnome is one of two very popular desktop environments, the other being KDE. Gnome was created by GNU for the purpose of being a free DE. It uses the Gtk graphics toolkit, which is released under the GPL, and as you can see, uses a style somewhat unlike Windows.

The other popular DE is called KDE, which stands for K Desktop Environment (very creative). KDE is actually the older of the two, and it uses the Qt widget toolkit, which has a strange licensing. Originally, Qt was free (as in beer) to use for open-source projects, but not free (as in speech). Nowadays, Qt is free in both manners for open-source projects, but Gnome is already around, so it stays. KDE has a little bit more of a Windows-like layout for its menu, but it has its own charm.

These are the two most popular desktop environments, but they are not the only choices. Xfce is a popular desktop environment that is more minimalist than either Gnome or KDE but which is still attractive. There is a window manager called Blackbox that has spawned a number of derivatives, all ending in *box. There is Ion, which is run entirely by the keyboard. There is Enlightenment, which is currently attempting to build an entirely new graphics backend, and which is looking to be very nice.

Note that the ones I've just mentioned are generally window managers: they tend to not come with as much bundled software. Fluxbox, for instance, is controlled by 4 text files, while Openbox is controlled by 2. They come with some utilities, generally, but not text editors or anything of that sort.

Most distros nowadays do offer choice in which desktop environment you can use. Debian and Gentoo make it pretty easy, Ubuntu provides 3 different versions of itself (Ubuntu, Kubuntu, Xubuntu), and most others at least let you choose between Gnome and KDE.

Licenses

One final topic to discuss today is licensing. For developers, it is important to understand what license to use for your code; for users, it is important to ensure that your software meets your personal philosophy.

First to understand is just what exactly a license is. A license is the legal part of software: what the user is allowed to do with your software. For instance, under Windows and Mac OS X, most licenses say you cannot reverse engineer it, you cannot decompile the software, etc. In the Linux world, licenses are the opposite, rather telling you what you CAN do. This is more complex than it would seem at first.

The most common license in the Linux world is the GNU General Public License (GPL). This license grants copyright of the code to the developer, but grants a great deal of freedom to the users. In particular, if a user legally obtains the software (by purchasing it or downloading it or any way that the developer chooses), he MUST be able to obtain the source code. Further, he may modify the source code, redistribute the source code, do essentially whatever he likes with it. There is a catch, however: the redistributed code MUST be made available under the GPL as well. This is to prevent a person or company from taking a GPL'd piece of software and redistributing it as proprietary software. The Linux kernel is distributed under this license, as is GCC (and essentially every application from GNU), and most applications available under Linux.

On the subject, there is also a license called the Lesser GNU General Public License (LGPL), which allows proprietary software to link with the code, but the code itself remains essentially under the GPL. This is commonly used for libraries: anyone may use the libraries, but the libraries themselves will always remain under the LGPL.

The other license of note to speak of is the BSD License. This license is far more common under the BSD operating systems, obviously, but it does have a place in the Linux world. The BSD license essentially says "This code is open-source, but anyone may modify it and release their modifications under any license they wish." This means that anyone can use my code (even proprietary software), and while they must give credit to the original author, they do not need to release their code under the same license.

There is a story about this. There is a program called Wine that allows you to run some Windows applications under Linux. Wine used to be available under a BSD license. A company (Transgaming) came in, took the code, and made a number of modifications, and released their code under a proprietary license, which they could legally do. Then Wine changed to the GPL, and now Transgaming can no longer take code from Wine. Now, though these two projects share a great deal of common ground, they do have different goals. I feel that this shows the strengths and weaknesses of each license pretty well.

As a final note on the subject, note that a license DOES NOT APPLY to the developer. A developer can release code under multiple licenses, can change licenses, can do literally anything with his own code. It is not unheard of for an application to be released under the GPL, with a proprietary version released under a different license. Developers are not restricted by their own licenses.