Unix Basics

Main Page
Helpful Links
Downloads
Tutorials
Grades
Syllabus
Contact Me
This lesson should get you started using the Unix operating system, which we will be using for this class.  There are actually several flavors of Unix, such as Solaris, BSD, and Mac OSX.  Fortunately, from a user's point of view, they operate quite similarly.  Additionally, while not strictly Unix, Linux is also very similar.

   All programming work for class should be done on CSE's server, located at cse.unl.edu.  So let's look at how to log into it.

Logging Into the Lab Machines

   You should all have received a username and password for CSE.  When logging into one of the machines, these are what you will use to access your account.  This should work for Windows or Linux, whichever you prefer.

Logging In to CSE

   After this, you need to open a shell to CSE.  In Windows, you can use a tool called PuTTY.  This is already installed on the lab machines.  Simply start it, and enter cse.unl.edu into the Host Name box.  Then, tell it to connect.  After confirmation, you will be prompted for your username and password.
   In Linux, simply open a command shell and type in ssh -l yourusername cse.unl.edu.  Then you will be prompted for your password.
   The good news is, you can do this from anywhere.  Your home computer will work just fine for this.  If using Windows, you need to get PuTTY here.  If you use Linux, you almost certainly already have ssh.  As for Macs, I don't know.  My guess is OSX has an ssh client, but I don't know for sure.

Logging Out

   When you wish to log out, simply type exit and press enter.  Or, if using PuTTY, you could simply close the window.

Basic Navigation

   Upon loggin in, you will be in your own home folder on CSE.  This is where all your work will take place.  Pot of gold underneath the rainbow. In Unix, you need permission to do things like write to a file or folder.  So this is the only area you can be sure of having adequate permissions.
   Now, let's cover a few navigation commands:

pwd
   This command stands for "print working directory."  It simply tells you exactly where you are.  Try it out.  In my home folder, I get back /home/grad/avisvan.

mkdir foldername
   This command makes a directory with the name specified.  You should use directories to organize your files.

cd
   When cd (change directory) is entered with nothing else, it takes you back to your home folder.

cd foldername
   When cd is followed by a directory name, it takes you to that directory.

cd ..
   The two dots represent the directory above the current one.  So if I entered this while I was in /home/grad/avisvan, it would take me to /home/grad.

ls
   This command displays the contents of the current directory.

ls -l
   This displays the contents of the current directory, but as a list with additional information.

ls foldername
   Instead of the current directory, this displays the contents of a directory you specify.

Removing Files and Folders

   Here are some commands for removing files and folders.  Be very careful with these.  Unlike Windows, there is no recycle bin in Unix.  Once you delete it, it's gone for good.

rm filename
   This removes the specified file.

rmdir foldername
   This removes the specified directory , but only if it's empty.

rm -Rf foldername
   This removes the specified directory, and everything it contains.

Copying and Renaming Files

   These commands allow you to make copies of files and directories, and to rename (move) them.

cp originalfile copyfile
   This makes a copy of a file.

cp -R originalfolder copyfolder
   This copies a directory and all its contents.

mv oldname newname
   This moves a file or folder.  The name of the command is somewhat deceptive, since it really renames the file.

touch filename
   This simply creates an empty file.  I include this because it could be useful for practicing the above commands.

Getting Information

   These commands are useful because they can be used to get information from the system, such as how to properly use a command, or the name of a command.

man command
   This displays the manual page for a command.  Try entering man which.  Press q to exit when done.

which command
   This tells the location of a command.

less textfile
   This displays the contents of a text file.  Press q to exit when done.

apropos keyword
   This command searches the system's manual pages for entries with the keyword at the top.  This is very useful for when you've forgotten the name of a command, but remember what it does.

Editing Files

   Most Unix users use Emacs or Vim for their text editing.  These are both very powerful and can perform many, many functions.  However, they can be quite daunting for a beginner.  Instead, I'll show you how to use a much simpler editor.

pico

   pico is a very simple editor.  You simply type things in and they are entered. (Vim isn't like that.  It could take you awhile to figure out you need to press 'i' to enter anything.)

   One nice thing is that pico's commands are listed at the bottom of the screen.  Note that the ^ symbol means to hit the control key.

   So, to save a file, hold control and hit O.  If no filename was specified when starting pico, it will then ask for one.

   Hold control and hit X to exit.

   To open an existing file, simply type pico filename.