Question Nexus

Ask a question get an Answer

The Terminal

Posted by slayton on October 4, 2008

The Terminal.

To start out this post I’m going to pose a simple question. What can you do faster, type out ten words on your keyboard or click 10 different icons spread around your desktop.  Most people when intially posed this question respond that clicking is faster.  This may be the case if the icons are really close and you don’t know how to type, but as soon as you have very basic typing skills it becomes much easier to type commands then to perform a visual search, followed by moving and then clicking a mouse.

If you know what your doing you can almost always perform the task many times more quickly and efficiently in the terminal. In fact you will eventually learn that there are many things that can really only be accomplished in a terminal. The terminal like most things in linux isn’t designed to be easy to learn, but easy to use.  The learning curve is steep but once you’ve reached the top you’ll be doing thins faster and more efficiently then you ever could using the GUI.

What is a terminal?

A terminal is an application that lets you control or interact with your computer using a shell. Shells are basic programs that interact with the operating system of your computer. I don’t want to get much more deep then that; however, if you want to know more the wikipedia articles are great. There are several terminal programs: Konsole, Terminal, XTerm.  I will be using Terminal exclusively. Also there are several types of shells, each with a different set of commands. Like most modern linux distributions Ubuntu ships with Bash but there are several different shells that can be installed if you like.

So I’ve opened a terminal now what?

With a terminal open you should see something like: username@computername:~$. The ~ says that you’re in your home directory and the $ sign means that the shell is waiting for commands. If you’re familiar with DOS ~$ is like  C:Documents and Settings/User_Name/.  Think about you computer as a tree.  The root of the tree is / with directories as branches and files as leaves.  A branch can have sub branches but leaves cannot. A leaf is the end node and can have nothing attached to it.  Your terminal is like a monkey sitting on a branch. The monkey can climb up branches, climb down branches, or do something to the leaves.  You can like this monkey climb around your file-system like its a tree.

Basic Commands:

I am not going to provde a comprehensive list of commands but rather go over several commands that I use regularly:

  • ls list the contents of your current directory, like DIR but better
  • cd <dir> change directory to dir, dir must be a subfolder of where you are currently located
  • cd .. change directory, go up one directory, if you are located in  /home/user/Folder cd .. will put you in /home/user/, note the space between cd and ..
  • cp <src> <dest> Copy what is at src to dest, when copying folders include -r to recursively include the folder contents
  • mv <src> <dest> Move what is at src to des, when moving folders all contents will be move automatically
  • sudo <username> <command> Switch User DO, executes a command as another user, <username> can be ommited and the root user will be assumed
  • . a period is the shortcut for where you currently are.  If you are located in /home/user/dir1/dir2/dir3 typing  cp  -r /home/user/data/ .  will recursively copy all of /home/user/data to /home/dir1/dir2/dir3/data
  • ~ this is a shortcut for /home/<username>/ use can use it in almost any command like

For a great list of possible commands check out: http://www.ss64.com/bash/ It’s hardly comprehensive but it is a good start.

Doing more with Basic Commands:

You may have noticed the  -r I added to the cp command. Most commands can take options which are either a letter after a – or a word after –.  To see what different options are available for a command you can read the man page (manual) for that command by typing: man <command> or you can see the help prompt by typing: <command> -h or <command> –help. Most commands can take one or many command line options allowing for some really powerful commands.  These commands are what make the terminal such a powerful tool that take it way beyond anything you could do with a GUI.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: