browser icon
You are using an insecure version of your web browser. Please update your browser!
Using an outdated browser makes your computer unsafe. For a safer, faster, more enjoyable user experience, please update your browser today or try a newer browser.

Unix / Linux: The Basics

Posted by on May 19, 2010

1.  A Brief History
2.  Logging On
3.  Changing Your Password
4.  Logging Out/Off
5.  File Management & Intro to vi

A Brief History of Unix –

The Unix operating system was developed at the AT&T Bell Laboratories in 1969. It has gained widespread acceptance as both a commercial operating system, and now with the gains by Linux, in the private sector as well. While there are many versions of Unix and Linux, changed to fit specific needs, the basics of the operating system are the same and in this introduction you will learn the power and
stability that Unix can offer. While many persons of the Microsoft Windows and Macintosh age find Unix type systems to be unfriendly and unforgiving, with a little practice Unix systems can surpass many of the abilities and functions of other operating systems. Perhaps it’s single largest draw to people is that Linux and Unix Operating Systems are free, or "Open Source". Generally the costs involved in purchasing a copy of Unix or Linux is in the packaging and support that is offered, not the OS itself. You can download them from any number of websites for your own use. In addition, you can, if you have the programming skills, customize it to make it work exactly the way you want it to. With that, let’s take a look at Unix and how it works. For the purposes of this section, I am using Unix based Sun OS and BSD, but as I said, you can use these same commands, essentially, on any Unix or Linux system and feel quite comfortable.

Logging On –

All Unix and Linux systems require you to log on. You will need to have a user name and password that lets the OS know who you are, and what areas you have access to. If you do not have a user name and password then you will need to contact your system administrator. When you first sit in front of a Unix terminal, you should see a log in screen that displays information similar to the following: In this case I will log in

login: John

Welcome to Unix!


Changing your password

Your password will never be displayed so be careful to type it in exactly as it was given to you. You should note that the $ is the command prompt line. If you do not get a login when you get to your machine, try pressing the ENTER key several times. This is probably a good time to change your password. Passwords have to be at least six characters in length, and should combine both letters and numbers. Try not to use easily to identify items like your name or your social security number! Now let’s change your password. In this case we will use the “passwd” utility. At the prompt, just type in passwd. You should then receive prompts for your old password, and then your new password, which you will need to type twice in order to confirm it. It should look something like this.

$ passwd
Changin password for John
Old password:
New password:
Re-enter new password:

Voila, you have just changed your password so that no one can get it. Make sure that you remember your password. If you ever forget it it will have to be changed by the system administrator.

Logging Out

Depending on which version of Unix you are using, the commands for logging out may vary. One of the following should do the trick though. Pressing both the Control key and the D key, typing exit, or typing logout are all ways to log off the machine you are on and send the machine back to the login screen.

File Management

Unix can be rather strange for those used to a Windows or Mac environment. Perhaps the single biggest complaint is the lack of feedback from the OS, whether it be in the execution of commands, or in displaying files and directories. So in order to dispel these complaints, we will delve into the basics of Field Management and begin to do some interactive learning, with Unix telling us what we need to
know. Ready?

The first thing you need to do is log onto your system and just take a look. Generally all you will see on your screen is some brief text and a prompt, $ , signifying that Unix is waiting for us to do something. So, let’s do it.By default, your log on takes you to your root directory. Let’s take a look at the contents of that directory. At the prompt type ls.


Once you have done this you may, or may not, be returned with a list of directories and files contained within your root directory. Don’t worry too much about what is what right now, just try to get used to the idea of using the OS. As you stare at the text on your screen there is something that you won’t see. All of the hidden files and directories. So how do we look at these? Simple, we use what is called an argument. Not the kind involving two people fighting, no, this is just an extension or an option that allows you to further define exactly how you want a utility to operate. In this case we will look at the
-a option. Here the -a means all. We want to see all of the files and directories in our root directory. Why don’t you try it? Below you can see the difference between using just ls and using ls -a.

By using the ls utility I was able to see that I had three directories – bin, mail, and test. Using the -a argument showed me every single item! Most of these I will never need to touch, so they stay hidden, but it is a good idea to know where they are in case I do have to do something. OK, enough of looking at the contents of a directory. Lets do some real damage! Let’s create a directory in our root directory and name it test. Now in many OS’s we would have to first create the directory ( folder if that is easier to understand ) and then name it. In Unix we will do it in a couple simple punches on our keyboard. Lets look at the steps.

$ mkdir test

Ok….that was pretty hard. What we have just done is told Unix to make a directory ( mkdir ) and call it test. I am sure that all this exertion has just got you spent. Now we can use the ls utility to verify that we did indeed make that directory. Unix gave us no response…and in Unix, no news is good news. If there had been a problem Unix would have given us some error message. But because everything was done correctly, we received no errors, and Unix did just what we asked it to. Now that we have a directory, we need to move our operations into it. Here again we will cover some very difficult concepts so please pay attention!

$ cd test

Whew….all this Unix typing with no graphics is ready to kill me. What we just did was tell Unix to use the cd utility to change directories (cd..get it) from our current one to the directory named test. Now try using the ls utility. Nothing there…wait…use the argument -a and you will see something like this.

$ ls -a

Dots? What are those dots? To put it simply, they are just representations of directories that will exist in every directory you ever make….so don’t get to concerned. We will go into depth on that in a later lesson. Right now we know that we have a clean and empty directory in which we can start doing some really neat stuff. Here we will sidestep for a moment to use a utility called vi. vi is a text editor that is built into Unix. It is by no means a high end word processor, but it is a very handy little tool with a great deal of options and power behind it. We will cover it in depth later, but for right now, just follow the examples. At our command prompt, type the following:

$ vi first

What you have just done is told Unix to use the vi editor and call the file first. Your screen should look something like this:

Don’t be too alarmed. It will make sense here very quickly. You are looking at the vi editor. The squiggly lines (~) called tilde are just indicators that there is a blank line there. As soon as we begin entering text they will disappear. Whenever you first enter vi you are in one of three modes that vi has. This first one is called command mode. But, we don’t have anything to command right now, so we need to get into the insert mode. There are several ways of doing this, but my personal favorite is to just hit the Insert Key on the keyboard twice. That should put you into Insert or Edit Mode. Then start typing. You can type whatever you want and Unix will just start plugging away at it. Again, we are not going to get too in depth on vi right now, so just write the following sentence:

This is the first day of the rest of my life as a Unix Master!

Once you have typed in this line ( don’t worry about typo’s ) you will need to press the escape key twice. This will put you back into command mode. Now we want to save our work. In this case we will need to enter a colon (:)and then the letter w. Hit the enter key. This should give you some results like the following.

At the bottom of the vi editor you will see that the new file first contains 1 line and 63 characters. Now type in the colon again, this time followed by the letter q. This will quit from vi and put you back into the Unix Shell. Make another file in vi called second and type in the following text:

I am getting even better at this than I thought!

Don’t forget to write the contents ( :w ) and then quit ( :q). Now ls the directory again and see that your files are there. You should see your two files in the directory. If you don’t, then back up and try again. Now lets do some really neat stuff…let’s join these files together!

To join together two files we can use the cat function. In this case we want to join the cat function to put our file second at the end of the file first in order to have both files in one! Confused? Don’t be, just follow the directions below and it should all make sense quickly.

Make sure that you are in your directory called test.

$ cat second >> first

Hard wasn’t it? If we had only used one chevron > ( called a re-direct ) instead of 2 we would have replaced the original contents of our first file and been left with the contents of second in both files. Let’s say that we wanted to check to make sure that we did this right. Try this.

$ cat first

You should receive an output to your screen showing the contents of the file with both lines of text it it. Now let’s say that we wanted to put these two files together, but call them something else. For this we would do the following.

$ cat first second > third

If you check, you now have a new file called third that has the contents of both first and second. Pretty easy stuff.

Now that we have made a mess of our test directory lets do some more file management to clean things up. First lets delete, or remove, all the files we created. While we could do this one file at a time, Unix lets us do it all at once.

$ rm first second third

That effectively deleted all the files. Next we need to type in cd to return to the root directory. Once there type to following.

$ rmdir test

You have just deleted the directory called test. Just as we used mkdir to make our directory, we use rmdir to remove our directory. OK, that should just about do it for now. Come back next week for another installment of Unix and remember to practice, practice, practice.!

OK, you have done enough for this lesson. Try practicing with vi and your file management so that you can easily create, delete, and modify files and directories. We will cover more in the next section.

Share on Facebook

Leave a Reply