Unix Basics

Most of the time you can happily use the desktop GUI world of icons & click-click-click to navigate your directory(folder) setup. However, for this course and in order to set up new packages you will find a survival set of understandings about the underlying textual command interface of Unix very helpful.

So, let's talk about the Unix command "echo" and how it can be used to discover the values of various "environment variables".

All Unix systems (and mac & windows) have "environment variables" You can query these if you know what they are called. For example, try this at your command line prompt

        echo $HOME
        echo $CLASSPATH

Both of these variables store one or more "pathways". A "path" gives ordered navigation directions thru folders to reach appropriate files or directories.

Here's some other Unix commands you'll find useful from time to time.

    ls 
    
list contents of current directory(folder)

ls can be used alone or in targeted way

                  ls  
                  ls ~                 ('~' is shorthand for $HOME)
                  ls ..                ('..' is parent of current working directory)
                  ls ../*.java         (* is a "wild card")
             
The "/" symbol separate folder levels in the path

ls can also be used in combo with environment variables

                  ls $HOME/cs157/hw/1/*.java 
             
    cd 
    
change current directory(folder)

cd can be used alone or in targeted way

                  cd  
                  cd ~
                  cd .. 
                  cd ../.. 
                  cd $HOME/cs157 
             
    pwd 
    
"print working directory"
    mkdir 
    

make a new directory(folder) from the command line
Unless you specify and alternate path, directory is underneath the working directory (aka "inside current folder")

                  mkdir JavaPkgs  

                  mkdir JavaPkgs/Shapes157

                  mkdir ../JavaPkgs/Sorting

                  mkdir $HOME/JavaPkgs/ArrayImplementations

                  mkdir ~/JavaArchives
             
    export 
    

export can be used to both create and "publish" a new environment variable

                  export MY_NEW_VAR=lalalalala

                  echo $MY_NEW_VAR
             

export can ALSO be used to modify a pre-existing environment variable

                  export CLASSPATH=$CLASSPATH:$HOME/JavaPkgs/

                  echo $CLASSPATH
             

To make the export value PERMANENT, you will have to edit a configuration file. This file is called ".bashrc" and is found in your $HOME directory. Edit it now to add the export line as the last line. Save and exit.

Changing the CLASSPATH export in your .bashrc, means that any terminals opened up afterwards will get the new CLASSPATH, automatically. After logging out and back in you won't have to worry about which terminals know about the new CLASSPATH and which don't. They'll all know.

    grep
    

grep is used to search files for strings (aka simple "regular expressions")

The first field is the regular expression.
The second is which file(s) you want to look into.

                  grep  onMouse  Client.java 

                  grep   //   Client.java 

                  grep  Window  *.java 

             
    mkdir
    

mkdir is used to create a new directory (aka "folder")

The first field is the regular expression.
The second is which file(s) you want to look into.

                  grep  onMouse  Client.java

                  grep   //   Client.java

                  grep  Window  *.java

             
    cp
    

cp is used to make copies of one or more files

The first field is what you want a copy of.
The second is the new name and/or place you want the copy to be named or go to.

                  cp  FirstClient.java  HW1_Client.java     (copies a single file)

                  cp  *.java   JavaArchives/                (copies all files ending in .java into subdirectory JavaArchives)

                  cp  -rf JavaPkgs/   SavaAllJavaPkgs/      (makes a copy of the entire directory & all subdirectories)

                  cp  ../FirstClient.java  .                (copies file found in parent directory(..) to current directory(.) )

             
    mv
    

mv is used to move a file or files from one place to another (or one name to another)

                  mv  FirstClient.java  HW1_Client.java     (renames a single file)

                  mv  *.java   JavaArchives/                (moves all files ending in .java into subdirectory JavaArchives)

                  mv  JavaPkgs/   SavaAllJavaPkgs/          (renames a directory)

                  mv  ../FirstClient.java  .                (moves file found in parent directory(..) to current directory(.) )

             
    rm
    

rm is used to remove/DELETE a file or files Remove/DELETE one or more files. BE CAREFUL!!!

                  rm  FirstClient.java                      (deletes a single file)

                  rm  *.class                               (deletes all files ending in .class in current directory)

                  rm  */*.class                             (deletes all files ending in .class from all subdirectories;
                                                             does NOT remove those in current directory)

                  rm  ../*.class                            (deletes all files ending in .class from parent directory)

                  rm  *                                     (deletes all files in directory.  BE CAREFUL!!!)