UNIX basics

strict warning: Declaration of views_handler_filter_node_status::operator_form() should be compatible with views_handler_filter::operator_form(&$form, &$form_state) in /home/chaosmin/secure_html/sites/all/modules/views/modules/node/views_handler_filter_node_status.inc on line 13.

Many people (from a certain generation) think of the command line as DOS, but in fact very first versions of DOS were copies of the UNIX command line.  This is a very basic introduction to the modern command line found on UNIX, Linux and MacOS X systems.  (It won't help with Windows systems, unless if they have added on some UNIX command line tools such as Cygwin.)

When you first sit down at the command line, pay attention to what characters are on the last line, where the blinking cursor is: this is the prompt.  Typically this ends with a character such as # or %.  It is also very common for the prompt to contain useful information about the name of the system, the user, the date, etc.  For instance, mine looks like the following:
rob-UX31A SFSU # 

...which tells me my username, machine name, and current working directory.  (More on that last one later.  Actually, more on that right now.)  "Directory" is a term for your current location in the system; if you're used to using a graphical user interface such as Macintosh or Windows, a directory is what you typically think of as a folder.  Since there is no graphic user interface available, everything must be revealed through typing commands at the prompt, followed by hitting the Return key.  When you first sit down at the terminal for an unfamiliar computer system, there are a few commands which are a good idea to type in first.


If the response to this looks familiar--say, your name--then all is good.  If it comes back with gobbledegook, or worse "root," then you want to back away from the machine and get some help from youir nearest sysadmin or helpdesk professional.  (The "root" user has complete control of the machine, and can very easily execute dangerous commands which could cause the machine to behave strangely or even stop working at all.  You have been warned.)  The next command to issue looks a little intimidating, but is useful to know if we're dealing with a sane environment:

echo $SHELL


The only answer we want to this querry is "bash," or possibly "/bin/bash."  Bash stands for the Borne-Again SHell (long story), and is the default shell on most modern systems.  The rest of this tutorial assumes we are running in bash.  Different shells--also known as command-line interpreters--have subtly different vocabularies and syntaxes, and may behave differently in important ways.  The last command we want to type at a new system is one we'll use quite often, is to find out where we are on the computer (remember that "directory" is the term corresponding to "folder" in a graphic user interface):


Which stands for "Print Working Directory"... aka the name of the folder we are in. Let's get used to calling that "directory," because that's what it really is.  Using that terminology will help understanding what other commands mean, as the two following examples will show.

ls  =  "List" directory contents.
    ls -F (shows list of folders)
    ls -al (shows all files, in long format)
    ls mar* (lists all files beginning with "mar")

cd = "Change Directory" and, if only cd, it takes you to your home dir.
    cd documents ( "documents" is the name of folder)
    mv = Move files.
    cd /FolderName/FolderName/ (takes you into a folder)

mv = moves = It deletes the old file and makes one were it is moved to
    mv FileName NewFileName
    mv FileName ../ (moves a file up a directory)
    mv FolderName/FileName /FolderName/FolderName/FolderName/
        Moves files from one folder to another

cp = Copy files
    cp NameOfFile NewNameOfFile
    cp FileName ../ (copies a file up one directory)
    cp FolderName/FileName /FolderName/FolderName/FolderName/
        Copies files from one folder to another

rm = remove directory entries (deletes file completely)... use with caution!  Very important files are typically "locked" from accidental deletion, but you should never assume that and delete things you don't understand or recognize.
    rm FileName

sudo = execute a command as another user, typically the "root" user.  Beginners won't need this, but it's important to know.
    sudo rm SomeImportantFile.txt

less  = lists the contents of a file file
    less myfile.txt

Next is possibly the single most useful command you will find on UNIX systems, namely how to invoke the instruction manual that comes with every UNIX system in the world (again, including Linux and MacOS X).  This is so supremely important that old-school geeks will sometimes answer questions with RTFM ("Read The Fine Manual"), which is basically asking the user to look up the answser for themselves.  Good practice.
man = manual
    man ComandName
    Q = exit man

Since you absolutely MUST learn this command, start by looking up the manual page for the manual itself!  Following the above guidelines, you will quit it by hitting the "Q" key on the keyboard and will first invoke it by typing the following:
    man man

Now that you've learned the basics, time for a little finesse.  First off, you need autocomplete.
Auto-complete: hitting the tab key lets the terminal fill out the word if there is no other like it.  Typically, this goes rather like the following:
    ls So[TAB]

Which produces the output:

Next is history.  You can type "history," but much more useful are the up and down keys.
Arrow keys move you through your terminal inputs: use the up key to revisit commands in your history.
This becomes indispensible once you realize you can edit previous commands.  Saves lots of typing.

A very powerful--and thus, sometimes quite dangerous--convention is the wildcard, deonted by the asterisk:
* = wild card
As in the following example, which would list all files beginning with a certain string:
    ls project_folder_*

If you have looked up the man pages for any of the previous commands (for instance, "man less"), you may have noticed mention of switches. A switch is a comand option, typically denoted by a hyphen.  We've already seen some examples of this, when I mentioned the ls command to list the contents of a directory.  This is where you really begin to unlock the power of the commmand line, with options that sometimes aren't even possible through the GUI (the "graphic user interface").  It is good to note that switches can be combined in various ways.  The following two examples, for instance, produce identical output, namely a listing of all files, in long format, with special files being flagged:

    ls -a -l -F
    ls -alF
Here are a smattering of other basic commands to help you get your feet wet with the command line:

nano = an inline text editor
    nano (creats a new text file)
    nano FileName (opens the file)
    ^X = exit nano
    ^O = write text to file

ssh = OpenSSH SSH client (remote login program).  Like sudo, not for beginners, but also important to recognize.

mkdir = make directories (directory = folder)

tar = manipulate tape archives, which means a group of files that have been compressed (sort of) into a single bundle
    tar cfv FolderNameToMake.tar FileNameToCompress
        (c=create f=file v=verbose )

touch NewNameOfFile = this creates an empty file without anything in it.  Sometimes useful when you want to timestamp a file with the moment you embark on a project, even though you won't get to type anything into that file until much later.

This concludes our (very basic!) introduction to the UNIX command line, which should give you just enough information to be really, really dangerous.  Practice with the supervision of a geek friend is highly recommended and remember, Google is your friend!