Quick Reference to Using the Unix Operating System

For the commands listed below, bold indicates a keyword or characters that should be typed verbatim, and italics indicates a name or information that you need to provide.  For example, the command "cp file1 file2" means that you should type "cp" followed by two filenames.  You will provide the actual names of the two files.


Connecting 

To log on to babbage

  1. Double-click on the "SSH Secure Shell Client" icon on the desktop.   If you do not have SSH Secure Shell, you can download a free version here:  http://people.uncw.edu/guinnc/courses/spring14/332/SSHSecureShellClient-3.2.9.exe
  2. Press "Enter" to bring up the "Connect to Remote Host" window
  3. Specify "babbage.cis.uncw.edu" as the host name and your student login as the user name (the port should be "22" and the authentication should be "password".)
  4. Click "Connect"
  5. Enter your password and press "Enter"

Files

cp file1 file2

make a copy of file1 and call it file2 (destroys the old file2 if it existed)

cp file subdir

copy file into subdirectory (with the same name)

mv file1 file2 

move (rename) file1 to file2 (destroys old file2 if it existed; file1 no longer exists)

mv file subdir

move file into subdirectory 

rm file

removes (deletes) file 

cat file

display file contents on screen

more file

    or

less file

display file contents on screen one page at a time (use space bar to go forward one page, 'b' to go backward one page, and 'q' to quit)

vi file

evoke the vi editor on file (create the file if it doesn't exist)

javac file.java

compile a JAVA source file 

java classname

execute a JAVA class (must contain a main method)


Directories

ls

    or

ls subdir

list the files in the current directory or another directory

ls -l

    or

ll

list the files and details (file size, owner, group, permissions, etc.) in the current directory or another directory

mkdir subdir

create a new subdirectory 

rmdir subdir

remove the subdirectory (it must first be empty) 

cd subdir

change current directory

cd

change back to your home directory 

cd ..  

go up one level in directory hierarchy 

pwd

print working directory (full path name) on the screen


Other Users

mail or alpine

read or send mail  

w

show who is currently logged on

finger username

show information about person who owns the login name


Starting and Stopping

Ctrl-d

    or

logout

    or

exit

logout of shannon

Ctrl-c

interrupt the current program or process


Miscellaneous

man command

manual page for command (q-quit, Enter-next line, spacebar-next page)

passwd

change password (You will be asked to enter your old password, then your new one, then your new one again to confirm that you typed it correctly.  If it does not say it was successful, then your password remains the same.)

script

create typescript file of everything done until Ctrl-d. Do not use vi.


I/O Redirections

command > file

execute the command and write the output into the file (overwrites the file if it exists)

command >> file 

execute the command and write the output to the end (append) of  the file (does not overwrite the file if it exists)

Examples:
 

cat file1 file2 file3 > file4

create file4 containing the concatenation of file1, file2, and file3 (the number of files specified can be unlimited)

javac javafile.java

compile a java file to create the class file

java classname > file

execute JAVA program and write output (from System.out.println(...) statements) to file 

java classname < file

execute program using the file as input for System.in

java classname &> file

execute JAVA program and write output (from BOTH System.out and System.err ) to the file 

java classname < file1 > file2

execute program with input file1 as System.in and output file2 as System.out 

mail -s "subject" username < file

email the file to the user with the subject line give in quotes. BE VERY CAREFUL TO USE THE SYMBOL '<' (and not '>').  Otherwise, you will overwrite your file