User:Trappist/HowToLearnUnix

This article is designed, not to teach you Unix administration, but to teach you how to teach yourself. It includes the basic skills you need to get started, some tasks to perform to develop new skills, and links to other resources to answer your questions.

Choosing an Operating System
The first thing you need is a machine running the operating system you want to learn. Linux is a good OS to start with, and if you don't already have a favorite distribution, allow me to recommend ubuntu. You should get the latest released version of the distribution. Whether to get the desktop or server version depends on several factors. You will learn more quickly by switching to this OS as your primary operating system, perhaps by dual-booting with Windows, because it will force you to learn things to use your own computer. If you don't have the time to learn this way, and you have a separate machine available to set up as a server, download the server version. If you install the desktop edition, though, be sure to force yourself to use console tools, not the available GUI administration tools, to perform administrative tasks, as you will seldom have GUI tools available when administering an actual UNIX server.

Also, if you're not running commodity hardware, be sure to download the file appropriate for your hardware. If you have standard PC or server hardware, the following download links should be appropriate. If you're not sure, you probably have standard hardware.

Download Ubuntu Gutsy Server Edition Download Ubuntu Gutsy Desktop Edition

Getting Up and Running
Once you've downloaded your OS, burn it onto CD. You don't want to write the ISO file to CD as you would other files. An ISO file is a CD image, and your CD burning software should have an option to write a CD image to the CD. The result will be a bootable installer. Once the CD is ready, reboot the computer with the disc in the drive. You may need to change a BIOS setting to allow the machine to boot to CD.

Once this is properly done, you'll see the first screen of the installer. Check here for a guided tour of the installation process. When the installation is complete, you'll be prompted to reboot. When you do, you'll be running Linux.

Note that the installation process for the server edition is considerably different, and lacks a graphical installer.

First Steps
Most of the rest of this document assumes you're running Ubuntu Desktop Edition. If you've chosen another Linux distribution, or another UNIX operating system, the ideas are the same, but the details will differ.

If you've got a graphical desktop, you may want to first spend some time poking around to get a feel for how things work, discover features, etc. Once you're ready to get started, read on.

By now you've hopefully discovered a terminal emulator, like gnome-terminal, xterm, or similar program. If not, hit alt-f2 and type "gnome-terminal" (without the quotes). This is one of many ways to launch an application.

First, let's explore your filesystem using some basic commands. You'll start out in your home directory, so let's move somewhere else - /etc, the directory containing most of your system-wide settings. Try cd /etc The cd command means Change Directory. Now you'll be in the /etc directory. Let's see what's in here. ls With no arguments, this lists the contents of the current directory. It will show any files and directories in /etc (in this case) that are not hidden. In UNIX, hidden files have filenames starting with a dot. Here you should see directories like init.d, fonts, <tt>apt</tt>, etc., and files like <tt>hosts</tt>, <tt>fstab</tt>, <tt>resolv.conf</tt> etc. Almost everything in this particular directory should be either another directory or a plain text file.

Administring a UNIX system involves editing a lot of text files. You'll want to be familiar with a good console text editor. In the case of Ubuntu, the default console text editor is called nano. It's fairly simple and easy to use, and tempting to get comfortable with. But you're going to be doing a lot of console text editing, which means you need a more powerful editor, which means you've got some learning to do. And, since files in this directory are for system-wide (i.e., not just for your user) configuration, not just anyone can edit them. You have to have root privileges. The preferred way to do this is by using sudo. Check that link for more details.

Let's have a look at the <tt>/etc/hosts</tt> file. First, do cat /etc/hosts That will dump the contents of that file to your terminal. The first line will look something like this: 127.0.0.1 localhost.localdomain localhost This is the first file your computer looks at to resolve domain names, before doing a DNS lookup (unless configured otherwise). If you want to edit it (no reason to do that right now, but let's have a look) you'd say vi /etc/hosts Now you're in an editor. You can make changes, but you won't be able to save them, because you're not root. Just do :q! to quit. For more on vi/vim, check out the documentation at vim.org or use google. A lot of the howtos seem to be offline at the moment for review, but there are zillions of them. I highly recommend learning vim. Start with the basics, and once you're comfortable, return to the docs to learn some more tricks. this is a decent place to start. That documentation is also availabe from within vim, by typing <tt>:help</tt> in command mode (the default mode, when not in edit mode). Note: <tt>vi</tt> is generally a symbolic link to <tt>vim</tt>, which is VI iMproved. Ubuntu ships with a less featureful version of it, but you can install the full version by doing <tt>sudo apt-get install vim</tt>.

here is one of many command line "cheat sheets" available as a quick guide to some of the basic commands. To use these commands effectively, one other thing you need to understand is the filesystem hierarchy.

Filesystem Hierarchy
Linux distributions and UNIX operating systems will differ some in their implementations of the Filesystem Hierarchy Standard, but one of the purposes of standards is consistency, and so you will find that most implementations are consistent and compliant with the standard. See the standard itself for a more technical and complete description, and below for a first look.


 * <tt>/bin</tt> : Contains basic commands needed for navigation and for the system's initialization scripts.
 * <tt>/boot</tt> : Generally contains everything needed to boot, including the kernel and its configuration files and any files needed at runtime by your bootloader.
 * Note: "Boot" does not mean get your system into a useful state. It simply means fully execute the kernel and any modules needed to complete that mission.
 * <tt>/dev</tt> : Device files. In UNIX, it's often said, "everything is a file."  In <tt>/dev</tt> you will find file representations of physical and virtual devices.  Different devices have different representations, and can be interacted with in different ways.  For example, you can <tt>cat</tt> a raw wav file into <tt>/dev/dsp</tt> (Digital Sound Processor, your sound card) to hear it.  You can use the <tt>dd</tt> command line tool to interact with <tt>/dev/random</tt> to produce a stream of random data.
 * <tt>/etc</tt> : Contains your systemwide configuration files. As an administrator you will be spending a lot of time in this directory.  Many of these files and directories will be application-specific (you may have <tt>/etc/postfix</tt> or <tt>/etc/sendmail</tt>, but seldom both), but some applications are common across all UNIX flavors (that I've ever seen) and so some files will be on every UNIX system (with the same disclaimer), such as:
 * <tt>/etc/hosts</tt> : Described above.
 * <tt>/etc/resolv.conf</tt> : Contains information on how to resolve hostnames, such as IP addresses of nameservers. Like many system config files, more information can be found on <tt>/etc/resolv.conf</tt> on most systems by saying <tt>man resolv.conf</tt>
 * <tt>/etc/crontab</tt> : Tables for driving cron, an execution scheduler. There are multiple man pages for crontab.  Try <tt>man 5 crontab</tt> for information on the file, and <tt>man 8 crontab</tt> for information on the program.  Also see the section below on man for more information.
 * <tt>/etc/fstab</tt> : Information necessary for mounting your filesystems, including network and other virtual filesystems. Try <tt>man fstab</tt> for more information.
 * <tt>/etc/hostname</tt> : The file typically containing the system's hostname. The hostname is set at boot time by reading this file, so one way to change your hostname is to edit this file and reboot.  Systems are not required to have this particular file, so it has no man page (on most systems).
 * <tt>/etc/passwd</tt> : Despite its name, this file doesn't usually contain any password information. Instead it has a line for each user, including username, userid, groupid, full name, home directory and login shell.  Most systems come with a tool to allow you to safely edit the file (by doing lint checking when you save) called <tt>vipw</tt>, which will launch the <tt>EDITOR</tt> environment variable (usually <tt>vim</tt> or <tt>nano</tt>) to edit the file with failsafes.
 * <tt>/etc/shadow</tt> : Contains user password information, stored cryptographically using a one-way hash. It's worth noting the way this works.  The password, when set, is encrypted using a mathematical algorithm that, in theory, cannot be reversed, so the password cannot be decrypted.  When you login, the same math is applied to the supplied password.  The result is compared with the value in <tt>/etc/shadow</tt>, and if the encrypted strings match, you are allowed to log in.
 * <tt>/etc/sudoers</tt> : Not every system has <tt>sudo</tt> installed, so not every system will have this file. If your system doesn't have sudo installed, you'll want to install it right away and add yourself as a sudoer.  Say <tt>man sudoers</tt> for more info, and use <tt>visudo</tt> (similar to <tt>vipw</tt>) to edit the file.
 * <tt>/home</tt> : User home directories. For most systems, this should be on its own partition.  This will allow you, the administrator, to migrate to another Linux distro or even operating system, for example, without losing or having to migrate their data and user-specific configurations.  Simply install the new OS without formatting this partition.  Another benefit is that a user who uses too much space (if you haven't set up filesystem quotas) won't be able to fill up the system's available space, which can be an administrative headache.
 * <tt>/lib</tt> : Contains shared libraries needed to start your system. Shared library filenames typically end in .so, sometimes followed by dots and numbers indicating version information.  They are analogous to .dll files in Windows - they contain functionality shared by multiple executable files, such as reading from and writing to files, etc.  This particular directory contains shared libraries required by executables in <tt>/bin</tt> and <tt>/sbin</tt>.
 * <tt>/media</tt> : Mount point for removable media. This is where your CDROM drive, USB sticks, floppies, etc. will generally be mounted.  Implementation varies by distribution/OS, but a mounted CDROM drive may be accessed through (for example) <tt>/media/cdrom</tt>.
 * <tt>/mnt</tt> : Temporary mount point for arbitrary filesystems. You may temporarily mount, for example, a remote SMB filesystem, a loopback device (like a mounted ISO file), or an actual partition on the machine here.  See <tt>man mount</tt>.
 * <tt>/opt</tt> : 3rd party software. What's generally installed here is binary-only software not compiled for a specific distribution.  For example, if you download and install Google Earth, it will be installed here by default.  It is statically compiled, meaning it shouldn't require any libraries specific to your system, which means it should be portable across distributions.  That distinguishes it from most other applications on your system.  If you use a lot of these applications, it may be a good idea to also make <tt>/opt</tt> a separate partition, since it should be portable across distributions and distribution versions, like <tt>/home</tt>.
 * <tt>/root</tt> : Root's home directory. Nothing to see here.
 * <tt>/sbin</tt> : System binaries. Like <tt>/bin</tt> except that these binaries are generally only usable by the superuser, or root.
 * <tt>/tmp</tt> : Temporary files. On most modern UNIX operating systems, this is a special filesystem, like tmpfs, occupying a specific amount of space.  It should have the "sticky" filesystem attribute set, meaning any user can create files here, but users cannot edit each other's files.
 * <tt>/usr</tt> : Almost a filesystem unto itself, <tt>/usr</tt> contains shareable, read-only files. Shareable in this context means that the files are not host-specific.  You sould be able to share these files with another host, which would mount <tt>/usr</tt> remotely and be able to use its contents.