combine in os

Upload: hardik-darji

Post on 09-Apr-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/7/2019 Combine in OS

    1/40

    Ps:- this command is used to find out which are currently running.

    Following is a list of some of the flags that determine what process are listed by the PS

    command.

    - A :- List details of all Process running in the system.

    - e :- List details of all Processes , except Kernel Process.

    - k :- List all the Unix Kernel Process

    - p list :- List details of all Process specified in the list.

    - t list :- List details of all Process initiated from the terminals specified in the list.

    -U list :- List details of all Process initiated by the user specified in the list.

    - a :- List details of all Processes that have terminals associated with them.- g :- List details of all Processes.- x :- List details of all Processes that do not have any terminal associated with them.

    Ex. Ps f t tty2

    Give all the Processes executing at terminal tty2,

    Jobs :- A job is typically one command line of commands ,which can be a singleCommand , shell script, or a chain of piped commands. In a chain of piped

    Command has a unique process ID , but all have the same Job ID.

    :- We can use the jobs command to find out the details about active jobs.

    :- Once you have the job ID you can start using it to do primitive job controls.

    :- Use the %(Percent Sign) infront of the job no. to indicate the no. is a job no.

    rather than a Process ID.

    Ex. # Fg %5 -> want to bring job no.5 from bg to fg.

    # jobs

  • 8/7/2019 Combine in OS

    2/40

    # jobs l

    Wait :- You can use the wait command to wait for completion of jobs.

    - It is useful during shell programming when you want one Process to finish the- next Process is invoked.-

    If you do not specify a process ID , Unix will wait for termination of all processes- Spawned by the Kernel Environment.- Ex. To find out wheter the process Id 15060 has completed,- Wait 15060.

    Sleep :- If you want to wait for a certain period of time between execution of commands, use the

    sleep command.

    - Use this command in case where you want to check for, say the presence of a file every 15minutes.

    - The arguments is specified in seconds- Sleep 15.

    Nohup :- The process in unix terminated when you logout of the system or exit the current shell

    whether they are running or not.

    - The only way to ensure that the process currently running is not terminated when you exitis to use the nohup command.

    - It redirects the message to a file called nohup.out . Under the directory from which thecommand was executed.

    - i.e. If you want to execute a script sam-script in by from the current directory.Nohup sam.script.

    - For Example,To find the sample string in all the files in the current directory , execute the

    following : nohup gsep sample-string * &.

    Nohup.out [2] 160788

    Communication : commands

    Used to connect to another gost,

    To transfer files between host computers and so on without logging into a user

    session at the remote system

  • 8/7/2019 Combine in OS

    3/40

    Cu : allows u to connect to another host computer, either directly or indirectly.

    i.e. if u are currently on host1 and u use Cu to connect to host2 ,u can connect to host3

    than host2, so that u are connected directly to host2 and indirectly to host3

    host1 -> host2 -> host3

    -d print diagnostic messages

    -lLine outside the default device to be used for communication

    -n prompt for the telephone no rather than accepting it as part of the

    command line

    -sspeed specify the speed (in bounds) of the line to be used for communication

    between hosts.

    -Tseconds specify the length of time unix will try to connect to the remote host.

    - Once you are able to successfully log into the remote host, u can useSeveral subcommands.

    - Remember to prefix the ~ with a \ so that unix does not apply special meaning to

    ~. - Disconnect from the remote host.

    ~! - Disconnect from the remote host.

    ~!command - Execute command at the local host.

    ~%cd dir - Change the directory on the local host to the specified

    directory.

    ~$command - Run, on the local system

    the command denoted by the command vari and send the

    commands qp to the remote system for execution.

    cu remote2

    lu s 2400 l tty1

  • 8/7/2019 Combine in OS

    4/40

    - To execute the ls command on the local system, execute the following command ;o ~!ls

    FTP :-

    To transfer files between 2 host computers

    ftp otherhost

    open otherhost

    get filename

    put filename

    close

    bye or quit

    mailx

    - u can send mail to other users in the system and receive mail from them by using themailx commands.

    - It also provides subcommands to facilitate saving,deleting and responding to messages.- Also provides facilities to compose and edit messages before finally sending it to one or

    more users.

    - Unix uses mailboxes to receive mail for a user.- Each user has a system mailbox in which all mail for that useris received pending action

    by the user.

    - The user can read, save and delete the mail after the mail is received.- The default secondary mailbox is called the mbox. It is usually present in the home dir.

    of the user.

    Ex :-

  • 8/7/2019 Combine in OS

    5/40

    Mailx

    mail > prompt from which u can use the subcommands.

    mail f - To see the mail.

    now use on friend1 to create & send mail to other users

    - terminated by ctrl d

    Talk :-

    - U can converse with another user in real time using the talk command if

    the other user is logged on.

    - Take one mandatory argument :o The username or user and hostname.

    U can Optionally provide a second arg. That specifies the TTY onto which the user is logged.

    - The user on the remote host can be specified in one of the following formats.o username@hosto host!usernameo host.usernameo host;username

    when u execute the talk command, it opens 2 windows,

    - One for sending messages and- One for receiving messages

    The command waits for the other user to respond.

    Ex :-

  • 8/7/2019 Combine in OS

    6/40

    talk friend To quit the talk session, press ctrl + c

    talk testuser@host1

    Vacation :-

    If u want to notify a mail sender that u are on vacation, u can use the vacation command.

    - We can customized message in a file called .vacation.msg in your home directory.

    - If this file does not exist, a system default message is send.

    Before u go on vacation, use the following command to initialize the .vacation.dir and

    .vacation.peg files in your home directory

    Vacation I

    This should be followed by the creation of the .forward & .vacation.msg files.

    Write :-

    We can use the write command to hold a conversation with another user in the local host or

    remote host, just as u can with the talk command.

    - To hold a conversation with another user, the following must be true.o The user must be logged on.o The user must not have denied permission by using the mesg command.

    - A message consists of all the characters u type until u press Enter key.- To end the conversation Press ctrl d.

    File comparision: -

    Cmp : Compares the content of 2 files and generates o/p into std. Output.

    Following are the o/p generated by the cmp command :

  • 8/7/2019 Combine in OS

    7/40

    No o/p if the Files are exactly identical.

    Display the byte no. and line no. of the first position where the

    files are different.-l Displays, for each different, the byte no. in decimal and the differing bytes

    in the octal.

    -s Return only and exit value without generating any output.

    The values of the return code are null for identical files,

    1) if the files are different ,2) if the cmp file is not successful in comparing the files.

    Eg:- 1. cmp newprog1 old prog1

    2. ret_code =cmp s newprog1 oldprog1

    if [[$ret_code eq null]] then

    echo file are identical

    else

    echo files are different

    fi

    Comm : If you have files that are sorted and you want to compare them, use the comm. Command.

    -can be used to either exclude or include the common lines between the two files.

    -def. Output on the std. Output in 3 columns.

    y Lines that exist only in the first file.y Lines that exist only in the second file.y Lines that exist in both files.

    Flag:

    -1 Suppress the display of the first column

    -2 Suppress the display of the second column

    -3 Suppress the display of the third column

    Ex: comm file1 file2

    -if you are interested only in finding out which lines are identical in file1 and file2,

  • 8/7/2019 Combine in OS

    8/40

    comm 12 file1 file2

    diff: you can compare text files with diff command

    flag

    -b Ensure that more than one space on tab character is considered as one.

    However, reading space or tab characters are processed as is.

    -c Line

    -c Line

    -D string Create a merged version of the first and second files on the standard output

    -Defining string compiles the second file

    -e Generate output that can be input to ed to produce the second file from the first file

    -I Compare the 2 files ignoring case of letters.

    -l Generate formatted output

    - Also generates a summary at the end-n Generate output in the reverse order of the e flag

    Also generates the count of lines added and deleted

    -r Execute this command on all identically named subdirectory of the specified directory.

    -S file Ignore files

    - used while comparing directory to ignore filenames-w Ignore all space and tab character

    i.e. Treat them identically for comparison purposes

    diff3:

    - The diff command compares 2 files- If you want to compare 3 files at the same time then use diff3 command- Writes output to standard output that contains the following notations to identify the

    differences:

    ==== means all 3 files differ

    ====1 means the first file differ

    ====2 means the second file differs

  • 8/7/2019 Combine in OS

    9/40

    ====3 means the third file differs

    flag

    -3 produce an edit script that contains only lines containing the differences from the

    third file

    -E , -X

    -e

    -x

    dir cmp :

    - if u want to compare the contenets of 2 directories

    - this commant compares the names of the files in each directory and generates a list

    of filename that exits in only one of the directories followed by filenames that exist

    in both and whether they are identical or not .

    flag :

    -d - generate a list of files that exist in either of the directories followed by a list of .

    files that exist in both directories.

    -s - generates a list of files that exist in eighter of the directories followed by a list of

    files that are different.

    Sdiff :

    Compares 2 files and display o/p on the std o/p in a side-by-side format.

  • 8/7/2019 Combine in OS

    10/40

    Details of o/p :

    - if the w lines are identical the command displays each line of the 2 files with a series

    of space between them.

    - if the line exists in only the first file , a < is displayed at the end of the line.

    - if the line exists in only the second file, a < is displayed at the beginning of the file.

    if the lines from the two files are different , a | is displayed between the lines.

    Flags :

    -s if u do not want to display the identical lines

    -w no set the width of the display to no.

    -l display onlu the line from the first file if ht lines from the two files are identical.

    -o file create a marged file from the first and second file depending on a no of

    subcommands u can specify.

    Touch :

    If a file does not exist this command creates it (if u have write access to the directory.

    if a file is already present this command modifies the last modifications time of the

    file.

    Chmod :

  • 8/7/2019 Combine in OS

    11/40

    U may have to modify the permission of a firectory or files to either secure then or to make

    them accessible to others .

    y chmod command to modify the permission for files and directoties

    The permission in unix is specified in and octal no(0 to 7)

    permission for a file or directory can be specified for the folloing:

    y Owner : The user who created the file.y Group : the group to which the owner be longs.y World of others : Users other than the owner and users in the group to which the owner

    belonge.

    # ( 4 * value of read bit ) + ( g * value of wrie bit ) + ( 1 * value of execute bit )

    This is chmod 744 test file

    owner with read write and execute permission.

    group with read only permission

    others with execute only permission.

    # we can use symbolic mode also,

    whose permission ( owner,group or others ) u want to change.

    what permission add,subtract or equals u want to perform on the permission

    The permission ( r,w,x and s on)

    write permission to group them chmod gtw testfile.

    if u want to rewoke the read permission other then chmod o-r test file.

  • 8/7/2019 Combine in OS

    12/40

    if u want to grant the saw sorld chmod o=g test file.

    Chgrp :

    If u want to change the group to which the file belongs use the chgrp command.

    Ex To change the owner of testfiel from staff to devp chgrp newgroup testfilename.

    Chown :-

    If u want to change the owner of a file or directory.

    Note :- on unix systems only the root user can change the owner of a file or directory.

    if u want to change owner of testfile to friwel then

    chown friend testfile.

    Rm :

    To remove files permanently from the disk

    Flag :

    -i interactively remove the files ( ask Y or N)

    -fRemove the files without any messages

    does not generate any messages the case in which a file does not

    exist or u donot has permission to remove files.

    -r Remove files within a directory and directories themselves

    recursively.

    Mv :

    To rename a file and to move from one directory to another refaining the origined file name

    ( save as copy )

  • 8/7/2019 Combine in OS

    13/40

    Flages :

    -i move or rename files interaetively

    -r without any messages.

    Cp :

    Can be used to make a copy of the contents of one or more source files as sypecified target

    files if target files already exists it is overwritten with the contents of the cource file.

    Flag :

    -p retain the modification date & time as will as permission modes of the source file

    -I interactive mode

    -h follow the symbolic links

    -r copy files under the specified directories and their subdirectory.

    Cat :

    Cp command allows u to copy one files into another files it does not allow u to copy multiple

    files into the sanefile

    to coneatemultiple files into a single files into a single file use the cat command

    cat f1 f2 f3 > newfile

    flage :

    -n display o/p lines preceded by line nos., numbered sequentially from 1

    -b eliminate line nos., from blank lines when used with the n flag.

  • 8/7/2019 Combine in OS

    14/40

    -q suppress messages if the cat command can not find one or more of the input files.

    -v display nonprintable characters in the file as printable chars

    -e display a $ at the end of each line, when specified with the v flage.

    y cat file1 file2 file3 > newfileo if the file newfile already exists it is overwritten with the coneatenated files file1

    file2 & file3.

    y if nesfile already exists & u want to concatenage at the end of the existing file instead ofusing the redirection op >use the >> op.

    o cat file1 file2 file3 >> newfile.

    Rcp :-

    Instead of local,

    If y want to copy files from one host to another u can use the rcp command to copy files

    between the same or different hosts.

    If neither thesance non the target file specifies the host name the rcp can behaves the same carry as

    the cp command.

    Flag :

    -p date

    -r recuersevely

    Directory manipulation commands:

    Mkdir : To create a directory

    Rmdir: To remove a directory

  • 8/7/2019 Combine in OS

    15/40

    File Information Commands:

    Ls: used to inquire about the various attributes of one or more files or directories.

    - By def., the list of files within a directory is sorted by filename, we can modify sort order.

    Find: * to search for the particular file.

    y gives you the flexibility to search for a file by various attributes, such as name, size,permission and so on.

    y Also, allows you to execute commands on the files that are found as a result of thesearch.

    Format: find dir-name search expression

    Dirname can be full path name or . (single periond) for the current directory.

    y following is a list of terms that can be used with the find command:- name filename

    to specify the name of the file (including wildcards) to be used for searching.

    - size numbery to specify the size of the file to be used for searching the file size specified is in

    blocks.

    y To specify that you want to match the size of files less than the specified size, use a (minus sign) in front of size. size 5

    And greater than + (plus sign)

    - size number ( The file size is than taken to be specified in number of bytes)- prune to restrict the find command not to process directories recursively.By def., find recursively processes all the directories of subdirectories under the

    specified directory.

    y atime access timey mtime modified timey ctime chang I-node entries

    type filetype -> to search for a specific type of file

    b block special file

    c char. Special file

    d - directory

    f regular file

    l symbolic link

    p fifo ( a named pipe)

  • 8/7/2019 Combine in OS

    16/40

    s socket

    y user -> to search for files whose owner matches the specified username.y perm permission -> to search for files with a specified permissiony newer filename -> to search for files that have a time of modi later than that of thespecified filename.

    y Gray grpname -> to search for files that belong to the specified group.y Inum number -> to search for files a nose I-node no. matches the specified inodenumber.

    y Links number -> to search for files with a specified number of linksy Ls -> to print the current pathname along with the I node no., size in kb, protectionmode, no. of hardlinks, user, group, size in bytes, modi. Time

    y Exec command -> to execute the command.To execute the command on the list of files found by the find command, use {} followed by \

    ;

    y ok command -> -do- unix asks for confirmation before executing the commandy print -> to print the o/p generated as a result of the search.Ex: 1] If u you want to search for all the files in the current directory that have been modified in thelast 24 hours.

    Use the mtime op. as follows:

    Find mtime 0 print

    2] To search for a file whose permission is 600 ( only owner has read & write permissions)

    find. perm 600 print

    3] To search for all filenames that start with test,

    use the name op. and execute

    find name test* print

    4] If you want to search for all files in the current directory that have a size of more than zero

    bytes and less than 50 bytes and whose names start with test,

    find size t0c a size 50c name test*

    -exec ls l {} \;

    file : can be used to determine th type of the specified file

    Executable, text, etc.

  • 8/7/2019 Combine in OS

    17/40

    File contents-Related commands:

    more: can be used to display the contents of a file one screen at a time

    -spacebar to display the next page,

    -Return/enter to display the next line.

    The more command is typically used when o/p from other commands is piped to the more

    command for display.

    Flag:

    +number start display at line no in the file.

    +g start at the end of the file and be able to go

    -number set the size of the display window to number

    +/pattern start in the file at the line no. where pattern occurs first.

    -w Allow u to go back in a file after reaching end of file is reached.

    -v prevent display of nondisplayable chars.graphically

    EX-1 if u want to start the display of the file at line no.20 of file1

    more +20 file1

  • 8/7/2019 Combine in OS

    18/40

    2 if u want to start from the bottom of the file rather then at the top of the file & gobackwards

    more +g file1

    less: may not available by default on all unix systems behaves similarly to the morecommand,except that the less command allows u to go backward as well as forward in the file by

    default.

  • 8/7/2019 Combine in OS

    19/40

    fail: u can use the fail command to display a file, on std o/p; starting at a specified point from

    the top or bottom of the file.

    By default ,tail displays the last 10 lines of the file.

    Flags

    -c numberstart from the specified char. posi. number.

    -b numberstart from the specified 512-byte block posi. Number.

    -k numberstart from the specified 1024 byte block posi. Number.

    -n numberstart display of the file at the specified line no.

    -r numberdisplay lines from the file in reverse order.

    -f display the end of the file continuously as it grows in size.

    y with all these flags, the number u specify can be a number prefixed by a +(plus sign) or a-(minus sign)

    (if u specify +, the fail command starts processing from the top of the file

    if u specify -,or do not specify any sign,tail starts processing from the bottom of the file.

    EX :

    1 : if u want to see the last 10 lines of the file,

    Fail file1

    2 : if u want to skip 25 lines from the start of the file.

    Tail +25 file1

    3. if u want to display the lines of files1 in reverse order.Tail r n 5 file1

  • 8/7/2019 Combine in OS

    20/40

    Head: displays file on the std. O/p.

    Starts at the top of the file and displays the specified no of bytes or

    lines from the top of the file.

    by default,head displays 10 lines.

    Flags

    -c numberdisplay the no of bytes from the top of the file.

    -n numberdisplay the no . lines from the top of the file.

    wccounts the no. of bytes,words and lines in specified files.

    EX

    Wc file1

    25 125 491 file1lines words bytes

    shows that file1 has 25 lines,125 words,&491 bytes.

    Flag

    -lcount only the no. of lines in the file.

    -wcount only the no. of words in the file.

    -ccount only the no. of bytes in the file.

  • 8/7/2019 Combine in OS

    21/40

    Read: is used in shell scripts to read each field from a file and to assign it to a shell variable.

    EX: while read r lname fname

    Do

    Echo $lname,$fname

    Done

  • 8/7/2019 Combine in OS

    22/40

    Ex: pg -7 -s -penter commandfile1

    Pg+/line5/file1

  • 8/7/2019 Combine in OS

    23/40

    Tee: if u want to execute a command and want its output redirected to multiple files in addition to

    the std.o/p, use this tee command

    the tee command accepts input from the stdi/p

    so it is possible to pipe another command to the tee command.

    Flag :

    -a to append to the end of the specified file

    The def. Of the tee comm.. is to overwrite the spp. File

    Ex :

    1 if you want to use the cat comm. On file1 to display it on the screen, but uwant to make a copy of file2,

    cat file1 |tee file2 |more

    2 If you want to append file1 to the end of an already existing file2, use the flag aCat file1 |tee a file2 |more

    Vi can be used to edit one or more files using full-screen mode

    Mode of vi editors:-

    1 command mode2 text input mode3 command entry mode

    File Content Search Command :-

    We can use find comm. To search for filenames in a directory

    To search for a pattern in one or more files,

  • 8/7/2019 Combine in OS

    24/40

    Use the grep series of command.

    The grep comms. Search for a string within the specified fiels & display

    the o/p on std. O/p.

    grep :-

    can be used to search for a specified pattern in one or more files ;

    it displays the matching o/p on std. O/p.

    Flagso -b display the block no. at the start of each line found.o -c display the count of lines in which the pattern was

    found without displaying the lines.

    o -E behaves as egrepo -F behaves as fgrep.o -f filename specify filename that contains the patterns to be

    matched.

    o -h suppress the filenames as part of the display,if more than one file is being searched.

    o -i search, ignoring the case of the letter.o -l list just the filenames in which the speci. Pattern

    has been found.

    o -n display relative line no. before each line in o/po -Q suppress all o/po -V Find lines not matching the specified pattern.o -W search for specified patterns as words.o -X Match the patterns exactly with a line.

    Ex :-

    1 grep dummy file12 grep i -n dummy file1 relative line number3 grep -i -c dummy file1 2( just no of lines found )4 if you want to get a list of all lines that do not contain the

    specified pattern, use the r flag grep i v dummy file1

    script :-

    from a file displays line that are not command.

    5 If you want to find out which lines start with a capital letter A through C,

    Grep ^[A-C] file1 ( ^ = Caret)

    ^[^A-C] (lines do not start with A

    through C )

  • 8/7/2019 Combine in OS

    25/40

    Strings :- Can be used to search for strings in executable files

    Flag

    -a or - search the entire file, not just the data section.

    -o List each string preceded by its offset in the file ( in local )

    -Number Specify a min. string length other than the def. Of 4.

    Printing :-

    Cancel cancel 734

    lp

    pr

    lpstart

    Scheduling :-

    Unix gives you the ability to schedule scripts and commands for execution at some latertime.

    You can specify the exact time when the command should be run. Also provide a way of reporting on the scheduling jobs and removing them if you dont

    execute them.

    At :-

    allows you to do (1) Scheduling a command for execution at a specified time. (2) Display a list of scheduled jobs. (3) Removing jobs from the specified jobs list.

    Flag :-

  • 8/7/2019 Combine in OS

    26/40

    -l Display a list of jobs scheduled by you.

    -m Mail a report of successful execution of the jobs.

    -t date Schedule a job to be executed at the specified date and time.

    -r joblist Remove the jobs specified in the jobs list from the queue.

    Example:- my job at 11:00 -> assuming that current time is 9:30 p.m.

    at 2300 my job

    at 23:00 my job

    at 11:00 p.m. my job

    at 23:00 today my job

    at now + 6 hours my job

    at 6:30 p.m. next week my job.

    AtQ:- Can be used to list the jobs scheduled at a later time.

    The jobs are displayed in the order of time at which the earlier-scheduled jobs displaled first.Flag :-

    -c -> Display a list of jobss in order of time at which the at command was

    executed to schedule the jobs.

    -n -> Display the number of scheduled jobs.

    Crontab :- Unix system have a daemon running all the time that can run jobs at

    regularly scheduled intervals.

    Crontab file of the following fields (Seperately spaces or tabs)

  • 8/7/2019 Combine in OS

    27/40

    - minutes- hour- day- year- day of the week- command

    Example :- lunch at 12:20 then

    30 12 * * * * echo Tome to go for lunch

    - If you want to execute my job on Friday at 4:00 p.m. every week then0 16 * * 5 my job.

    Storage Commands :-

    Compress :- You can use this command to reduce the size of a file.

    Has a .Z appended to its name.

    The compressed file retains the permi & time attributes of the original file.

    Cpio:- You can use this command to copy files to archival medium from disk or to

    restore files from archival medium to disk.

    There are three major forms of this cpio command.

    (1) cpio o to read standard input for path names & copy them to standard o/p.

    (2) cpio i to read from standard input archival files & create disk files.

    (3) cpio p to read standard input for the pathname & copy to the specified

    directory.

  • 8/7/2019 Combine in OS

    28/40

    Flag :-

    d :- Create a directory if the specified directory does not exist.

    f :- Copy files that do not match the specified pathname.

    r:- Copy files interacting with the option of modifying the filename

    t :- Create a list of files without actually copying a file.

    u :- Overwrite a file if it already exist.

    v:- List the filenames being copied.

    Example :- (1) If you have a list of files that you want to copy to a diskfile.

    Ls *.txt | cpio ov > /dev/rfd0

    This example copies all files that have an extension of *.txt

    (2) If you want to copy all files from the current directory as well as theFiles in its subdirectories , use the p flag.Additionally, you can use the d flag .so that all

    the needed directories are created.

    Find print | cpio pd /u/testuser/cpiodir

  • 8/7/2019 Combine in OS

    29/40

    DD :- can be used to read data from the std. Input & copy it to the std. O/p after converting data

    according to specified conversion parameters.

    Flags :-

    if=filename Specify the input filename to be copied.

    of=filename Specify the output filename to be created.

    files=filename Specify the no. of files to be copied ( such as from a tape containing

    multiple files)

    conv=conversion parameter Specify the type of conversion to be used. Some of the values

    of this parameter can be ASCII,EBCDIC,block,unblock,lcase

    and ucase.

    Example :-

    (1) If you have a file from a system that stores data in EBCDIC format & U want toConvert the data to ASCII.

    dd if=file1 of=file2 conv=ASCII

    (2) If you want to copy file1 on disk to a tape with a block size of 1024,

    dd if=file1 of=/dev/rmt0 bs=1024 conv=syne.

    ck:- if U want to save disk space,use the pack command to compress a file in a way similar to the

    Compress command.

    - Generates new file with .z appended to the filename.- The original file is removed.- Get 30% to 59% compress for text files.Flag:-

  • 8/7/2019 Combine in OS

    30/40

    -f force packing

    Ex. Pack file1.

    at:- can be used to uncompress a file to the std. O/p.

    Ex. With pack command file1.2 then

    Pcat file1.2

    r :- it is used to copy files from disk to an archival medium ( usually tape) or vice-versa.

    :- The tar command does not provide any recovery from tap emors.

    g :-

    c Create a new archive & write the file details at the begging of the archieve.

    t generates a list of files in the archieve.

    x Obtain one or more files from an archieve.

    If you specify a directory name -> all the files in the directory are extracted.

    If no file on directory is specified, all the files in the specified archive are extracted.

    -p Restore the files with their original permition, ignoring the current setting of the umask.

    -f archive : Use the specified archive as the archive name istead of the system default.

    -v Display the name of each file as it is processed.

    amples:-(1) If you want to extract all the files in the /u/testuser directory from the archive file on the

    /dev/emt1 tape device.tar xvt /dev/rmt1 /u/testuser

    (2) If U want to archive a file to an archive on the default tape drive,tar drive ,tar c file1

    compress:- can be ued to uncompress a file that has earlier been compressed using the compress

  • 8/7/2019 Combine in OS

    31/40

    Command .

    Umcompress file1.2

    pack :- can be used to uncompress files that have the .z extention & that have been compressed

    using the pack command.

    Unpack file1.2 >file2

    atus Commands:-

    Date:- used to display the current date and time in a specified format.

    Env :- can be used to display the current environment or to chane one or more of the ENV

    Variables. And run a specified command.

    Flag:-

    -i to indicate that only the variables setup as part of the env. Command are used for

    specified command.; all the current variables setups are ignored.

    Example :-

    (1) assumed that my job script that displays the current setting of the Env variablescalled ZANG.

    If U execute the script my job as a part of the ENV command without modifying the

    LANG variable.

    Env path=/u/testuser/jobs : $path my job LANG=c

    If U modify the LANG variable as a part of the Env command

    Env LANG=c++ path=/u/testuser/jobs : $path my job LANG=c++

    Iostat:- can be used to obtain statistics about the cpu ; clicks & tty of a system.

    Display the following details:-

    tty and cpu header. Tty and cpu statistics detail

  • 8/7/2019 Combine in OS

    32/40

    physical volume header. One line for each physical value.

    Sar :- to get a report about system information by definition generates the CPU Utililzation

    Report. But U can use various flags to collect information about other system activities.

    Flags:--A report data on all system activities.

    -a reports data on a use of the file system access reactive.

    -b report buffer activities.

    -c report system calls such as forks ,access & so on..

    -f file Extract data from the specified file.

    -k report on kernel activity.

    -m report on semaphore & message activity.

    -o file save the activity data in the specified file.

    -r report on paging statistics.

    -v report on process and I-node activity.

    -y report on TTY activity.

    UNAME:- Display details about the O/S and computer system on the std. O/P.

    Flag:-

    -m Display the machine ID.

    -r Display the release number of O/S.

    -s Display the system name.

    -v Display the O/S version.

    -S name Modify the system name.

    -a Display the machine ID, the release number of the O/S ,System name.

    Uptime:-display the following the information.

  • 8/7/2019 Combine in OS

    33/40

    the current time the length of a time, the system has been up the no. of users currently logged on. The no. of jobs executing in the system

    Vmstat:- can be used to get information about the processes virtual memeory, physicalVolumes , and CPU activity include CPU utilization , virtual memory and physical

    Volume. This information can be used to monitor the load on the system.

    Details displayed by vmstat are as follows:

    Processes (1) r (2) b Virtual memory (1) avm (2) fre Page (1) re (2) pi (3) po (4) fr (5) sr (6) cy Faults (1) in (2) sy (3) cs Cpu (1) us (2) sy (3) id (4) wa

    Example :- If U want to statistics five times in interval of the five seconds.

    Vmstat 5 5

    Text Processing :-Cut :-

    To extract data from each line of a text file

    can be used for a file that contains data records so that each line consist of one or

    more fields separated by tab characters.

    Flag :-

    -c characterlist specify a list of characters to be cut from each

    line

    -f fieldlist Specify a list of fields to be cut from each line.

  • 8/7/2019 Combine in OS

    34/40

    -d character To override the character to be interpreted

    as the field delemiton.

    -s To suppress lines that do not hr the specified

    delimiter character.

    Ex :-

    1 If you want to extract the first field,cut f1 file1

    2 if you want to cut the chars 2 to 6 ,cut c2 -5 file1

    3 if you want to cut all chars in the first field up to the first 5 character, use thefollowing command.

    4 Cut ds s f1 file1

    ex : invokes the ex editor to edit one or more files

    fmt : can be used to format files to a 72 characters line by default.

    - preserves the blank lines in the i/p file as well as the spacing between words.- U can modify the line length using the width flag

    Fold : can be used to generate multiple lines from a single line by splitting the line at the

    specified position

    - By def, the line length is 80 bytes.

    Flag :

    -b specify the position in bytes.

    -s split a line after the last space at a position that is less than or equal to thespecified width

    -w width specify the line width.

  • 8/7/2019 Combine in OS

    35/40

    Ex : if you want to split the line at byte position 40

    fold -w 40 file1 > file2;

    if you do not want to split words,

    fold w 40 s file1>file2.

    Join :- can be used to merge 2 files (one can be std. Input to execute a third file (Which can bestd. O/p)

    - each line in the file is merged on the basis of a field that has the same value in bothi/p files to create one line in the o/p file.

    - The filed in each file are separated by either a space or the tab character.

    Flag:-- -1 field or j1 field specify that the join should be made on the basis of

    field in the first file.

    - -2 field or j2 field specify that the join should be made on the basisof the field in the second file.

    - -e string specify that blank fields in the o/p file bereplaced by the specified string.

    - -o field.fieldnumber specify that the o/p should consist of the specifiedfields.

    u can specify multiple fields by separating them

    with commands

    - -t char Modify the field seperator char from the default

    value of the space.

    Ex :-

    1 If u want to join the 2 files & display the matching lines as well as theNon-matching lines from the specified file.

    - Join a1 file1 file2

    paste :-

    can be used to paste lines from one or more files(one of them can be std. Input)

    to the std. O/p, which can be redirected to a file.

  • 8/7/2019 Combine in OS

    36/40

    - This comm. concatenates the line from each input file to the output file, separating

    them by default with the tab character.

    Flag :-

    -d list specify chars, that will be used to separate corresponding lines from

    the i/p files in the o/p files.

    u can specify multiple chars if u have multiple i/p files.-s merge subsequent lines from the i/p file for each i/p file, one at a time,

    separated by the specified delimiter char.

    Ex :-

    - if u want to modify def. Separate filename tab to / =>past -d / file1 file2

    Sort :-

    Is used to sort one or more files in the specified order by the specified key.

    It can also be used to merge files that hr already been sorted.

    Flag :-

    - -k key specify the key on which to sort the specification for the key

    inchides the starting field & column position & the end field

    & col. Position.

    - -A Specify the sorting be done according to ASCII sequence.

    - -c check whether the specified files are sorted according to the

    specified key & order.

  • 8/7/2019 Combine in OS

    37/40

    - -d sort according to dictionary order.

    - -f change all letters to uppercase before the sort.

    - -i Ignore nondisplayable characters. For comparison.

    - -m merge presorted of files.

    - -n sort according to numerical valued.

    - -o file redirect the o/p to the specified file instead of to the std. O/p

    - -r sort the o/p in the reverse order of the specified order.

    - -u create only one line in the o/p for lines that sort identically.

    Ex :-

    1 if you want to sort in the reverse order,sort r file1

    2 if you want to sort according to alphabetic ordersort d file1

    tr :-

    to translate or delete characters from std. I/p to generate std. O/p./

    - translate specified chars in the i/p from the input to generate the output.- Delete specified chars in the i/p from the input to generate the output.- Delete all but the first occurrences of the specified chars.

    Flag :-

    -c translate all but the specified chars using the specified new

    characters.

    -d delete the specified chars.

    -s delete all but the first occurrence of the specified chars.

    Specify i/p & o/p sequence of chars

  • 8/7/2019 Combine in OS

    38/40

    [char1-char2] to specify a range of chars. Including char1 & char2

    [char1*number] to specify number occurrences of char.

    [char *] to specify the use of as many occurrences as are needed

    of character so that the i/p string of chars. To be

    translated matches the o/p chars.

    [:charlist:] to specify a list of chars. As the i/p or o/p string.

    The charlist can be upper, lower, alph, space, digits,

    & so on.

    Ex :-

    1 if u want to change the double quotes to spaces,tr \ < file1

    2 if u want to change all lowercase letters to uppercase lettertr [:lower:] [:upper:]

  • 8/7/2019 Combine in OS

    39/40

    -u display only the lines that appears only once in the i/p file.

    -s no. of characters

    or

    +noofchars specify the no of chars from the start of a line that will be ignored

    while comparing adjacent lines.

    -no of fields

    or

    +no of fields specify the no of fields from the start of a line that will be ignored

    while comparing adjacent lines

    Ex :-

    1 if u want to find unique lines in file12 if u want to display only the duplicate line

    uniq d file1

    3 if u want to display the lines that appear only once in file1uniq u file1

    Sed :-

    To edit a file using a script

    - in the script, u can specify commands to edit one or more lines according rulesspecified as part of one or more commands.

    Flag :-

    -e command use the specified sed comm.. to edit the file.

    -f filename use the filename as the editing script to edit the file.

    -n suppress messages from sed.

    Ex :-

    1 if u want to print the line no of the line in which a specified pattern is found,sed e /sed/= file1

  • 8/7/2019 Combine in OS

    40/40