0% found this document useful (0 votes)
43 views

Combine in OS

The document summarizes several Linux commands used for process management, job control, communication between systems, and file comparison/transfer. It describes commands like ps, jobs, wait, sleep, nohup, cu, ftp, mailx, talk, vacation, write, cmp, and comm. Key details include how ps lists running processes, jobs tracks background processes, wait pauses for jobs to finish, and communication tools like cu, ftp allow transferring files between systems.

Uploaded by

Hardik Darji
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Combine in OS

The document summarizes several Linux commands used for process management, job control, communication between systems, and file comparison/transfer. It describes commands like ps, jobs, wait, sleep, nohup, cu, ftp, mailx, talk, vacation, write, cmp, and comm. Key details include how ps lists running processes, jobs tracks background processes, wait pauses for jobs to finish, and communication tools like cu, ftp allow transferring files between systems.

Uploaded by

Hardik Darji
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 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 single

Command , 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
# 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 15
minutes.
- 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 exit
is to use the nohup command.
- It redirects the message to a file called nohup.out . Under the directory from which the
command 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
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 use
Several 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
- 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 the
mailx 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 :-
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@host
o host!username
o host.username
o 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 :-

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 :

à 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.

 Lines that exist only in the first file.


 Lines that exist only in the second file.
 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,

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

====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.
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 :

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

 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:

 Owner : The user who created the file.


 Group : the group to which the owner be longs.
 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.

à 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)

-f à Remove 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 )

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.

-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.

 cat file1 file2 file3 > newfile


o if the file newfile already exists it is overwritten with the coneatenated files file1
file2 & file3.
 if nesfile already exists & u want to concatenage at the end of the existing file instead of
using 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

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.

 gives you the flexibility to search for a file by various attributes, such as name, size,
permission and so on.
 Also, allows you to execute commands on the files that are found as a result of the
search.
Format: find dir-name search expression

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

 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 number
 to specify the size of the file to be used for searching the file size specified is in
blocks.
 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.

 atime – access time


 mtime – modified time
 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)

s – socket

 user -> to search for files whose owner matches the specified username.
 perm permission -> to search for files with a specified permission
 newer filename -> to search for files that have a time of modi later than that of the
specified filename.
 Gray grpname -> to search for files that belong to the specified group.
 Inum number -> to search for files a nose I-node no. matches the specified inode
number.
 Links number -> to search for files with a specified number of links
 Ls -> to print the current pathname along with the I node no., size in kb, protection
mode, no. of hardlinks, user, group, size in bytes, modi. Time
 Exec command -> to execute the command.
To execute the command on the list of files found by the find command, use {} followed
by \ ;

 ok command -> -do- unix asks for confirmation before executing the command
 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 the
last 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.


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


2 if u want to start from the bottom of the file rather then at the top of the file & go
backwards
more +g file1

less: may not available by default on all unix systems behaves similarly to the more
command,except that the less command allows u to go backward as well as forward in the file by
default.
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 numberÞstart from the specified char. posi. number.

-b numberÞstart from the specified 512-byte block posi. Number.

-k numberÞstart from the specified 1024 – byte block posi. Number.

-n numberÞstart display of the file at the specified line no.

-r numberÞdisplay lines from the file in reverse order.

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

 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
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 number Þdisplay the no of bytes from the top of the file.

Þ-n numberÞdisplay the no . lines from the top of the file.

wcÞcounts the no. of bytes,words and lines in specified files.

EX

Wc file1

25 125 491 file1


lines words bytes

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

Flag

-lÞcount only the no. of lines in the file.

-wÞcount only the no. of words in the file.

-cÞcount only the no. of bytes in the file.


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<namefile.

Þthis reads the first name & last name from the namefile file and prints them.

Od: can be used to display the contents of a file in a specified format

(executable file)Þfiles that are not text.

Pg: displays the contents of a file one page at a time just like the more and less command do

Flag:

-cÞclear the screen at the end of each page of display and start the display at the top of the screen

-eÞcontinue to the next file at the end of one file,if the pg command is invoked with multiple files.

-fÞtruncate lines that are longer than the width of the screen display.

-p stringÞ display the string as the pg command prompt

:}def. Prompt

%d}Þthe page no. is displayed at the prompt.

-sÞhighlight all messages & prompts issued by the pg can.

+numberÞstart the display of the specified line no in the file

-numberÞset the size of the display screen to the spec. no. of lines

+/pattern/Þsearch for the pattern in the file& start the display at that line.
Ex: pg -7 -s -p”enter commandÞ”file1

Pg+/”line5”/file1
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 u
want 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 –a
Cat 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 mode
2 text input mode
3 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,


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.

 Flags
o -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 egrep
o -F behaves as fgrep.
o -f filenamespecify 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/p
o -Q suppress all o/p
o -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 file1


2 grep –i -n dummy file1 à relative line number
3 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 )
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 later
time.
 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 don’t
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 :-
-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)


- 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 then
0 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.
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 the
Files 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


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 to
Convert 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.

Pack:- 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:-
-f force packing

Ex. Pack file1.

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

Ex. With pack command file1.2 then

Pcat file1.2

Tar :- 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.

Flag :-

-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.

Examples:-
(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

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

Umcompress file1.2

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

using the pack command.

Unpack file1.2 >file2

Status 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 variables
called 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
 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.


 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, physical
Volumes , 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.


-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 the
following command.
4 Cut –d”s” –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 the
specified width

-w width specify the line width.


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 be
std. O/p)

- each line in the file is merged on the basis of a field that has the same value in both
i/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 basis
of the field in the second file.
- -e string à specify that blank fields in the o/p file be
replaced by the specified string.
- -o field.fieldnumber à specify that the o/p should consist of the specified
fields.
à 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 the
Non-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.


- 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.
- -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 order


sort –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


à [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 letter


tr [:lower:] [:upper:] <file1

3 if u want to delete all the newline char ‘\n’ from the file
tr –d ‘\n’ <file1

4 if u want to delete all but the first occurrences of a space & replace the
space with a –(hypen) tr –s ‘ ‘ ‘-‘ <file1

UNIQ :-
Can be used to eliminate duplicate adjacent lines from a file or from std. I/p to

Generate std o/p or another file.

- Also it is possible to compare only part of a line for comparison by using


Certain flags.

Flag :-
-c à precede each line with a number while displaying the o/p (the no.
specifies the no of recursences of the line in the i/p file).

-d à display only th elines that occur multiple times adjacent to each other in
the i/p file.

-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 file1
2 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 file1


uniq –u file1

Sed :-

To edit a file using a script

- in the script, u can specify commands to edit one or more lines according rules
specified 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

You might also like