You are on page 1of 20

Command

sed 's/OLD_Text/NEW_Text/' <old_file>new_file

sed 's/OLD_Text/NEW_Text/g' <old_file>new_file

sed 's/OLD_Text/(&)/g' <old_file>new_file

sed -e 's/OLD_Text/(&)/g' -e 's/OLD_Text1/(&)/g' <old_file>new_file sed -n -e Xp -e Yp FILENAME

Description This will change the first occurance of the OLD_Text on each line to NEW_Text from old_file and write it to new_file

This will change all the occurances of the OLD_Text on each line to NEW_Text from old_file and write it to new_file This will change all the occurances of the OLD_Text on each line to (OLD_Text) from old_file and write it to new_file (pls note that you can put any format for &) This will change all the occurances of the OLD_Text on each line to (OLD_Text) and all the occurances of the OLD_Text on each line to (OLD_Text1) from old_file and write it to new_file (pls note that you can put any format for &) To print the Xth and Yth line of the file

Example

sed 's/mine/me/' </tmp/ss>/tmp/ss

sed 's/mine/me/g' </tmp/ss>/tmp/ss

sed 's/mine/(&)/g' </tmp/ss>/tmp/ss

sed -e 's/mine/(&)/g' -e 's/nine/(&)/g' <old_file>new_file sed -n -e 120p -e 145p -e 1050p /var/log/syslog

Command rpm -ivh rpm -Uvh rpm -e package rpm -ev rpm -ev --nodeps package rpm -qa rpm -q --whatrequires package rpm -qpi vnc-server-4.0-0.beta4.3.2.i386.rpm

Description Install the package Upgrade package Erase/remove/ an installed package Erase/remove/ an installed package Erase/remove/ an installed package without checking for dependencies Display list all installed packages You can see a list of packages that requires the RPM package you're trying to erase by executing: By running the above command all the information about the package will be printed on screen.

Example rpm -ivh mozilla-mail-1.7.5-17.i586.rpm rpm -ivh --test mozilla-mail-1.7.5-17.i586.rpm rpm -Uvh mozilla-mail-1.7.6-12.i586.rpm rpm -Uvh --test mozilla-mail-1.7.6-12.i586.rpm rpm -e mozilla-mail rpm -ev mozilla-mail rpm -ev --nodeps mozilla-mail rpm -qa rpm -q --whatrequires kernel rpm -qpi vnc-server-4.0-0.beta4.3.2.i386.rpm

Command

awk {'print $n'} filename.txt

$ awk 'BEGIN {print "Name\tDesignation\tDepartment\tSalary";} > {print $2,"\t",$3,"\t",$4,"\t",$NF;} > END{print "Report Generated\n--------------"; > }' employee.txt

awk '$2~/xxx/' filename

awk '$1>400' filename $ awk 'BEGIN { count=0;} $4 ~ /Technology/ { count++; } END { print "Number of employees in Technology Dept =",count;}' employee.txt

Description For each record i.e line, it splits the record delimited by whitespace character by default and stores it in the $n variables.If the line has 4 words, it will be stored in $1, $2, $3 and $4. $0 represents whole line. NF is a built in variable which represents total number of fields in a record.

input file is $cat employee.txt 100 Thomas Manager Sales $5,000 200 Jason Developer Technology $5,500 300 Sanjay Sysadmin Technology $7,000 400 Nisha Manager Marketing $9,500 500 Randy DBA Technology $6,000 output is $ awk 'BEGIN {print "Name\tDesignation\tDepartment\tSalary";} > {print $2,"\t",$3,"\t",$4,"\t",$NF;} > END{print "Report Generated\n--------------"; > }' employee.txt Name Designation Department Salary Thomas Manager Sales $5,000 Jason Developer Technology $5,500 Sanjay Sysadmin Technology $7,000 Nisha Manager Marketing $9,500 Randy DBA Technology $6,000 Report Generated --------------

This will compare the variable with $2 with xxxx and print the whole line which matches XXXX

This will compare the variable 1 with the value

Example

1. ps -ef | grep dhcpd | awk {'print $2'} 2. awk {'print $2'} /tmp/sss

awk '$2~/Thomas/' employee.txt the output will be 100 Thomas Sales $5,000

Number of employees in Tehcnology Dept = 3

Command grep word grep "String" grep "String" filename grep -i word grep "startwith.*endwith" filename grep -w word filename grep -A n "string" filename grep -A n "string" filename grep -C n "string" filename export GREP_OPTIONS='--color=auto' GREP_COLOR='100;8' grep -v word grep -e x -e y filename grep -c "string" filename grep -o "is.*line" demo_file grep -n "tech" file name grep -v '#' filename pgrep process name pgrep -l procee name pgrep -u root sshd grep "e$" a_file egrep "x|y" filename egrep "x?" filename fgrep "1000$" filename

Description to check a single word (only substring)- case sensitivity to check continues text string (only substring) - case sensitivity to check continues text string (only substring) in the file to check a single word (only substring) - case insensitivity to check a particular line with matching start word and end word (only substring) to check a single full word - case insensitivity print n lines after the matched string print n lines before the matched string print n lines before and after the matched string This option will need to be executed before executing grep command. This will highlight the matching string in the grep output invert the grep option to check the OR condition of word x, y to check the number lines that match the string to display only the string which matches show the line number while displaying the output to see the lines without any comments to display the process ID (here the process name can be partial) to display the process ID and full process name (here the process name can be partial) will only list the processes called sshd AND owned by root. command will search the file for lines ending with the letter e: to check the OR condition of word x, y to check the substring its simply looks for the exact pattern 1000$ (not for the lines ending with 1000)

Example grep technology grep "technology leads" grep "technology leads" /tmp/sss grep -i technology grep "tech.*how" /tmp/sss grep -w tech /tmp/sss grep -A 5 "tech" /tmp/sss grep -B 5 "tech" /tmp/sss grep -C 5 "tech" /tmp/sss

grep -v tech grep -e 1000 -e "2000" /tmp/sss grep -c "tech" /tmp/sss grep -o "is.*line" /tmp/sss grep -n "tech" /tmp/sss pgrep dhcpd pgrep -l dhc pgrep "1000$" /tmp/sss egrep "1000|2000" /tmp/sss egrep "100?" /tmp/sss

There are several types of signal you can send to terminated a process in Linux. The most commonly used methods are as fol 1. SIGTERM 2. SIGKILL A process can be sent a SIGTERM signal in three ways (the process ID is '1234' in this case): kill 1234 kill -TERM 1234 kill -15 1234 The process can be sent a SIGKILL signal in two ways: kill -KILL 1234 kill -9 1234 the SIGTERM will do clean exit, where as the SIGKILL will do immediate exit without bothering any other processes

Command

killall -9 FULL_process_name

pkill FULL_OR_PARTIAL_process_name

xkill

rocess in Linux. The most commonly used methods are as follows

cess ID is '1234' in this case):

mediate exit without bothering any other processes

Description Instead of specifying a process by its PID, you can specify the name of the process. If more than one process runs with that name, all of them will be killed. But note that the process name should be a full name of the process. It cant be a substring of the process.

You can send signal to any process by specifying the full name or partial name. So there is no need for you to find out the PID of the process to send the signal. xkill is the simplest way to kill a malfunctioning program. When you want to kill a process, initiate xkill which will offer an cross-hair cursor. Click on the window with left cursor which will kill that process

Example

killall -9 dhcpd (not dhc or something like that)

pkill dhc $ xkill Select the window whose client you wish to kill with button 1.... xkill: killing creator of resource 0x1200003

TOP provides an ongoing look at processor activity in real time. It displays a listing of the most CPU-intensive t for manipulating processes. It can sort the tasks by CPU usage, memory usage and runtime. can be better con features can either be selected by an interactive command or by specifying the feature in the personal or syste Command

top -p PID

top and then press o to go for interactive mode

l time. It displays a listing of the most CPU-intensive tasks on the system, and can provide an interactive interface usage, memory usage and runtime. can be better configured than the standard top from the procps suite. Most nd or by specifying the feature in the personal or system-wide configuration file. See below for more information. Description

This will shows the activity of a particular PID

This will a detailed information about sorting. User can press

the system, and can provide an interactive interface han the standard top from the procps suite. Most configuration file. See below for more information. Example

top -p 1022

truncate table table_name; delete from table_name; show engines;

to change the default engine permanently, please add default-storage-engine line under [mysqld] in /etc/my.cnf file

This will delete all the contents of a table same as before but the previous one is much more faster than this to see all the supported and default mysql engine

lease add default-storage-engine line under [mysqld] in /etc/my.cnf file

You might also like