Unix Tutorial


What is Unix?

Getting started

Hardware

Software

Basic Commands

vi Commands

 

Files

File Commands

Different types of file

File Redirection

Permissions

Pipelines / Filters

 

Directory

Directory Structure

Directory Command

Shell

Different types of shell

Compiling Program

Networking

Commands

Reference

Reference Commands

Online help : Manpages

Useful links/Books

 

Search Engine

Directory Commands


Directories are used to organize your files.Here is the list of directory commands :

mkdir || rmdir || pwd || ls ||cd ||


 

ls Command:

  • When you first login, your current working directory is your home directory. Your home directory has the same name as your user-name, for example, f1011or cs1234, and it is where your personal files and subdirectories are saved.
  • To find out what is in your home directory : type at Paris % ls (short for list).
  • The ls command lists the contents of your current working directory.
  • If there is no files visible in your home directory, in which case, the UNIX prompt (Paris : Default Server) will be returned.
  • Alternatively, there may already be some files inserted by the System Administrator when your account was created.First time when you open your account by default public_html and windows folder will be created.ls does not, in fact, cause all the files in your home directory to be listed, but only those ones whose name does not begin with a dot (.) Files beginning with a dot (.) are known as hidden files and usually contain important program configuration information. They are hidden because you should not change them unless you are very familiar and know exactly what you want to do.
  • To list all files in your home directory including those whose names begin with a dot,

type % ls -a ls is an example of a command which can take options: -a is an example of an option. The options change the behaviour of the command.

Command flags for ls are as following :

Flag
Meaning
-1
Force single-column output on listings.
-a
List all files, including any dot files.
-C
Force multiple-column output on listings.
-l
Generate a long listing of files and directories.
-r
Reverse the order of any file sorting.
-R
Recursively show directories and their contents.
-s

Show size of files, in blocks

 

-t
Sort output in most-recently-modified order.
-x

Sort output in row-first order.

 

 

top of the page


mkdir command :(Make Directory)

  • The command mkdir creates a new directory. You will find it useful to make a new directory for each new assignment you have.
  • We will now make a subdirectory in your home directory to hold the files you will be creating and using in the course of this tutorial. To make a subdirectory called csc1000 in your current working directory type % mkdir csc1000 .To see the directory you have just created, type % ls
  • Now suppose that you want to make this sample directory tree Home Directory with two subdirectories bin and csc1000.In csc1000 make further two subdirectories homework1 and homework2.we can do this by typing

%cd

This is just to ensure that you are working in your home directory.

%mkdir bin csc1000

At this time we have created two subdirectories bin and csc1000 in our home directory.

%cd csc1000

Now we are in csc1000 directory.

%mkdir homework1 homework2

we could have done the same above steps in just two steps.

%cd

%mkdir bin csc1000 csc1000/homework1 csc1000/homework2

Here the first command changes to the home directory.The second command makes two new directories as well as makes two subdirectories in csc1000.

top of the page


pwd Command

pwd is one of the most useful Unix Commands.The pwd(print working directory) tells in which directory you are working for that moment.When you type at the prompt

%pwd

this is your working directory.

/home/users/login_id

top of the page


 

cd Command

  • This command is used to change directory.For example,type

%cd director

where director is the name of the directory to which you want to change.

  • If you enter the command without a directory name,cd will, by default,change to your home directory.
  • To change to root directory,type

%cd /

  • To change your working directory to /public_html/csc5750/homework1,type

%cd /public_html/csc5750/homework1

  • To change above directory homework1 to homework2,type

%cd..

Now if you do pwd your directory will look like public_html/csc5750.Type

%cd homework2

top of the page


rmdir Command

rmdir command is used to remove a directory. For example you want to remove directory extra,type

% rmdir extra

This will remove the directory extra.

To remove a directory we first remove all the file in it, then remove the directory with rmdir ( r emove d irectory).

% pwd

jeremy

% cd letters

% pwd

jeremy/letters

% rm *

% cd ..

% rmdir letters

The command rm * removes all files in the current directory. The command cd .. changes the current directory to the parent of the current one. In this case, it changes us from jeremy/letters to jeremy . Remember that jeremy/letters is a path.

top of the page