08 unix commands

Upload: pankajchmes

Post on 03-Jun-2018

269 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/11/2019 08 Unix Commands

    1/25

    Revision no.: PPT/2K403/02Revision no.: PPT/2K605/03

    UNIX Commands

  • 8/11/2019 08 Unix Commands

    2/25

    Revision no.: PPT/2K605/03

    CMS INSTITUTE, 2006. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute

    Introduction

    UNIX system provides the user with a number of powerful

    commands to examine and maintain files efficiently.

    Commands take a stream of characters as input and generate

    a stream of characters as output.

    UNIX shell usually treats the terminal keyboard as standard

    input and the terminal screen as standard output.

    Standard error is displayed, by default on the standard output

    which may be redirected to an output file.

  • 8/11/2019 08 Unix Commands

    3/25

    Revision no.: PPT/2K605/03

    CMS INSTITUTE, 2006. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute

    Basic UNIX Commands

  • 8/11/2019 08 Unix Commands

    4/25

    Revision no.: PPT/2K605/03

    CMS INSTITUTE, 2006. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute

    cat

    Syntax

    cat [options] [file 1 file2 file3 .......... ]

    Displays text file contents or copies the contents of file1 into

    file2.

    Example

    To display the contents of the file named poem.

    $cat poem

  • 8/11/2019 08 Unix Commands

    5/25

    Revision no.: PPT/2K605/03

    CMS INSTITUTE, 2006. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute

    chdir/cd

    Syntax

    cd pathname

    Used to change the working directory.

    Example

    To return to your home directory

    $cd

    To change to misc directory by specifying the pathname along

    with the command.

    $cd misc

  • 8/11/2019 08 Unix Commands

    6/25

    Revision no.: PPT/2K605/03

    CMS INSTITUTE, 2006. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute

    clear

    Syntax

    Clear

    To clear the screen

    Example

    To clear the screen on the monitor.

    $clear

  • 8/11/2019 08 Unix Commands

    7/25

    Revision no.: PPT/2K605/03

    CMS INSTITUTE, 2006. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute

    cp

    Syntax

    cp file1 file2

    Used to create duplicate copies of files.

    Example

    To copy the contents of File A to File B.

    $copy fileA fileB

    If the File B exists, the contents of FileB are erazed and the

    contents of FileA are written onto it.

  • 8/11/2019 08 Unix Commands

    8/25

    Revision no.: PPT/2K605/03

    CMS INSTITUTE, 2006. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute

    find

    Syntax

    find pathname -name filename to be search -print

    Used to search for files in a directory.

    The parameters -name and -print are compulsory.

    Example

    To find a file A in the `/` i.e. root directory the command would be

    $find / -name fileA -print

  • 8/11/2019 08 Unix Commands

    9/25

    Revision no.: PPT/2K605/03

    CMS INSTITUTE, 2006. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute

    In

    Syntax

    In file1 file2

    Used to establish an additional filename for the same ordinaryfile.

    In this file1 is the name of the ordinary file for which you wish

    to establish an additional name or link and file2 is theadditional name of the file specified by file1.

    It creates multiple links for the same file.

    Example To create a link for a file `appeal`

    $In appeal appeal1

  • 8/11/2019 08 Unix Commands

    10/25

    R i i PPT/2K605/03

  • 8/11/2019 08 Unix Commands

    11/25

    Revision no.: PPT/2K605/03

    CMS INSTITUTE, 2006. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute

    Is (contd.)

    -r Reverse order of sort of listing

    -R Recursively listing files of all subdirectories

    -p Puts a slash(/) after each filename if that file is a directory.

    -F Puts a slash(/) after each filename if that file is a directory and

    puts a asterisk (*) after each filename if that filename is

    executable.

    R i i PPT/2K605/03

  • 8/11/2019 08 Unix Commands

    12/25

    Revision no.: PPT/2K605/03

    CMS INSTITUTE, 2006. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute

    Is (contd.)

    Examples

    To list the files in the long format in the present directory.

    $ ls l

    total3

    -rw -r--r-- 1 CMS student 13 Jan 1 10:39

    data1

    -rwxrwxrwx 1 CMS student 19 Feb 10 21:35

    data2

    drwxrwxr -- 2 CMS student 32 jan 16 16:50

    prog-files

    Revision no : PPT/2K605/03

  • 8/11/2019 08 Unix Commands

    13/25

    Revision no.: PPT/2K605/03

    CMS INSTITUTE, 2006. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute

    mkdir/md

    Syntax

    mkdir/md pathname

    To create directories in your current directory.

    Example

    To create a directory `dd` in the present working directory

    $mkdir dd

    Revision no : PPT/2K605/03

  • 8/11/2019 08 Unix Commands

    14/25

    Revision no.: PPT/2K605/03

    CMS INSTITUTE, 2006. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute

    more

    Syntax

    more [options] [file1 file2 file3 ............]

    It allows the display of text in controlled increments on a CRT

    terminal.

    It is commonly used to make it possible to read the contents of

    a long text file or the data stream in a pipe line a screen full at

    a time.

    Example

    To list the entire contents of a large directory one screen at a time

    $ls |more

    Revision no : PPT/2K605/03

  • 8/11/2019 08 Unix Commands

    15/25

    Revision no.: PPT/2K605/03

    CMS INSTITUTE, 2006. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute

    mv

    Syntax

    mv [option] file....... Target

    It is used to move or rename files/directories.

    Example

    To rename the file named `wordlist` to `dictionary`.$mv wordlist dictionary

    To move/rename two files `appeal` and `poem` respectively to the

    Mail directory.$mv appeal poem Mail

    Revision no : PPT/2K605/03

  • 8/11/2019 08 Unix Commands

    16/25

    Revision no.: PPT/2K605/03

    CMS INSTITUTE, 2006. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute

    pwd

    Syntax

    Pwd

    To display the full pathname for the current (or working)

    directory.

    Example If one is presently working in `/etc` directory the command would

    give the resultas follows

    $pwd/etc

    $

    Revision no : PPT/2K605/03

  • 8/11/2019 08 Unix Commands

    17/25

    Revision no.: PPT/2K605/03

    CMS INSTITUTE, 2006. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute

    rmdir/rd

    Syntax

    rmdir/rd pathname

    Used to delete a directory (directory should be empty before

    deleting).

    Example

    To remove a directory `asdf` from the present working direcory

    $rmdir asdf

    Revision no.: PPT/2K605/03

  • 8/11/2019 08 Unix Commands

    18/25

    Revision no.: PPT/2K605/03

    CMS INSTITUTE, 2006. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute

    wc

    Syntax

    wc [options] file...

    To count the lines, words and characters in one or more filesthat you specify on the command line.

    Command switches with `wc` are:

    -l to count the number of lines. -w to count the number of words.

    -c to count the number of characters.

    Example To check the number of lines in the file `test`

    $wc l test

    Revision no.: PPT/2K605/03

  • 8/11/2019 08 Unix Commands

    19/25

    CMS INSTITUTE, 2006. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute

    rm

    Syntax

    rm [options] file..

    Used to remove one or more files from a directory. Command switches with `rm` are:

    -f force the removal of files that do not have write permission.

    -R recursively delete the entire contents of the directory as well

    as the directory file itself.

    Example

    To remove the file name `appeal` the command would be

    $rm appeal To delete all the files in the directory Mail as well as the directory

    Mail.

    $rm -R Mail

  • 8/11/2019 08 Unix Commands

    20/25

    Revision no.: PPT/2K605/03

  • 8/11/2019 08 Unix Commands

    21/25

    CMS INSTITUTE, 2006. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute

    tail

    Syntax

    tail [options] file...

    Used to view the end of a file and by default the last 10 lines of

    the file are displayed.

    The switch -n used to print the last n lines of the file mentioned

    in the command.

    Example

    To display last 5 lines of `dd` file command would be

    $tail 5 dd

    Revision no.: PPT/2K605/03

  • 8/11/2019 08 Unix Commands

    22/25

    CMS INSTITUTE, 2006. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute

    who

    Syntax

    Who

    Used to display the names of all the users who are currentlylogged in.

    Example

    To display the users currently logged in$who

    CMS1 tty02 Feb 2 10:30

    CMS2 tty03 Feb 2 9:40

    CMS3 tty01 Feb 2 9:00

    CMS4 tty07 Feb 2 9:00

    Revision no.: PPT/2K605/03

  • 8/11/2019 08 Unix Commands

    23/25

    CMS INSTITUTE, 2006. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute

    who am i

    Syntax

    who am I

    Used to display the name of the current user.

    Example

    To display the name of the user currently logged in.$who am i

    CMS tty02Feb 2 10:30

    $

    Revision no.: PPT/2K605/03

  • 8/11/2019 08 Unix Commands

    24/25

    CMS INSTITUTE, 2006. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute

    Cal

    Syntax cal [month][year]

    Used to display the current calendar month but can be used to

    display any month and year specified. Example

    To display the current calendar month$cal

    May 2004Su Mo Tu We Th Fr Sa

    12 3 4 5 6 7 89 10 11 12 13 14 15

    16 17 18 19 20 21 2223 24 25 26 27 28 29

    30 31

    Revision no.: PPT/2K605/03

  • 8/11/2019 08 Unix Commands

    25/25

    CMS INSTITUTE, 2006. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute

    date

    Syntax

    Date

    Used to display the current date and time.

    Example

    To display the current date

    $ date

    Fri May 21 11:30:05 IST 2004

    $