Combine in OS
Combine in OS
Following is a list of some of the flags that determine what process are listed by the PS
command.
- 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
Jobs :- A job is typically one command line of commands ,which can be a single
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.
# 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 * &.
Communication : commands
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
-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 –
~%cd dir - Change the directory on the local host to the specified
directory.
cu remote2
lu –s 2400 –l tty1
- To execute the ls command on the local system, execute the following command ;
o ~!ls
FTP :-
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
- terminated by ctrl – d
Talk :-
- U can converse with another user in real time using the talk command if
- 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,
talk testuser@host1
Vacation :-
If u want to notify a mail sender that u are on vacation, u can use the vacation command.
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.
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 :
à 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.
The values of the return code are null for identical files,
else
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.
flag
-b Ensure that more than one space on tab character is considered as one.
-c Line –
-c Line –
-D string – Create a merged version of the first and second files on the standard output
-e Generate output that can be input to ed to produce the second file from the first file
-r Execute this command on all identically named subdirectory of the specified directory.
diff3:
flag
-3 produce an edit script that contains only lines containing the differences from the
third file
-E , -X –
-e –
-x –
dir cmp :
-à 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
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
-à 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 :
-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
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 .
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 :-
Note :- à on unix systems only the root user can change the owner of a file or directory.
Rm :
Flag :
does not generate any messages the case in which a file does not
recursively.
Mv :
To rename a file and to move from one directory to another refaining the origined file name
( save as copy )
Flages :
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
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
flage :
-q à suppress messages if the cat command can not find one or more of the input files.
-e à display a $ at the end of each line, when specified with the –v flage.
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
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.
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.
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.
2] To search for a file whose permission is 600 ( only owner has read & write permissions)
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,
-exec ls –l {} \;
more: can be used to display the contents of a file one screen at a time
The more command is typically used when o/p from other commands is piped to the more
command for display.
Flag:
+/pattern Þ start in the file at the line no. where pattern occurs first.
EX-1 if u want to start the display of the file at line no.20 of 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.
Flags
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 :
Fail file1
ÞStarts at the top of the file and displays the specified no of bytes or
lines from the top of the file.
Flags
Þ-c number Þdisplay the no of bytes from the top of the file.
EX
Wc file1
Flag
Do
Echo $lname”,”$fname
Done<namefile.
Þthis reads the first name & last name from the namefile file and prints them.
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.
:}def. Prompt
-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
Flag :
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
Mode of vi editors:-
1 command mode
2 text input mode
3 command entry mode
à The grep comms. Search for a string within the specified fiels & display
the o/p on std. O/p.
grep :-
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 :-
5 If you want to find out which lines start with a capital letter A through C
,
Grep “^[A-C]” file1 ( ^ = Caret)
Flag
Printing :-
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.
-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
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
Crontab :- Unix system have a daemon running all the time that can run jobs at
regularly scheduled intervals.
- 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.
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
(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 :-
r:- Copy files interacting with the option of modifying the filename
Example :- (1) If you have a list of files that you want to copy to a diskfile.
(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.
Flags :-
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
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.
(2) If you want to copy file1 on disk to a tape with a block size of 1024,
Pack:- if U want to save disk space,use the pack command to compress a file in a way similar to the
Compress command.
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.
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.
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.
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
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
Flag:-
-i to indicate that only the variables setup as part of the env. Command are used for
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.
Iostat:- can be used to obtain statistics about the cpu ; clicks & tty of a system.
Report. But U can use various flags to collect information about other system activities.
Flags:-
-A report data on all system activities.
UNAME:- Display details about the O/S and computer system on the std. O/P.
Flag:-
-a Display the machine ID, the release number of the O/S ,System name.
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.
Vmstat 5 5 ‘
Text Processing :-
Cut :-
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 :-
Ex :-
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
- 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
Flag :
-s split a line after the last space at a position that is less than or equal to the
specified width
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
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.
paste :-
can be used to paste lines from one or more files(one of them can be std. Input)
Flag :-
-d list à specify chars, that will be used to separate corresponding lines from
the i/p files in the o/p files.
Ex :-
Sort :-
Is used to sort one or more files in the specified order by the specified key.
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.
- -o file à redirect the o/p to the specified file instead of to the std. O/p
- -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
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.
& so on.
Ex :-
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
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
Sed :-
- 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.
Ex :-
1 if u want to print the line no of the line in which a specified pattern is found,
sed –e “/sed/=” file1