it's Been long time since last unix/linux tips , so today we will learn to use ps / grep / awk / xargs / kill in one long command .. .
ps : prints information about selected processes. Use options to specify which processes to select and what information to print about them .
grep : The grep command searches the input text files (standard input
default) for lines matching a pattern. Normally, each line found is
copied to the standard output. grep supports the Basic Regular
Expression syntax (see regexp(5)). The -E option (egrep) supports
Extended Regular Expression (ERE) syntax (see regexp(5)). The -F
option (fgrep) searches for fixed strings using the fast Boyer-Moore
string searching algorithm. The -E and -F options treat newlines
embedded in the pattern as alternation characters. A null expression
or string matches every line.
awk : awk scans each input file for lines that match any of a set of
patterns specified literally in program or in one or more files
specified as -f progfile. With each pattern there can be an
associated action that is to be performed when a line in a file
matches the pattern. Each line is matched against the pattern portion
of every pattern-action statement, and the associated action is
performed for each matched pattern. The file name - means the
standard input. Any file of the form var=value is treated as an
assignment, not a filename. An assignment is evaluated at the time it
would have been opened if it were a filename, unless the -v option is
used.
An input line is made up of fields separated by white space, or by
regular expression FS. The fields are denoted $1, $2, ...; $0 refers
to the entire line.
xargs : xargs combines the fixed initial-arguments with arguments read from
standard input to execute the specified command one or more times.
The number of arguments read for each command invocation and the
manner in which they are combined are determined by the options
specified.
kill : The kill command sends a signal to each process specified by a pid
process identifier. The default signal is SIGTERM, which normally
terminates processes that do not trap or ignore the signal.
now , it's time to run some examples :
>ps # that is what we have running on the Back Ground ..
>ps | grep sleep # here we filter from the general output the rows with the word sleep
>ps | grep sleep | awk '{print $2}' # here we cut the second string form every row , which is the PID
> ps | grep sleep | awk '{print $2}' | xargs -i kill -9 {} # here we kill the process we filtered on by one by using xargs and the stoping the process with signal 9 by using kill .
and here is the final status :
No comments:
Post a Comment