2011-08-29

Linux: A Beginner's Guide, First Steps pt.1

Before we begin:


This is what you will need in order to follow through with these tutorials:


  • Linux: It doesn't matter which flavor, but it must be installed on your hard drive (HDD).  Most major distros guide you through the basic install process (or do it for you) and have awesome documentation to help get you started. 
  • Patience: You are learning an entirely new way of doing things.  Some of the things that I am about to teach you are so far removed from the way that you are used to doing them in Windows that it's hard to put them into words, suffice it to say that it's like learning another language.  That said, some things that I am going to teach you make the way that you used to do them look like overly complicated garbage!  
  • Time:  Under no circumstances should you undertake any of these tutorials unless you have the time to sit down, take a deep breath, and actually read with understanding.  Anybody can read, but reading for understanding is much more difficult.  It requires concentration.  If you are like me and have a spouse and children, then this is easier said than done.  Do your best!
  • English: It sounds odd, but I will not be translating these tutorials into languages other than English.  I speak fluent Castillian (Spanish), but translating is not a task that I am willing to undertake alone.  You will need at least a basic command of the English language if you are going to understand these tutorials.  Google Translate is a very good tool to use, but it is not always perfect.  If English is difficult for you, please have a friend who does have a good command of the language help you out.
  • A willingness to get your hands dirty:  This is pretty self-explanatory, but, you must understand that we are going to be going deep into your system at times.  If you are unwilling dig in on your own, then these tutorials will not help you.  With this, please understand that I am expecting you to type everything you see manually.  Copy/Paste is a great way to "gimp" your learning potential.  I found this out when learning the Python programming language.  Zed A. Shaw wrote a book about it and said the same thing, you must type in order to learn how to do this and commit it to memory!  Don't cheat yourself or your system out of best practices.


Baby steps:

I am a firm believer in the "sink or swim" approach.  It works very well in the United States Military as well as other professions.  I don't believe in handing out crutches.  Crutches are there to help you through rough spots until you can stand on your own.  I say "How can you stand if you never learned how?".  What this means is that, I will be teaching you how to stand on your own two feet, and then to walk, and ultimately run.  That said, I also believe in making life easier in every way possible.  I'll be including (eventually) scripts and other neat little tricks that will help you to be more efficient and actually enjoy managing your system.


Let's get down to business:

The first thing that every new Linux user needs to learn, is to not fear the command line interface (CLI).  The CLI is a powerful tool at your disposal.  If you consider that "The eyes are the windows to the soul." so to is the terminal the window to the system.  Think of it as a gateway into another world that few rarely see.  

Now that you are all hyped up to use the terminal, let's open one!  I will not try to guess which Linux distro or Desktop Environment (DE) or Window Manager (WM) that you are using, but almost all of them allow for this:

Alt+F2

Press that key combination, a "run" dialog box should have opened.  In it, type the word "xterm" without quotes and then hit "Enter" on your keyboard (Carriage Return).  If you think that xterm is ugly, it is.  Another route that you can take to opening a terminal depends on your DE/WM.  Click on your "kick-off" menu (the equivalent of Windows's 'Start' menu) and look under "Accessories", "System Tools", or "System".  You should see something that says "Terminal", "Konsole", "Console", or something similar.


Once you have a terminal opened, I want you to sit back and take a breath.  It can look pretty scary at first.  Now, your prompt may look a tad bit different than mine, but that's okay, our terminals do all of the same stuff.  

Basic CLI Navigation:

Now that you have a terminal opened and have taken that deep breath, it's time to learn some of the good stuff.  Right now you are using your terminal as a "user", that is, you are not root.  The way you can tell if you are root or not in almost every terminal is by knowing which symbol belongs to user, and which to root.  "$" is typically used to let you know that the user in the terminal is just that, a user.  No special privileges, no administrative permissions, nothing.  "#", AKA "Crunch", "Hash tag", "Pound Sign", "Number Sign" denotes "root".  If you are seeing this in your terminal, BE CAREFUL!  Root can destroy the system.  It is important to note that even veteran Linux users only use root permissions when absolutely necessary.  It helps to avoid heartache later and is just good practice.  This is one of the reasons that Linux is so secure, we only use that which has the power to destroy only when that power is warranted.  Now, on to your first command!

In your terminal, please type:

pwd

Press the "Enter" key.  You should now see something akin to:

(darthlukan@SithCouncil) pwd
/home/darthlukan
(darthlukan@SithCouncil) 

What that command does is "Print Working Directory".  It shows you in what folder you are currently "in" at the moment.  In Windows you clicked on Start>[username] and were taken to your personal folder that had "My Documents", "My Music", etc.  It was a pretty window with a bunch of folders in "Icon View".  The only difference between the terminal and Windows Explorer is that one is GUI and the other is not.  You can do all of the same stuff (and then some) in a terminal.  

The Linux file hierarchy: 

Before we move on to other fun commands, it's important to know what the Linux file hierarchy is.  The first thing to understand is that in Linux, everything is a file.  All files are organized into folders (and even these folders are files).  In Windows, you have "C:\", in Linux we have "/".  Everything follows "/".  Here's a basic rundown:

/ = Root directory (everything is in this folder)
../bin = Binaries/Programs
../boot = Files needed to boot up
../dev = Devices
../etc = Configuration files
../home = User home directories/personal folders
../lib 
../lib64 
../media = Mounted media devices
../mnt = Mounted devices
../opt = 
../proc = 
../root = root's directory (he/she doesn't keep their personal stuff in /home) 
../run 
../sbin = System Binaries/Programs
../sys 
../tmp = Temporary files and folders (overwritten/deleted at boot)
../usr = Userspace programs, configs, and other shared files.
../var 

I didn't describe all of the folders because they are outside of the scope of this tutorial. We'll touch on them another time.  Suffice it to say that those other folders are used for magical things that you will eventually learn how to do soon :)

Another thing that is important to know is:

~/ = the current user's home directory.

Anytime you see that symbol, it means "/home/username".  In fact let's try something really quick.  In your terminal, type the following:

cd /

Then press enter.  Now type:

pwd

Press enter again.  Now type:

ls <== (lowercase "L")

Press enter.

You should see something like this:

(darthlukan@SithCouncil) ls
./  
../  
bin/  
boot/  
.config/  
dev/  
etc/  
home/  
install-data/  
lib@  
lib32/  
lib64/  
media/  
mnt/  
opt/  
proc/  
root/  
run/  
sabayon/  
sbin/  
sys/  
tmp/  
usr/  
var/
(darthlukan@SithCouncil)

Now, go ahead and type:

cd ~/     then press enter, the type:

pwd      and press enter again.

(darthlukan@SithCouncil) cd ~/
(darthlukan@SithCouncil) pwd
/home/darthlukan
(darthlukan@SithCouncil) 

You have just learned about five new things.  I'll outline them below:

pwd: Prints the working directory.
cd: "Change Directory" moves you in and out of folders.
ls: I call it "looksie", let's you "look" inside directories.
~/: Means "/home".  Ever see those geek shirts that say: 

"There's no place like ~/" or "There's no place like 127.0.0.1" ?  It's true, there is no place like /home. :)

And finally:

/: Means root, everything comes after the root directory, it is all inside the root directory, it's where things begin.

Let's try that "cd" command again.

cd /usr/share    then press enter.

Now, let's have a "looksie" :)

ls     then press enter.

Lot's of stuff in there huh?  We'll touch on all of the things in this folder at a later time, for now it's not important.

Now type:

cd     and press enter.

pwd        press enter.

Holy smokes!  How on earth did you end up there?  You didn't even tell Linux to take you back home!  Actually, you did.  See, the cd command without an argument defaults to taking you back to your home directory.  If you ever want to get back home, just cd there :)

Let's make something with all of this happiness:

Now that you have a decent command of basic movement and view commands in the terminal, let's do something useful.  We're going to give your home directory some stuff to work with.  First thing is first, I want you to "ls" in your home directory and take note of any directories that are already there.  If the folders that I show you how to create are already there, don't type them in to the command that I'm about to give you.

mkdir Documents    (press enter)
mkdir Pictures         (press enter)
mkdir Documents/notes Documents/work Pictures/screenshots Pictures/personal Pictures/edit Music Music/edit Downloads Videos Videos/capture Personal Backups Share        (press enter)

See what I did there?  Sure, you can make directories (mkdir) one at a time, or you can make them all at once with one command.  Another way to have done the same thing is to:

mkdir Documenta/notes && mkdir Documents/work 

But really, we want to make life easier on ourselves here.  Now, go ahead and browse through those directories using "cd", "ls", and "pwd".  I'm assuming that you installed a modern Linux distribution with a modern GUI (DE/WM), go ahead and open your File Manager using your GUI and arrange it so that it is right next to your terminal.  I want you to practice navigating your way around inside of your home directory using the folders that we've just created.  Use your GUI File Manager to create folders and move around inside of them.  Then, use your terminal to create more folders, just as I showed you above, and get comfortable with the two interfaces.

It's important to note here: I don't like GUI tools and interfaces at all.  I put up with them, I accept them because there are billions of people on this planet who are not like me (thank goodness!).  I would rather spend my life in a terminal than to have to click on one single object.  That said, in order to be a good user who is well rounded and knowledgeable in their OS, you have to know both the terminal and the GUI.  Find which you prefer.  At first, the GUI will be most comfortable and familiar to you.  That is okay!  Get comfortable with it.  My hope is that even if you come to despise your terminal, you won't fear it and will even be comfortable with it.  Let's be honest with each other, programs crash.  I remember when the DE/WM's out there today would crash all of the time and take you back to a TTY console (that thing with all of the startup information that you booted into), thankfully, I was no stranger to the terminal back then, so it wasn't a big deal other than to have to fix some bug or breakage.  Nowadays, most of the modern DE/WM's out there are pretty solid, but it's always good to be prepared.  Get comfortable with both interfaces now and you won't think twice about them later.

I'm going to leave you to your first steps in basic navigation using the terminal for now.  In the next section we'll talk about renaming, copying, moving, and deleting folders as well as files.  Until then, here are your assignments:

Continue to practice your basic terminal navigation until you are comfortable, then practice some more.  For each command that you have learned, read the --help output (example: ls --help) and see if you understand what it says.  If you don't understand, use Google Search to see if you can find an explanation of all of those options.  Read some wiki articles on how to do some basic installation of software and how to keep your system up to date.  Make sure that these wiki articles are specific to your flavor of Linux so as to avoid any conflicting commands/programs and configuration issues.  Get comfortable with the basic uses of your new OS.

Until next time! 


No comments: