Unix Help
THE UNIX FILESYSTEM

Navigating the Unix Filesystem

cd			         Change directory - the basic command used to 
				 navigate Unix file systems. It has a number of
				 different uses including: 

cd / go to the root directory cd go to your login (home) directory cd ~username go to username's login (home) directory not allowed in the Bourne shell cd ~username/directory go to username's indicated directory cd .. go up one directory level from here cd ../.. go up two directory levels from here cd /full/path/name/from/root change directory to absolute path named note the leading slash cd path/from/current/directory change directory to path relative to here. note there is no leading slash

mkdir directory-name Make a directory rmdir directory-name Remove a directory pwd Print working directory - Tells where you are.



Displaying Directory Contents

To display the contents of a Unix directory use the ls (list) command. The command is of the format: ls - [options] [argument]. A short note about format, when arguments of a command are listed in square brackets those arguments are optional. In this case both options and arguments are optional which means that the ls command requires neither. Also note that options are always preceded by " -".

When ls is used with no options, it lists the contents of the current directory, except those file and directories that begin with a dot (.). When used with no options but with an argument, it lists the contents of the argument. For example "ls /etc" lists the contents of the /etc directory. A listing of some of the most commonly used options follows:

	a Lists all files including those starting with a dot (.)
	d Lists only directories, not files within the directories
	F The listing will indicate the type of entry with the 
	  following trailing symbols. 
	 	/   directories 
	 	=   sockets 
	 	@   symbolic links 
	 	*   executables
	l Long listing, lists the mode, link information, owner, 
	  size and last modification time.  Each output line 
	  begins with the mode field which consists of ten 
	  characters.  The first character is a - for a plain 
	  file and a d for a directory. The next nine characters 
	  consists of three sets of three characters which 				  indicate file permission.  The first three refer to the owner,
	  the next three to the group assigned to the file and 
	  the last, three to all other users. Within each group 
	  of three characters r indicates read permission, w 
	  indicates write permission, x indicates execute
	  permission and - indicates no permission.
See the man pages for more formation about the ls command.



Changing Directory and File Permissions

Every Unix file and directory has associated with it permissions for who can read it, write to it and execute it. The ls -l command displays the permissions. ( see Displaying Directory Contents above).

To change permissions use the chmod command. There are two different systax forms for the chmod command.

The first syntax is: chmod xxx filename The xxx is a three digit number where the first digit sets the permissions of the file owner the second sets the permissions of the file group and the last sets the permissions of all other users. Each digit is made up of the sum of the following:

 read	  4 
 write    2 
 execute  1
For example suppose we execute the following Unix command:
 ls -l somefile
The results of the command look like this:
 ---------- 4 someowner somegroup 512 Aug 9 15:34 somefile
This is a file on which the owner someowner members of the group somegroup and other users have no permissions, so no one can read it, write to it or execute it. To set this file so that the owner can read, write and execute it, the group can read and execute it and other users still have no per- missions we use the following Unix command:
 chmod 750 somefile
 
The first digit (for the owner is: 4 (read) + 2 (write) + 1 (execute) = 7; The next digit (for the group is: 4 (read) + 1 (execute) = 5; The final digit (for all other users) is 0

If we repeat the ls -l somefile command after the chmod 750 somefile command is executed, we get the following result:
 -rwxr-x--- 4 someowner somegroup 512 Aug 9 15:34 somefile
The second syntax is: chmod mode file1 file2 ...

For example: chmod -R mode dir
Changes all files in dir

Mode can be any of the following settings:

 u  user (owner)
 g  group
 o  other
   
 +  add permission
 -  remove permission
      
 r  read
 w  write
 x  execute
 

Example: chmod go+rwx public.html
adds read, write, and execute permissions for group and other for the file public.html.

See the man pages for more information about the chmod command.

Creating, Viewing, Moving and Deleting Files

Creating Unix Files

Unix files are created by using a text editor such as vi or emacs or with the commend touch filename

Viewing Unix files

There are several ways to view a Unix file including cat, more, less and view

   cat  concatenate - prints the contents of a file to the screen.
   more displays the contents of a file one screen at at time. 
   	    pressing the space bar displays the next screen.
	    pressing the cr or return key display the next line.
   less is similar to but more powerful than more  
	    See the man page for more information on less
   view is a read only version of vi
	    See the man pages for more information on view

head n filename displays the first n lines of the file.
tail n filename displays the last n lines of the file.
Moving Unix Files

To move a Unix file from one directory to another use the mv (move) command.

mv filename target

The mv command moves filename to target.

Deleting Unix files

To remove Unix files use the rm commend.

rm -[options] filename

The rm command removes the directory entry specified by the filename argument. There are several options, the most common are listed below.
  f Remove all files in a directory without prompting the user.
  i Interactive. With this option, rm prompts for confirmation  
    before removing any files.
  r Recursively remove directories and subdirectories in the 
    argument list. The directory will be emptied of files and 
    removed.
See the man pages for more information on rm