copy of unix commands.pdf

Upload: chintan-manek

Post on 28-Feb-2018

226 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/25/2019 Copy of Unix Commands.pdf

    1/50

    UnixUnix

  • 7/25/2019 Copy of Unix Commands.pdf

    2/50

    Logging In and OutLogging In and Out

    As a multi-user system, when connectedto UNIX System through remoteterminal, it will prompt you as:

    login:studentpassword: _ Here password is not displayed, and

    cursor is on its place as it is. $ is the default prompt, offered by UNIX

    System.

  • 7/25/2019 Copy of Unix Commands.pdf

    3/50

    Logging In and OutLogging In and Out

    passwdis the simple command in UNIXSystem to change current user password.

  • 7/25/2019 Copy of Unix Commands.pdf

    4/50

    Introductory CommandsIntroductory Commands

    date:

    ?Date is the command used to display systemdate and time.

    clear:?Clear is one of the commands to clear the

    screen.

    ?Another command works similarly istput clear

  • 7/25/2019 Copy of Unix Commands.pdf

    5/50

    Introductory CommandsIntroductory Commands

    who

    who am I

    ?Who is the command which will display user

    information logged on to the UNIX System,where as who am i is another commandwhich will display information of only aperson who is executing the command.

  • 7/25/2019 Copy of Unix Commands.pdf

    6/50

    Introductory CommandsIntroductory Commands

    man

    ?Man is a simple utility which will display helpfor any command specified as an argument.

    ?Another pattern used in some Linux versionsare: --help

  • 7/25/2019 Copy of Unix Commands.pdf

    7/50

    datedate CommandCommand

    With datecommand?%m: To display month in digit.

    ?%h: To display month name

    ?%d: To display day in digit.?%H: To display hour digits

    ?%M: To display minute digits

    ?%S: To display second digits

    date +%h %d %H %M

  • 7/25/2019 Copy of Unix Commands.pdf

    8/50

    whowhoCommandCommand

    Withwho command:? -H: will display headings for each column

    ? -u: will display more details including PID.

  • 7/25/2019 Copy of Unix Commands.pdf

    9/50

    ttytty CommandCommand

    With ttycommand:? It stands for (TeleTYpe)

    ?Used to display terminal device on UNIX

    System.

  • 7/25/2019 Copy of Unix Commands.pdf

    10/50

    unameuname CommandCommand

    With uname command:?uname will simply display domain name of

    UNIX System on which you have logged on.

    ?uname n is the option using which machinename on network.

    ?uname r will display version of youroperating system

  • 7/25/2019 Copy of Unix Commands.pdf

    11/50

    echoecho CommandCommand

    With echo command:? Is used to repeat and display again on screen,

    passed as argument.

    echo Good Morning

    echo Good Morning

    echo Good Morning

  • 7/25/2019 Copy of Unix Commands.pdf

    12/50

    tputtput CommandCommand

    With tput command:? Is the command for cleaning the screen.

    ?Another use is to position to relocate cursor.

    tput cup 10 20

  • 7/25/2019 Copy of Unix Commands.pdf

    13/50

    bcbc A UNIX CalculatorA UNIX Calculator

    With bccommand:? Is used as calculator in UNIX System.

    bc

    12 + 5 -> 17

    12*12 ; 2 32 x=3 ; y=4 ; z=5

    p = x + y + z

    p -> 12

  • 7/25/2019 Copy of Unix Commands.pdf

    14/50

    HOME DirectoryHOME Directory

    When you log in to the system, UNIXautomatically places you in a directorycalled ahome directory.

    It is created by the System when the useraccount is created.

    ?echo $HOME

  • 7/25/2019 Copy of Unix Commands.pdf

    15/50

    Checking path and changing directoryChecking path and changing directory Checking the current directory position:?$ pwd

    You can move around in the file system by

    using thecdcommand.?$ cd

    ?$ cd /bin

    ?$ cd /

  • 7/25/2019 Copy of Unix Commands.pdf

    16/50

    Making DirectoriesMaking Directories

    Like DOS, directories can be created withthemkdircommand.

    The command is followed by the names

    of the directories to be created.?$ mkdir first

    ?$ mkdir second third fourth

  • 7/25/2019 Copy of Unix Commands.pdf

    17/50

    Removing DictionaryRemoving Dictionary

    Thermdir command removesdirectories.

    ?You cant delete a directory unless it is empty.

    ?Even directory cant be removed where yourpresent command is.

  • 7/25/2019 Copy of Unix Commands.pdf

    18/50

    File ListingFile Listing

    This is simple and powerful command toget list of files and directories.

    ?$ ls

    ?$ ls ?$ ls x (Multiple column output)

    ?$ ls F (Identifying Directories and

    Executables with / and * respectively)?$ ls a (Shows Hidden Files presiding .)

  • 7/25/2019 Copy of Unix Commands.pdf

    19/50

    File ListingFile Listing

    ? -r (Reversing the sort order)? ls xa (Subdirectory

    Listing )

    ? ls xaR? ls l (Long Listing)

    ? ls t (Sorting files by modification time)

    ?

    ls u (Sorting files by access time)? ls i (Shows inode number for file)

  • 7/25/2019 Copy of Unix Commands.pdf

    20/50

    Creating FilesCreating Files

    Cat is useful to create as well as displayfiles in UNIX System.

    ?$ cat > f1.txt (Creates f1.txt file)

    ?$ cat f1.txt (Displaying File Contents)?$ cat < f1.txt (Alternate Command)

  • 7/25/2019 Copy of Unix Commands.pdf

    21/50

  • 7/25/2019 Copy of Unix Commands.pdf

    22/50

    Copying FilesCopying Files

    The cp command copies a file or a group offiles to destination.

    For required two parameters, if two ordinary

    files are given, first is copied to second.?$ cp f1.txt f2.txt

    If destination file exists, will be overwrittenwithout warning.?$ cp f1.txt first?$ cp f1.txt first/f2.txt

  • 7/25/2019 Copy of Unix Commands.pdf

    23/50

    -i is the option used as interactive copyingoption.

    It warns user before overwriting the

    destination file.?$ cp i f1.txt f2.txt

  • 7/25/2019 Copy of Unix Commands.pdf

    24/50

    Removing FilesRemoving Files

    Files can be deleted with rm.?$ rm

    ?$ rm * (It wont warn you!!)

    ?$ rm i * (Interactive Remove Process)?$ rm r * (Removes files and directories

    recursively)

  • 7/25/2019 Copy of Unix Commands.pdf

    25/50

    Renaming FilesRenaming Files

    mv is very similar to MOVE command inDOS.

    It has two purposes, renaming file and

    moving group of files and directories todestination directory file.

    ?$ mv f* second

    ?$ mv test.script new.script?$ mv second sec

  • 7/25/2019 Copy of Unix Commands.pdf

    26/50

  • 7/25/2019 Copy of Unix Commands.pdf

    27/50

  • 7/25/2019 Copy of Unix Commands.pdf

    28/50

    Printing FilePrinting File

    No user is allowed direct access to theprinter.

    Instead, one has to spool a job along with

    others in a print queue. lp (Line Printing) is the command (or lpr)

    to fire print job to the System.

    ?$ lp test.script

  • 7/25/2019 Copy of Unix Commands.pdf

    29/50

    ?$ lp dlaser test.script (specifies thespecific printer name laser)

    ?$ lptTitleHere test.script (Prints title

    on the first page of the print.?$ lp n4 test.script (Specifies the number of

    copies 4)

    ?$ cancel laser (Cancels current job on

    printer laser)

  • 7/25/2019 Copy of Unix Commands.pdf

    30/50

    Know your FILE typeKnow your FILE type

    There are basically three types of files inUNIX System

    ?Ordinary

    ?Directory?Device

    file is the command to

    identify and display the type of file.

  • 7/25/2019 Copy of Unix Commands.pdf

    31/50

    System is able to differentiate betweentext file, C file, FORTRAN file, shellprogram, executables, directories, empty

    files etc.Though this is not accurate utility with all

    the flavors.

  • 7/25/2019 Copy of Unix Commands.pdf

    32/50

  • 7/25/2019 Copy of Unix Commands.pdf

    33/50

    Splitting Files into MultiplesSplitting Files into Multiples

    When it becomes impossible to workwith large files,split command is used tobreak files into multiple files.?

    $ split It splits files default into files namely xaa,

    xab, xac and so on. (Max. : 676) Specify additionally file lines as options to

    over ride default size of 1000 lines.?$ split 15

  • 7/25/2019 Copy of Unix Commands.pdf

    34/50

  • 7/25/2019 Copy of Unix Commands.pdf

    35/50

  • 7/25/2019 Copy of Unix Commands.pdf

    36/50

    -l is the option which gives a detailed listof the byte number and the differing bytesin octal for character that differs in both

    the files.

  • 7/25/2019 Copy of Unix Commands.pdf

    37/50

    Finding CommonsFinding Commons

    Commcompares each line of first filewith its corresponding line in second fileand generates output.

    Output is divided into three columnsseparated by TABs,?First column contains unique lines in first file.

    ?Second column contains unique lines in the

    second file?Third column contains unique lines in both

    the files.

  • 7/25/2019 Copy of Unix Commands.pdf

    38/50

    To drop particular column, -1 | -2 or 3are the options which can be used asparameters.

    ?$ comm f1 f2 1

  • 7/25/2019 Copy of Unix Commands.pdf

    39/50

    Pattern Matching with Wild CardsPattern Matching with Wild Cards

    UNIX System offers several wild cardpatterns to mach the criteria?* : Matches any number of character including

    none

    ?? : Matches a single character

    ? [abc] : Matches single character either a, bor c

    ? [!abc] : Matches single character but not a, bor c

  • 7/25/2019 Copy of Unix Commands.pdf

    40/50

  • 7/25/2019 Copy of Unix Commands.pdf

    41/50

    EscapingEscaping

    It is generally accepted principle thatfilenames shouldnt contain the shellmeta-characters.

    If then do, while accessing, \ is used toescape the sequence (original) meaning ofmeta-characters.

    Enter key is also escaped!!

    ?$ wc l f1 \

  • 7/25/2019 Copy of Unix Commands.pdf

    42/50

  • 7/25/2019 Copy of Unix Commands.pdf

    43/50

  • 7/25/2019 Copy of Unix Commands.pdf

    44/50

  • 7/25/2019 Copy of Unix Commands.pdf

    45/50

    Two or more commands can also becombined and the aggregate output isdiverted to file.

    ?$ (ls l;who) > newFile

  • 7/25/2019 Copy of Unix Commands.pdf

    46/50

    cal for Calendarcal for Calendar

    calcommand is used to display calendar.?$ cal

    ?$ cal 1993 -1 is the option to display current month

    -3 is the command to displayprevious/current/next month

    -s displays Sunday as first week day

    -m displays Monday as first week day

    -j as Julian Date format -y displays calendar of current year

  • 7/25/2019 Copy of Unix Commands.pdf

    47/50

    Tees (And Not Trees)Tees (And Not Trees)

    UNIX provides a feature tee - by whichyou can save the standard output in a file,as well as display it on the terminal orpipe it to another process.

    teeuses standard input and standardoutput, which means that it can be placedanywhere in a pipeline.

    teebreaks up the input into twocomponents, one is saved in a file andanother is passed to standard output.

  • 7/25/2019 Copy of Unix Commands.pdf

    48/50

    ?$ ls | tee file.lst?$ cat One | wc l | tee temp.wc

    ?$ cat Five | wc l | tee a temp.wc

    ?$ cal | tee a file1 > file2

  • 7/25/2019 Copy of Unix Commands.pdf

    49/50

  • 7/25/2019 Copy of Unix Commands.pdf

    50/50