How to ... in your Unix account

I will add addtional topics to this listing in response to questions you may have.


How to...

  1. Connect to Linux using ssh.
  2. Directories/files:
  3. Print a file.
  4. Email a file from your unix account.
  5. Compiling.
  6. Unix online manual.
  7. Vim editor
  8. Emacs
    1. Start and Exit emacs
    2. Abort any emacs command
    3. Create a new file or find an existing one.
    4. Compile a program in emacs
    5. Find compiler syntax errors in emacs
    6. Cursor movement
    7. Cut and paste
    8. Managing emacs Windows
    9. Unix directories in emacs

Connect to your CTI Linux account using secure shell.

First, you must activate your ctilabs account(s) at:


  https://accountactivate.cti.depaul.edu/

Help/instructions for activating your account available. Here is a
link to the help document.

Activating your account will take at least 10-15 minutes during regular hours if you are already registered for a cti class. Otherwise, there may be a delay of up to one day after you have registered. You will need your campus connection password and id, but you must register at the beginning of every quarter to be able to access cti lab accounts.

Next, make sure you have a connection to the internet; e.g., dial in to your ISP if necessary.

Run the secure shell application. See the link below for PuTTY, a nice ssh application. There are other secure shell applications. In what follows, I'll just refer to it as 'ssh'.

You will need to know the CTI server address for you Linux account. There are 7 addresses, any of which will connect you to your account:

ctilinux1.cstcis.cti.depaul.edu
ctilinux2.cstcis.cti.depaul.edu
...
ctilinux7.cstcis.cti.depaul.edu

You will get a command window and after ssh connects to the appropriate Linux server, with the prompt:


login as: your_login

your_login@ctilinux1.cstcis.cti.depaul.edu's password:

Enter your CTI (campus connection) login name and password.

To log out type "ctrl-d".

(Currently you must use a secure shell, so telnet will not work. There are free sources as well as trial versions of secure shell. In particular: PuTTY is free, small, and convenient to use:)


PuTTY - a Free Windows Telnet/SSH Client

If this doesn't fit your needs see also www.ssh.com (commercial and free) or www.openssh.com (free with links for unix, mac and windows). Note that the lab computers have a secure shell client that you can use.


Directories/Files

List directories [back]

Command: ls

Arguments: Optional list of files and or directory names

Options: -l -F

Description: Lists the specified files and or directories. For a directory, all its files and directories are listed. If no file or directory is specified, the current directory is assumed.

Example(s):

hawk:glancast> ls
prog1            prog1_ver0.cpp   prog2            sample.cpp
tmp 
hawk:glancast> 

hawk:glancast> ls -lF
total 28
drwxr-xr-x   2 glancast cscfclt      512 May 16 11:38 prog1/
-rw-r--r--   1 glancast cscfclt     8177 Jun 20 15:39 prog1_ver0.cpp
drwx------   2 glancast cscfclt      512 Jul 20  2000 prog2/
-rw-r--r--   1 glancast cscfclt     2224 Jun 20 15:39 sample.cpp
drwx------   2 glancast cscfclt      512 Sep  6  2000 tmp/
hawk:glancast> 

Display current directory name [back]

Command: pwd

Arguments: none

Options: none

Description: Print Working Directory; i.e., display the name of the current directory.

Example(s):

hawk:glancast> pwd
/condor/cscfclt/glancast/343class
hawk:glancast> 

Delete Files/Directories [back]

Command: rm

Arguments: file list

Options: -i -f -r

Description: Removes (deletes) the specified files

-i   Ask before removing each file
-f   Remove files even if write permission is not set
     without prompting.
-r   Recursive remove directories and subdirectories in
     the list. Files will be removed in these directories
     first and then the directory itself.

Example(s):

hawk% rm prog1.cpp
hawk% rm -i *.cpp
hawk% rm -fr prog2.cpp hw1_dir

Rename a file/directory [back]

Command: mv

Arguments: existing_file new_file

Options: -i

Description: Renames existing_file to have the name new_file -i Prompts if mv would overwrite an existing file.

Example(s):

hawk% mv prog1.cc prog1.cpp

Copy a file [back]

Command: cp

Arguments: existing_file new_copy

Options: -i

Description: Copy existing_file to the file new_copy. If new_copy doesn't exist, create it. If it does exist, first delete its contents.

If new_copy is a directory, a copy of existing_file is created in directory new_copy with the same file name - existing_file.

-i   Prompt if the new_copy file already exists, before
     overwriting it.

Example(s):

hawk% cp sample.cpp prog1.cpp

hawk% cp ~glancast/343class/dot_emacs.zip .

Create a directory [back]

Command: mkdir

Arguments: new_subdirectory_name

Options:

Description: Create a subdirectory of the current directory

Example(s):

hawk% mkdir hw1

Change the current directory [back]

Command: cd

Arguments: target_directory

Options:

Description: Change the current directory (working directory) to the specified target_directory. If no target_directory is specified, change to the login directory.

Example(s):

hawk% cd hw1

hawk% cd ..

hawk% cd

Print a File[back]

There are no accessible printers for the Unix account.

So to print a file, you need to use ftp to transfer the file to a PC. You can then print the file as you would any other file on the PC.


Email a file from your Unix account.[back]

To email a text file as a message, say blob.cpp, from your Unix account to mine non-interactively:


hawk% mailx -s "subject line here" <blob.cpp glancast

To mail the same file interactively as an attachment to a message with a subject, etc. use the email program pine.

hawk% pine

In pine, type C to Compose a message and then tab to the appropriate prompt to specify the recipient (lancaster@cs.depaul.edu), the subject, and the message.

To      : 
Cc      : 
Attchmnt: 
Subject : 
----- Message Text -----


Move (by tabbing again) to the Attchmnt: entry.

Type ctrl-T to get to your directory to select the file to attach. Use the arrow keys to move to directories or files.

If the cursor is on a directory name, the Enter key will display the contents of the directory. If the cursor is on a file name, the Enter key will select that file as the attachment to your email message and return you to the message.

hawk% pine

Compiling

Compile a C++ program and run it. [back]

To compile a single file C++ program in a file named prog.cpp use the g++ compiler.

hawk% g++ prog.cpp -o prog

This compiles the program in prog.cpp, links it with any standard c++ library routines called (e.g. i/o routines) and produces the executable file named prog.

Now run prog:

hawk% prog

Simple make files.[back]

Instead of typing the command to execute the g++ compiler as:

 g++ prog.cpp -o prog

You can simply type:

make prog

The make program is a utility which can build executable files from source files, but it generally has to be told what to build, what the executable depends on, and how to build the executable from these dependencies. (The make program can make certain assumptions if you don't specify all of these.)

Here is a simple make file for the compilation above in which you specify the target, dependencies, and the rules for building the targets. The make utility will automatically look for a file named 'makefile' first (then for 'Makefile').

Here is a sample file (it would be named 'makefile'):

prog: prog.cpp
        g++ prog.cpp -o prog

If this file, 'makefile', has been created, to compile or recompile, you can simply type:

make

For simple cases like this where there is only one target that depends on only one file, the default rules that make uses are sufficient and no actual 'makefile' is necessary. However, in this case you still have to tell make the name of the target:

make prog
In the case the make utility doesn't find either 'makefile' or 'Makefile', it will look for a source file named prog.cpp (or prog.xxx for other file extents make knows about). If make finds prog.cpp, it will use it as the file on which the target depends and make knows a default rule to compile 'prog.cpp' with executable output named 'prog'.

Unix online Manual[back]

Browse Unix man pages

To view the unix online manual, you need to know the exact name of a manual topic; e.g., fork. In some cases you may not know the exact name. You can try the man command with the -k option (for keyword)

hawk% man -k fork
/usr/local/graphics/man/windex: No such file or directory
/usr/local/teTeX/man/windex: No such file or directory
/condor/cscfclt/glancast/local/man/windex: No such file or directory
fork		fork (2)	- create a new process
fork1		fork (2)	- create a new process
pthread_atfork	pthread_atfork (3t) - register fork handlers
vfork		vfork (2)	- spawn	new process in a virtual memory	efficient way
fork		fork (2)	- create a new process
fork1		fork (2)	- create a new process
pthread_atfork	pthread_atfork (3t) - register fork handlers
vfork		vfork (2)	- spawn	new process in a virtual memory	efficient way

The output shows all manual topic names in the first column related to the keyword entered (fork).

Display a manual page

Once you know the name of the manual page for a topic use the man command again with that specific topic:

hawk% man fork
System Calls						  fork(2)



NAME
     fork, fork1 - create a new	process

SYNOPSIS
     #include <sys/types.h>
     #include <unistd.h>

     pid_t fork(void);

     pid_t fork1(void);

DESCRIPTION
     The fork()	and fork1() functions create a new process.   The
     new  process (child process) is an	exact copy of the calling
     process (parent process).	The child  process  inherits  the
     following attributes from the parent process:
 
     .... (continues)

Saving/Printing a Unix manual page to a file

To put the same manual page information in a (new) file in your directory named fork.txt:

hawk% man fork | col -b > fork.txt

Once you have this file, you can transfer it to a PC using ftp and print it just like any other file.


Vim

For the moment see this file vim_commands.html. I'll reorganize this by editing tasks soon.


Emacs

Start, Suspend, and Exit emacs [back]

Start emacs:

hawk% emacs

Suspend emacs. Once emacs is started, you can temporarily suspend emacs and go to the Unix prompt. Then return to the emacs session where you left off.

Suspend emacs:  ctrl-x ctrl-z
Resume emacs:   hawk% fg
Exit emacs: ctrl-x ctrl-c

Abort any emacs command [back]

Abort any command: ctrl-g

Create a new file or find an existing file [back]

Before any editing you need to create a new file or find an existing file with the find-file command:

find-file:  ctrl-x ctrl-f

Compile a program in emacs [back]

After copying the dot_emacs.zip file and extracting the .emacs file it contains, the emacs compile command is bound to the keys:

compile: ctrl-c c

Find next compile error [back]

next-error:  ctrl-x `   (That's the ctrl-x and then the
                         back-quote key, which is located 
	                 just to the left of the number 1 key.)

Cursor movement[back]

previous-line:	ctrl-p or up-arrow 
next-line: ctrl-n or down-arrow
backward-char: ctrl-b or left-arrow
forward-char: ctrl-f or right-arrow
scroll-up: ctrl-v  (scroll the text up nearly a full screen)
scroll-down: ctrl-z (scroll text down nearly a full screen)
forward-word: Esc-f  (Escape key + f)
backward-word: Esc-b
beginning-of-line: ctrl-a
end-of-line: ctrl-e

Cut and paste[back]

The cut (kill-region) command works on the region between the point and the mark. The point is the location of the cursor. You set the location of a mark with the set-mark-command, which sets the mark to be the current location of the cursor (the current point).

So to cut a region of text

  1. move the cursor to the first character of the region.
  2. set the mark (ctrl-c m, if you have unzipped dot_emacs.zip)
  3. move the cursor to the character just after the region.
  4. kill-region (ctrl-w)

To paste a previously cut (killed) region:

  1. Move the cursor to the position where the text is to be inserted.
  2. ctrl-y ("yank" - insert the last killed text)

Summary of Cut/Paste Related keys

set-mark-command: ctrl-m
cut (kill-region): ctrl-w
paste (yank): ctrl-y
exchange-point-and-mark: ctrl-x ctrl-x

Since the region between the mark and the point is not highlighted, the exchange-point-and-mark command is useful to check where the mark (and point) are currently located since they determine the region that will be acted upon by a cut operation.


Managing emacs Windows[back]

Commands to split/delete/navigate emacs windows

Command Name Key(s) Description
split-window-vertically ctrl-x 1 Split the current window (containing the cursor) into two windows, each visiting the same file.
delete-window ctrl-x 0 Delete the window (but not the buffer or the file it holds) containing the cursor.
other-window ctrl-x o Move the cursor to the next window. Does nothing if there is only one window.