Sie sind auf Seite 1von 97

UNIX / Linux: 7 Practical PS Command Examples for Process Monitoring !

S"SI#"L" on "P$IL %&' &(%%

Process is a running instance of a program) Linux is a multitas*ing operating s!stem' +,ic, means t,at more t,an one process can e acti-e at once) Use ps command to find out +,at processes are running on !our s!stem) .,is article explains 7 practical usages of ps command and its options) .o monitor and control t,e processes' Linux pro-ides lot of commands suc, as ps' *ill' *illall' nice' renice and top commands) %) List Currentl! $unning Processes /ps 0ef' ps 0aux1 Its a commonl! used example +it, a ps command to list do+n all t,e process +,ic, are currentl! running in a mac,ine) .,e follo+ing example s,o+s t,e options of ps command to get all t,e processes) 2 ps 0ef root root root root root &344% &347( 4 ( 5e %( 6 4 ( 5e %( 6 ((:(7:8% 9pdflus,: ((:((:&( 9pdflus,: ((:((:%% ss,d: root<pts/%8

7(788 77;& ( 5e &% 6

7(734 7(788 ( 5e &% pts/%8 ((:((:(& 0 as, 7(7=7 77;& ( 5e &% 6 ((:((:%( ss,d: root<pts/%4

>,ere: 0e to displa! all t,e processes) 0f to displa! full format listing)

In case of ?S@ mac,ines' !ou can use Aps 0auxB +ill gi-e t,e details a out all t,e process as s,o+n a o-e) 2 ps 0aux &) List t,e Process ased on t,e UI@ and Commands /ps 0u' ps 0C1 Use 0u option to displa!s t,e process t,at elongs to a specific username) >,en !ou ,a-e multiple username' separate t,em using a comma) .,e example elo+ displa!s all t,e process t,at are o+ned ! user +++run' or postfix) 2 ps 0f 0u +++run'postfix UI@ PI@ PPI@ C S.IME ..C .IME CM@ ((:((:(( Dmgr 0l 0t fifo 0u ((:((:(( /usr/s in/,ttpd&0prefor* 0f ((:((:(( /usr/s in/,ttpd&0prefor* 0f ((:((:(( /usr/s in/,ttpd&0prefor* 0f ((:((:(( /usr/s in/,ttpd&0prefor* 0f ((:((:(( /usr/s in/,ttpd&0prefor* 0f ((:((:(( /usr/s in/,ttpd&0prefor* 0f ((:((:(( /usr/s in/,ttpd&0prefor* 0f ((:((:(( pic*up 0l 0t fifo 0u

postfix 7847 7874 ( Mar(= 6 +++run 78=4 78=% ( Mar(= 6 /etc/apac,e&/,ttpd)conf +++run 78=3 78=% ( Mar(= 6 /etc/apac,e&/,ttpd)conf +++run 78=7 78=% ( Mar(= 6 /etc/apac,e&/,ttpd)conf +++run 78=; 78=% ( Mar(= 6 /etc/apac,e&/,ttpd)conf +++run 78== 78=% ( Mar(= 6 /etc/apac,e&/,ttpd)conf +++run %((7; 78=% ( Mar(= 6 /etc/apac,e&/,ttpd)conf +++run %((;& 78=% ( Mar(= 6 /etc/apac,e&/,ttpd)conf postfix %4377 7874 ( &&:&7 6

Eften ps is used +it, grep li*e Fps 0aux G grep commandH to get t,e list of process +it, t,e gi-en command) ?ut ps command itself ,as an option to ac,ie-e t,e same) .,e follo+ing example s,o+s t,at all t,e processes +,ic, ,as tatad)pl in its command execution) 2 ps 0f 0C tatad)pl UI@ PI@ PPI@ C S.IME ..C .IME CM@

root root root root root root root

=473

% ( Mar(= 6

((:((:(( /opt/tata/perl/ in/perl /opt/tata/ in/tatad)pl ((:((:(( /opt/tata/perl/ in/perl /opt/tata/ in/tatad)pl ((:((:(( /opt/tata/perl/ in/perl /opt/tata/ in/tatad)pl ((:((:(( /opt/tata/perl/ in/perl /opt/tata/ in/tatad)pl ((:((:(( /opt/tata/perl/ in/perl /opt/tata/ in/tatad)pl ((:((:(( /opt/tata/perl/ in/perl /opt/tata/ in/tatad)pl ((:((:(( /opt/tata/perl/ in/perl /opt/tata/ in/tatad)pl

=477 =473 ( Mar(= 6 =47= =473 ( Mar(= 6 =4;( =473 ( Mar(= 6 =4;% =473 ( Mar(= 6 =4;& =473 ( Mar(= 6 %&%77 =473 ( Mar(= 6

Note: >e can create aliases for ps command to list processes ased on commands' users or groups) 7) List t,e processes ased on PI@s or PPI@s /ps 0p' ps Ippid1 Eac, process +ill e assigned +it, t,e uniDue Process I@ /PI@1) >,en !ou launc, some application' it mig,t for* num er of processes and eac, su process +ill ,a-e its o+n PI@) So' eac, process +ill ,a-e its o+n process id and parent processid) 5or all t,e processes t,at a process for*s +ill ,a-e t,e same PPI@ /parent process identifier1) .,e follo+ing met,od is used to get a list of processes +it, a particular PPI@) 2 ps 0f 00ppid =473 UI@ root root root root root root PI@ PPI@ C S.IME ..C =477 =473 ( Mar(= 6 =47= =473 ( Mar(= 6 =4;( =473 ( Mar(= 6 =4;% =473 ( Mar(= 6 =4;& =473 ( Mar(= 6 %&%77 =473 ( Mar(= 6 .IME CM@ ((:((:(( /opt/tata/perl/ in/perl /opt/tata/ in/tatad)pl ((:((:(( /opt/tata/perl/ in/perl /opt/tata/ in/tatad)pl ((:((:(( /opt/tata/perl/ in/perl /opt/tata/ in/tatad)pl ((:((:(( /opt/tata/perl/ in/perl /opt/tata/ in/tatad)pl ((:((:(( /opt/tata/perl/ in/perl /opt/tata/ in/tatad)pl ((:((:(( /opt/tata/perl/ in/perl /opt/tata/ in/tatad)pl

.,e follo+ing example is to list t,e processes +,ic, ,as gi-en PI@) 2 ps 0f 0p &4((='7&4;'&8&3 UI@ root root PI@ PPI@ C S.IME ..C &8&3 7&4; 8 ( Mar(= 6 % ( Mar(= 6 .IME CM@

((:((:(( 9reiserfs/(: ((:((:(( /usr/s in/nscd

postfix &4((= 7874 ( ((:(& 6

((:((:(( pic*up 0l 0t fifo 0u

8) List Processes in a Jierarc,! /ps Iforest1 .,e example elo+ displa! t,e process Id and commands in a ,ierarc,!) Iforest is an argument to ps command +,ic, displa!s "SCII art of process tree) 5rom t,is tree' +e can identif! +,ic, is t,e parent process and t,e c,ild processes it for*ed in a recursi-e manner) 2 ps 0e 0o pid'args 00forest 83; KL ss,d: root<pts/7 4%8 G KL 0 as, %78;8 KL ss,d: root<pts/%% %74%7 G KL 0 as, &8((8 G KL -i )/7=(7%(LL%%%%7/Mournal

%44%7 KL ss,d: root<pts/% %44&& G KL 0 as, 8&;( KL ss,d: root<pts/4 87(& G KL 0 as, Note: Cou can also use tree and pstree command to displa!s process in a nice tree structure) 4) List elapsed +all time for processes /ps 0o pid'etimeN1 If !ou +ant t,e get t,e elapsed time for t,e processes +,ic, are currentl! running ps command pro-ides etime +,ic, pro-ides t,e elapsed time since t,e process +as started' in t,e form 99dd0:,,::mm:ss) .,e elo+ command displa!s t,e elapsed time for t,e process I@s % /init1 and process id &=374) 5or example F%(0&&:%7:&=O in t,e output represents t,e process init is running for %(da!s' &&,ours'%7 minutes and &=seconds) Since init process starts during t,e s!stem startup' t,is time +ill e same as t,e output of t,e AuptimeB command) P ps 0p %'&=374 0o pid'etimeN PI@ % %(0&&:%7:&= &=374 %0(&:4;:83

3) List all t,reads for a particular process /ps 0L1 Cou can get a list of t,reads for t,e processes) >,en a process ,angs' +e mig,t need to identif! t,e list of t,reads running for a particular process as s,o+n elo+) 2 ps 0C Ma-a 0L 0o pid'tid'pcpu'state'nl+p'args PI@ .I@ QCPU S NL>P CEMM"N@ %3==& %3==& ()( S %4 ))/Mre/ in/Ma-a 0@Ma-a)ext)dirsN))/Mre/li /ext:))/li :))/autoLli 0Xde ug 0Xnoagent 0@Ma-a)compilerNNENE 0XrunMd+p:transportNdtLsoc*et'ser-erN!'suspendNn'addressN4((3 %3==& %3==7 ()( S %4 ))/Mre/ in/Ma-a 0@Ma-a)ext)dirsN))/Mre/li /ext:))/li :))/autoLli 0Xde ug 0Xnoagent 0@Ma-a)compilerNNENE 0XrunMd+p:transportNdtLsoc*et'ser-erN!'suspendNn'addressN4((3 %3==& %3==8 ()( S %4 ))/Mre/ in/Ma-a 0@Ma-a)ext)dirsN))/Mre/li /ext:))/li :))/autoLli 0Xde ug 0Xnoagent 0@Ma-a)compilerNNENE 0XrunMd+p:transportNdtLsoc*et'ser-erN!'suspendNn'addressN4((3 %3==& %3==4 ()( S %4 ))/Mre/ in/Ma-a 0@Ma-a)ext)dirsN))/Mre/li /ext:))/li :))/autoLli 0Xde ug 0Xnoagent 0@Ma-a)compilerNNENE 0XrunMd+p:transportNdtLsoc*et'ser-erN!'suspendNn'addressN4((3 %3==& %3==3 ()( S %4 ))/Mre/ in/Ma-a 0@Ma-a)ext)dirsN))/Mre/li /ext:))/li :))/autoLli 0Xde ug 0Xnoagent 0@Ma-a)compilerNNENE 0XrunMd+p:transportNdtLsoc*et'ser-erN!'suspendNn'addressN4((3 %3==& %3==7 ()( S %4 ))/Mre/ in/Ma-a 0@Ma-a)ext)dirsN))/Mre/li /ext:))/li :))/autoLli 0Xde ug 0Xnoagent 0@Ma-a)compilerNNENE 0XrunMd+p:transportNdtLsoc*et'ser-erN!'suspendNn'addressN4((3 %3==& %3==; ()( S %4 ))/Mre/ in/Ma-a 0@Ma-a)ext)dirsN))/Mre/li /ext:))/li :))/autoLli 0Xde ug 0Xnoagent 0@Ma-a)compilerNNENE 0XrunMd+p:transportNdtLsoc*et'ser-erN!'suspendNn'addressN4((3 %3==& %3=== ()( S %4 ))/Mre/ in/Ma-a 0@Ma-a)ext)dirsN))/Mre/li /ext:))/li :))/autoLli 0Xde ug 0Xnoagent 0@Ma-a)compilerNNENE 0XrunMd+p:transportNdtLsoc*et'ser-erN!'suspendNn'addressN4((3 %3==& %7((( ()( S %4 ))/Mre/ in/Ma-a 0@Ma-a)ext)dirsN))/Mre/li /ext:))/li :))/autoLli 0Xde ug 0Xnoagent 0@Ma-a)compilerNNENE 0XrunMd+p:transportNdtLsoc*et'ser-erN!'suspendNn'addressN4((3 %3==& %7((% ()( S %4 ))/Mre/ in/Ma-a 0@Ma-a)ext)dirsN))/Mre/li /ext:))/li :))/autoLli 0Xde ug 0Xnoagent 0@Ma-a)compilerNNENE 0XrunMd+p:transportNdtLsoc*et'ser-erN!'suspendNn'addressN4((3

%3==& %7((& ()( S %4 ))/Mre/ in/Ma-a 0@Ma-a)ext)dirsN))/Mre/li /ext:))/li :))/autoLli 0Xde ug 0Xnoagent 0@Ma-a)compilerNNENE 0XrunMd+p:transportNdtLsoc*et'ser-erN!'suspendNn'addressN4((3 %3==& %7((7 ()( S %4 ))/Mre/ in/Ma-a 0@Ma-a)ext)dirsN))/Mre/li /ext:))/li :))/autoLli 0Xde ug 0Xnoagent 0@Ma-a)compilerNNENE 0XrunMd+p:transportNdtLsoc*et'ser-erN!'suspendNn'addressN4((3 %3==& %7(&8 ()( S %4 ))/Mre/ in/Ma-a 0@Ma-a)ext)dirsN))/Mre/li /ext:))/li :))/autoLli 0Xde ug 0Xnoagent 0@Ma-a)compilerNNENE 0XrunMd+p:transportNdtLsoc*et'ser-erN!'suspendNn'addressN4((3 %3==& %4747 ()( S %4 ))/Mre/ in/Ma-a 0@Ma-a)ext)dirsN))/Mre/li /ext:))/li :))/autoLli 0Xde ug 0Xnoagent 0@Ma-a)compilerNNENE 0XrunMd+p:transportNdtLsoc*et'ser-erN!'suspendNn'addressN4((3 %3==& %4748 ()( S %4 ))/Mre/ in/Ma-a 0@Ma-a)ext)dirsN))/Mre/li /ext:))/li :))/autoLli 0Xde ug 0Xnoagent 0@Ma-a)compilerNNENE 0XrunMd+p:transportNdtLsoc*et'ser-erN!'suspendNn'addressN4((3 0L option is used to displa! t,e list of t,reads for a process +,ic, ,as t,e command gi-en) "nd it also displa!s nl+p' +,ic, represents num er of lig,t +eig,t processes) In t,e a o-e example' a total of %4 Ma-a t,reads are running) 7) 5inding memor! Lea* /ps Isort pmem1 " memor! lea*' tec,nicall!' is an e-er0increasing usage of memor! ! an application) >it, common des*top applications' t,is ma! go unnoticed' ecause a process t!picall! frees an! memor! it ,as used +,en !ou close t,e application) Jo+e-er' In t,e client/ser-er model' memor! lea*age is a serious issue' ecause applications are expected to e a-aila le &8R7) "pplications must not continue to increase t,eir memor! usage indefinitel!' ecause t,is can cause serious issues) .o monitor suc, memor! lea*s' +e can use t,e follo+ing commands) 2 ps aux 00sort pmem

USE$ root

PI@ QCPU QMEM SST $SS ..C % ()( ()( %4&( 4(; 6 S S S S

S.". S."$. .IME CEMM"N@

&((4 %:&7 init &((4 %:44 agnt /idle1 &((4 &(:(& agnt /idle1 &((4 %4:84 agnt /idle1

inst %7(= ()( ()8 7887(; 77(8; 6 inst &=%= ()( ()8 7844;( 7773; 6 inst &84=8 ()( ()8 784(3; 73=3( 6

root &7384 ()( %8)8 %&7%&;; %%;7=73 6 S 7&

&((4 7:(% /.as*Ser-er/ in/)/+rapper0linux0x;30

In t,e a o-e ps command' Isort option outputs t,e ,ig,est QMEM at ottom) Uust note do+n t,e PI@ for t,e ,ig,est QMEM usage) .,en use ps command to -ie+ all t,e details a out t,is process id' and monitor t,e c,ange o-er time) Cou ,ad to manuall! repeat ir or put it as a cron to a file) 2 ps e- 00pidN&7384 PI@ ..C S.". .IME M"U5L .$S @$S $SS QMEM CEMM"N@ &7384 6 S 7:(% ( &4 %&7%&3& %%;7=73 %8)8 /.as*Ser-er/ in/)/+rapper0linux0x;307&

2 ps e- 00pidN&7384 PI@ ..C S.". .IME M"U5L .$S @$S $SS QMEM CEMM"N@ &7384 6 S 7:(% ( &4 %&7%&3& %%;7=73 %8)8 /.as*Ser-er/ in/)/+rapper0linux0x;307& Note: In t,e a o-e output' if $SS /resident set siVe' in #?1 increases o-er time /so +ould QMEM1' it ma! indicate a memor! lea* in t,e application)

S+itc,e of ps : SIMPLE P$ECESS SELEC.IEN S+itc, 0" 0N 0a 0d 0e . a g r x @escription select all processes negate selection select all +it, a tt! except session leaders select all' ut omit session leaders select all processes select all processes on t,is terminal select all processes on a terminal' including t,ose of ot,er users reall! all' e-en group leaders /does not,ing +/o SunES settings1 restrict output to running processes select processes +it,out controlling tt!s

00 negate selection deselect P$ECESS SELEC.IEN ?C LIS. S+itc, @escription 0C 0W 0U 0g 0p 0s 0t 0u U p t select ! command name select ! $WI@ /supports names1 select ! $UI@ /supports names1 select ! session leader E$ ! group name select ! PI@ select processes elonging to t,e sessions gi-en select ! tt! select ! effecti-e user I@ /supports names1 select processes for specified users select ! process I@ select ! tt!

00 select ! real group name or I@ Wroup 00User select ! real user name or I@ 00group select ! effecti-e group name or I@ 00pid 00sid 00tt! select ! process I@ select ! session I@ select ! terminal

00user select ! effecti-e user name or I@ 0%&7 %&7 implied 00sid implied 00pid

EU.PU. 5E$M". CEN.$EL S+itc, @escription 0E is preloaded X0oX

0c 0f 0M 0l 0o 0! E X M l o s u -

different sc,eduler info for 0l option does full listing Mo s format long format user0defined format do not s,o+ flagsY s,o+ rss in place of addr is preloaded XoX /o-erloaded1 old Linux i7;3 register format Mo control format displa! long format specif! user0defined format displa! signal format displa! user0oriented format displa! -irtual memor! format

00format user0defined format EU.PU. ME@I5IE$S S+itc, 0J 0m 0n 0+ C N E S c e @escription s,o+ process ,ierarc,! /forest1 s,o+ all t,reads set namelist file +ide output use ra+ CPU time for QCPU instead of deca!ing a-erage specif! namelist file sorting order /o-erloaded1 include some dead c,ild process data /as a sum +it, t,e parent1 true command name s,o+ en-ironment after t,e command

f , m n + 00cols 00columns

"SCII0art process ,ierarc,! /forest1 do not print ,eader lines /repeat ,eader lines in ?S@ personalit!1 all t,reads numeric output for >CJ"N and USE$ +ide output set screen +idt, set screen +idt,

00 include some dead c,ild process data /as a sum +it, t,e cumulati-e parent1 00forest 00,tml 00,eaders 00no0 ,eaders 00lines 00nul 00null 00ro+s 00sort 00+idt, 00Vero "SCII art process tree J.ML escaped output repeat ,eader lines print no ,eader line at all set screen ,eig,t unMustified output +it, NULs unMustified output +it, NULs set screen ,eig,t specif! sorting order set screen +idt, unMustified output +it, NULs

IN5E$M".IEN S+itc, @escription 0S L S 00,elp 00info print -ersion list all format specifiers s,o+ -ersion info print ,elp message print de ugging info

00 print -ersion -ersion E?SELE.E S+itc @escription , " M > * increase t,e argument space /@ecUnix1 use alternate core /tr! 0n or N instead1 get s+ap info from ))) not /de-/drum /tr! 0n or N instead1 use /-mcore as c0dumpfile /tr! 0n or N instead1

ZZZZZZZZZZZZZZZZZZZZZZZZZZZZ))

%( Linux @U Command Examples /5iles and 5olders @is* Usage SiVe1 ! JIM"NSJU "$E$" on UUNE &7' &(%& @u stands for @is* Usage) Linux du command is used for summariVing t,e dis* usage in terms of file siVe) It can e used +it, folders to get t,e total dis* usage) .,is article pro-ides some examples on ,o+ to use du command effecti-el!) "ll t,e du examples s,o+n ,ere are executed on a director! containing t,e follo+ing contents: 2 ls linux#ernel red,at testfile)txt u untu %) " asic example 2 du 0a ( 8 8 ( )/red,at/r,7 )/red,at )/testfile)txt )/linux#ernel

( 8 %3

)/u untu/u %( )/u untu )

I ,a-e used t,e 0a flag in t,e example a o-e to s,o+ t,e dis* usage of all t,e files and directories) Its ecause if 0a is not used t,en onl! directories t,at are occup!ing some dis* are listed) 5or example : 2 du 8 8 %3 )/red,at )/u untu )

So' no+ +e get a asic idea a out ,o+ to use du command ut as +it, me' an!one +ould find it ,ard to understand +,at t,ose num ers in t,e output mean66 Lets mo-e on to next examples and t,e clouds +ill clear off) &) @ispla! output in ,uman reada le form using 0, 2 du 0a, ( 8)(# 8)(# ( ( 8)(# %3# )/red,at/r,7 )/red,at )/testfile)txt )/linux#ernel )/u untu/u %( )/u untu )

So +e see t,at in t,e a o-e example' I used t,e 0, flag along +it, t,e 0a flag) .,e 0, flag is used to get t,e output in t,e ,uman reada le format) "s !ou can see t,at a o-e output is more eas! to understand as dis* usage is listed in terms of A#B) 7) @ispla! grand total in t,e output using 0c .,e example t,at I am using ,as a small director! structure) Ene could easil! calculate t,e total dis* usage of t,e director! ! calculating manuall!) ?ut' in real time scenario manual calculation is not practical) So' t,ere exists a flag t,roug, +,ic, one can get t,e total usage in t,e output) 2 du 0a,c

( 8)(# 8)(# ( ( 8)(# %3# %3#

)/red,at/r,7 )/red,at )/testfile)txt )/linux#ernel )/u untu/u %( )/u untu ) total

So +e see t,at t,roug, t,e 0c flag' one can get t,e total usage in t,e output) 8) @ispla! onl! t,e total count using 0s If !ou +is, to fetc, onl! t,e total siVe in form of a summar!' use t,e 0s flag) 2 du 0s, 7)7W )

So +e see t,at onl! t,e total siVe +as displa!ed in t,e output a o-e) 4) 5eed input files from stdin using AIfiles(0fromN0B If t,ere arises a situation +,erein !ou +ant to pro-ide AduB input on t,e go' t,en t,is is possi le t,roug, t,e AIfiles(0fromB flag) 2 du 0a, 00files(0fromN0 cop!%&# file%&# file ,ello>orld%&#,ello>orld [C 2 Note t,at +e passed -alue as A0B to t,e flag AIfiles(0fromB in order to indicate AduB to start accepting t,e file names from stdin) "fter entering eac, file name press ctrl\@ t+ice in order to produce t,e output for t,at file) 3) End t,e output +it, null !te using 0( cop!

If !ou +is, to produce eac, output ending +it,out a ne+line ut +it, a null !te instead t,en use t,e 0( flag) 2 du 0am 0( ( u% )/red,at/r,7% )/red,at% )/testfile)txt( )/linux#ernel( )/u untu/u %(% )/u unt

So +e see t,at t,e output a o-e +as produced in a single line as eac, output +as terminated +it, a ( !te) 7) CustomiVe t,e loc* siVe in output t,roug, I loc*0siVe .al*ing of loc* siVe' some times it is reDuired to ,a-e output in a different +a!) 5or example : 2 du 0ac ( 8 8 ( ( 8 %3 %3 )/red,at/r,7 )/red,at )/testfile)txt )/linux#ernel )/u untu/u %( )/u untu ) total

.,e a o-e output is represented in terms of num er of %(&8 !tes loc*s) No+ suppose if +e reDuire t,e output to e in num er of &(8; !tes loc*' t,en in t,is case t,e flag AI loc*0siVeB can e used) 2 du 0a,c 00 loc*0siVeN&(8; ( & & ( ( & )/red,at/r,7 )/red,at )/testfile)txt )/linux#ernel )/u untu/u %( )/u untu

; ;

) total

So +e see t,at t,e a o-e output is in t,e form of num er of &(8; !tes loc*s) ;) @ispla! output in !tes using 0 .o get t,e output in terms of !tes' t,e 0 flag can e used) 2 du 0ac, ( 8(=3 7 ( ( 8(=3 )/red,at/r,7 )/red,at )/testfile)txt )/linux#ernel )/u untu/u %( )/u untu

%&&=% ) %&&=% total So +e see t,at t,e a o-e output is in terms of !tes) =) Exclude particular t!pes of file/s1 using Iexclude Suppose +e do not +ant to ,a-e t,e statistics of )txt files) So for t,ese t!pes of reDuirements t,ere is a AIexcludeB flag) 2 du 0c ,a 00excludeNX])txtX ( 8)(# ( ( 8)(# %&# %&# )/red,at/r,7 )/red,at )/linux#ernel )/u untu/u %( )/u untu ) total

So +e see t,at in t,e output a o-e' t,e text file entr! +as not t,ere)

%() @ispla! t,e modification time and customiVe t,e displa! st!le .,is can e ac,ie-ed t,roug, Itime and Itime0st!le flags) 2 du 0c ,a 00time ( 8)(# 7 ( ( 8)(# %7# %7# &(%&0(40&& &%:4& &(%&0(40&& &%:4& &(%&0(30%; %=:&7 &(%&0(40&& &%:4& &(%&0(40&& &%:4& &(%&0(40&& &%:4& &(%&0(30%; %=:&7 &(%&0(30%; %=:&7 )/red,at/r,7 )/red,at )/testfile)txt )/linux#ernel )/u untu/u %( )/u untu ) total

2 du 0c ,a 00time 00time0st!leNiso ( 8)(# 7 ( ( 8)(# %7# %7# &(%&0(40&& &(%&0(40&& &(%&0(30%; &(%&0(40&& &(%&0(40&& &(%&0(40&& &(%&0(30%; &(%&0(30%; )/red,at/r,7 )/red,at )/testfile)txt )/linux#ernel )/u untu/u %( )/u untu ) total

5or Itime0st!le' !ou can also use full0iso' long0iso' iso)

S+itc,es: du ta*es a single argument' specif!ing a pat,name for du to +or*Y if it is not specified' t,e current director! is used) .,e SUS mandates for du t,e follo+ing options: 0a' displa! an entr! for eac, file /and not director!1 contained in t,e current director! 0c' displa! a grand total of t,e dis* usage found ! t,e ot,er arguments

0d P' t,e dept, at +,ic, summing s,ould occur) 0d ( sums at t,e current le-el' 0d % sums at t,e su director!' 0d & at su 0su directories' etc) 0J' calculate dis* usage for lin* references specified on t,e command line 0*' s,o+ siVes as multiples of %(&8 !tes' not 4%&0 !te 0L' calculate dis* usage for lin* references an!+,ere 0s' report onl! t,e sum of t,e usage in t,e current director!' not for eac, file 0x' onl! tra-erse files and directories on t,e de-ice on +,ic, t,e pat,name argument is specified) Et,er Unix and Unix0li*e operating s!stems ma! add extra options) 5or example' ?S@ and WNU duspecif! a 0, option' displa!ing dis* usage in a format easier to read ! t,e user' adding units +it, t,e appropriate SI prefix /e)g) %( M?1)) Eptions 0a' 00all 00apparent0siVe +rite counts for all files' not Must directories)

print apparent siVes' rat,er t,an dis* usageY alt,oug, t,e apparent siVe is usuall! smaller' i ma! e larger due to ,oles in /^sparse^1 files' internal fragmentation' indirect loc*s' and t,e li*e) scale siVes ! SITE efore printing t,em) 5or example' ^0?M^ prints siVes in units of %'(8;'473 !tes) /See SITE format elo+1) eDui-alent to ^00apparent0siVe 00 loc*0siVeN%^ displa! a grand total) dereference onl! s!mlin*s t,at are listed on t,e command line)

0?' 00 loc*0 siVeNSITE 0 ' 00 !tes 0c' 00total 0@' 00dereference0 args 00files(0fromN5

summariVe dis* usage of t,e NUL0terminated file namesspecified in file 5Y If 5 is X0X t,en rea names from standard input) eDui-alent to 00dereference0args /0@1) print siVes in ,uman reada le format' rounding -alues and using a

0J 0,' 00,uman0

re-iations) 5or exampl

reada le 00si 0* 0l' 00count0lin*s 0m 0L' 00dereference 0P' 00no0 dereference 0(' 00null 0S' 00separate0dirs 0s' 00summariVe 0x' 00one0file0 s!stem 0X' 00exclude0 fromN5ILE 00 excludeNP"..E$ N

X%#X' X&78MX' X&WX' etc) li*e 0,' ut use po+ers of %(((' not %(&8) li*e 00 loc*0siVeN%#) count siVes man! times if ,ard0lin*ed) li*e 00 loc*0siVeN%M) dereference all s!m olic lin*s) don^t follo+ an! s!m olic lin*s /t,is is t,e default1)

end eac, output line +it, ( !te rat,er t,an ne+line) do not include siVe of su directories) displa! onl! a total for eac, argument) s*ip directories on different file s!stems)

exclude files t,at matc, an! pattern in 5ILE

exclude files t,at matc, P"..E$N)

0d' 00max0dept,NN print t,e total for a director! /or file' +it, 00all1 onl! if it is N or fe+er le-els elo+ t,e command line argumentY 00max0dept,N(is t,e same as 00summariVe) 00time s,o+ time of t,e last modification of an! file in t,e director!' or an! of its su directories)

00timeN>E$@ 00time0 st!leNS.CLE 00,elp 00-ersion

s,o+ time as >E$@ instead of modification time: atime'access' use' ctime or status)

s,o+ times using st!le S.CLE: full0iso' long0iso' iso' or\5E$M".) /5E$M". is interpreted li*e t,e format of ^date^)1 displa! a ,elp message and exit) output -ersion information and exit)

ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ Cou s,ould get a grip on t,e Linux grep command) .,is is part of t,e on0going %4 Examples series' +,ere %4 detailed examples +ill e pro-ided for a specific command or functionalit!) Earlier +e discussed %4 practical examples for Linux find command' Linuxcommand line ,istor! and m!sDladmin command)

In t,is article let us re-ie+ %4 practical examples of Linux grep command t,at +ill e -er! useful to ot, ne+ ies and experts)

5irst create t,e follo+ing demoLfile t,at +ill e used in t,e examples elo+ to demonstrate grep command) 2 cat demoLfile .JIS LINE IS .JE %S. UPPE$ C"SE LINE IN .JIS 5ILE) t,is line is t,e %st lo+er case line in t,is file) .,is Line Jas "ll Its 5irst C,aracter Ef .,e >ord >it, Upper Case)

.+o lines a o-e t,is line is empt!) "nd t,is is t,e last line)

%) Searc, for t,e gi-en string in a single file .,e asic usage of grep command is to searc, for a specific string in t,e specified file as s,o+n elo+) S!ntax: grep XliteralLstringX filename 2 grep Xt,isX demoLfile t,is line is t,e %st lo+er case line in t,is file) .+o lines a o-e t,is line is empt!) &) C,ec*ing for t,e gi-en string in multiple files) S!ntax: grep XstringX 5ILELP"..E$N .,is is also a asic usage of grep command) 5or t,is example' let us cop! t,e demoLfile to demoLfile%) .,e grep output +ill also include t,e file name in front of t,e line t,at matc,ed t,e specific pattern as s,o+n elo+) >,en t,e Linux s,ell sees t,e meta c,aracter' it does t,e expansion and gi-es all t,e files as input to grep) 2 cp demoLfile demoLfile%

2 grep Xt,isX demoL] demoLfile:t,is line is t,e %st lo+er case line in t,is file) demoLfile:.+o lines a o-e t,is line is empt!) demoLfile:"nd t,is is t,e last line) demoLfile%:t,is line is t,e %st lo+er case line in t,is file) demoLfile%:.+o lines a o-e t,is line is empt!) demoLfile%:"nd t,is is t,e last line) 7) Case insensiti-e searc, using grep 0i S!ntax: grep 0i XstringX 5ILE

.,is is also a asic usage of t,e grep) .,is searc,es for t,e gi-en string/pattern case insensiti-el!) So it matc,es all t,e +ords suc, as Ft,eH' F.JEH and F.,eH case insensiti-el! as s,o+n elo+) 2 grep 0i Xt,eX demoLfile .JIS LINE IS .JE %S. UPPE$ C"SE LINE IN .JIS 5ILE) t,is line is t,e %st lo+er case line in t,is file) .,is Line Jas "ll Its 5irst C,aracter Ef .,e >ord >it, Upper Case) "nd t,is is t,e last line) 8) Matc, regular expression in files S!ntax: grep X$EWEXX filename .,is is a -er! po+erful feature' if !ou can use use regular expression effecti-el!) In t,e follo+ing example' it searc,es for all t,e pattern t,at starts +it, FlinesH and ends +it, Fempt!H +it, an!t,ing in0 et+een) i)e .o searc, Flines9an!t,ing in0 et+een:empt!H in t,e demoLfile) 2 grep Xlines)]empt!X demoLfile .+o lines a o-e t,is line is empt!) 5rom documentation of grep: " regular expression ma! e follo+ed ! one of se-eral repetition operators: 6 .,e preceding item is optional and matc,ed at most once) ] .,e preceding item +ill e matc,ed Vero or more times) \ .,e preceding item +ill e matc,ed one or more times) _n` .,e preceding item is matc,ed exactl! n times) _n'` .,e preceding item is matc,ed n or more times) _'m` .,e preceding item is matc,ed at most m times) _n'm` .,e preceding item is matc,ed at least n times' ut not more t,an m times) 4) C,ec*ing for full +ords' not for su 0strings using grep 0+ If !ou +ant to searc, for a +ord' and to a-oid it to matc, t,e su strings use 0+ option) Uust doing out a normal searc, +ill s,o+ out all t,e lines)

.,e follo+ing example is t,e regular grep +,ere it is searc,ing for FisH) >,en !ou searc, for FisH' +it,out an! option it +ill s,o+ out FisH' F,isH' Ft,isH and e-er!t,ing +,ic, ,as t,e su string FisH) 2 grep 0i XisX demoLfile .JIS LINE IS .JE %S. UPPE$ C"SE LINE IN .JIS 5ILE) t,is line is t,e %st lo+er case line in t,is file) .,is Line Jas "ll Its 5irst C,aracter Ef .,e >ord >it, Upper Case) .+o lines a o-e t,is line is empt!) "nd t,is is t,e last line) .,e follo+ing example is t,e >E$@ grep +,ere it is searc,ing onl! for t,e +ord FisH) Please note t,at t,is output does not contain t,e line F.,is Line Jas "ll Its 5irst C,aracter Ef .,e >ord >it, Upper CaseH' e-en t,oug, FisH is t,ere in t,e F.,isH' as t,e follo+ing is loo*ing onl! for t,e +ord FisH and not for Ft,isH) 2 grep 0i+ XisX demoLfile .JIS LINE IS .JE %S. UPPE$ C"SE LINE IN .JIS 5ILE) t,is line is t,e %st lo+er case line in t,is file) .+o lines a o-e t,is line is empt!) "nd t,is is t,e last line) 3) @ispla!ing lines efore/after/around t,e matc, using grep 0"' 0? and 0C >,en doing a grep on a ,uge file' it ma! e useful to see some lines after t,e matc,) Cou mig,t feel ,and! if grep can s,o+ !ou not onl! t,e matc,ing lines ut also t,e lines after/ efore/around t,e matc,) Please create t,e follo+ing demoLtext file for t,is example) 2 cat demoLtext 8) Sim >ord Na-igation

Cou ma! +ant to do se-eral na-igation in relation to t,e +ords' suc, as:

] e 0 go to t,e end of t,e current +ord) ] E 0 go to t,e end of t,e current >E$@) ] 0 go to t,e pre-ious / efore1 +ord)

] ? 0 go to t,e pre-ious / efore1 >E$@) ] + 0 go to t,e next +ord) ] > 0 go to t,e next >E$@)

>E$@ 0 >E$@ consists of a seDuence of non0 lan* c,aracters' separated +it, +,ite space) +ord 0 +ord consists of a seDuence of letters' digits and underscores)

Example to s,o+ t,e difference et+een >E$@ and +ord

] %=&)%3;)%)% 0 single >E$@ ] %=&)%3;)%)% 0 se-en +ords) 3)% @ispla! N lines after matc, 0" is t,e option +,ic, prints t,e specified N lines after t,e matc, as s,o+n elo+) S!ntax: grep 0" aNb XstringX 5ILEN"ME .,e follo+ing example prints t,e matc,ed line' along +it, t,e 7 lines after it) 2 grep 0" 7 0i XexampleX demoLtext Example to s,o+ t,e difference et+een >E$@ and +ord

] %=&)%3;)%)% 0 single >E$@ ] %=&)%3;)%)% 0 se-en +ords) 3)& @ispla! N lines efore matc, 0? is t,e option +,ic, prints t,e specified N lines efore t,e matc,)

S!ntax: grep 0? aNb XstringX 5ILEN"ME >,en !ou ,ad option to s,o+ t,e N lines after matc,' !ou ,a-e t,e 0? option for t,e opposite) 2 grep 0? & Xsingle >E$@X demoLtext Example to s,o+ t,e difference et+een >E$@ and +ord

] %=&)%3;)%)% 0 single >E$@ 3)7 @ispla! N lines around matc, 0C is t,e option +,ic, prints t,e specified N lines efore t,e matc,) In some occasion !ou mig,t +ant t,e matc, to e appeared +it, t,e lines from ot, t,e side) .,is options s,o+s N lines in ot, t,e side/ efore c after1 of matc,) 2 grep 0C & XExampleX demoLtext +ord 0 +ord consists of a seDuence of letters' digits and underscores)

Example to s,o+ t,e difference et+een >E$@ and +ord

] %=&)%3;)%)% 0 single >E$@ 7) Jig,lig,ting t,e searc, using W$EPLEP.IENS "s grep prints out lines from t,e file ! t,e pattern / string !ou ,ad gi-en' if !ou +anted it to ,ig,lig,t +,ic, part matc,es t,e line' t,en !ou need to follo+ t,e follo+ing +a!) >,en !ou do t,e follo+ing export !ou +ill get t,e ,ig,lig,ting of t,e matc,ed searc,es) In t,e follo+ing example' it +ill ,ig,lig,t all t,e t,is +,en !ou set t,e W$EPLEP.IENS en-ironment -aria le as s,o+n elo+) 2 export W$EPLEP.IENSN^00colorNauto^ W$EPLCELE$N^%((Y;^

2 grep t,is demoLfile t,is line is t,e %st lo+er case line in t,is file) .+o lines a o-e t,is line is empt!)

"nd t,is is t,e last line) ;) Searc,ing in all files recursi-el! using grep 0r >,en !ou +ant to searc, in all t,e files under t,e current director! and its su director!) 0r option is t,e one +,ic, !ou need to use) .,e follo+ing example +ill loo* for t,e string Frames,H in all t,e files in t,e current director! and all itBs su director!) 2 grep 0r Xrames,X ] =) In-ert matc, using grep 0Cou ,ad different options to s,o+ t,e lines matc,ed' to s,o+ t,e lines efore matc,' and to s,o+ t,e lines after matc,' and to ,ig,lig,t matc,) So definitel! CouBd also +ant t,e option 0- to do in-ert matc,) >,en !ou +ant to displa! t,e lines +,ic, does not matc,es t,e gi-en string/pattern' use t,e option 0- as s,o+n elo+) .,is example +ill displa! all t,e lines t,at did not matc, t,e +ord FgoH) 2 grep 0- XgoX demoLtext 8) Sim >ord Na-igation

Cou ma! +ant to do se-eral na-igation in relation to t,e +ords' suc, as:

>E$@ 0 >E$@ consists of a seDuence of non0 lan* c,aracters' separated +it, +,ite space) +ord 0 +ord consists of a seDuence of letters' digits and underscores)

Example to s,o+ t,e difference et+een >E$@ and +ord

] %=&)%3;)%)% 0 single >E$@ ] %=&)%3;)%)% 0 se-en +ords) %() displa! t,e lines +,ic, does not matc,es all t,e gi-en pattern) S!ntax: grep 0- 0e XpatternX 0e XpatternX 2 cat test0file)txt

c d

2 grep 0- 0e XaX 0e X X 0e XcX test0file)txt d %%) Counting t,e num er of matc,es using grep 0c >,en !ou +ant to count t,at ,o+ man! lines matc,es t,e gi-en pattern/string' t,en use t,e option 0c) S!ntax: grep 0c XpatternX filename 2 grep 0c XgoX demoLtext 3 >,en !ou +ant do find out ,o+ man! lines matc,es t,e pattern 2 grep 0c t,is demoLfile 7 >,en !ou +ant do find out ,o+ man! lines t,at does not matc, t,e pattern 2 grep 0- 0c t,is demoLfile 8 %&) @ispla! onl! t,e file names +,ic, matc,es t,e gi-en pattern using grep 0l If !ou +ant t,e grep to s,o+ out onl! t,e file names +,ic, matc,ed t,e gi-en pattern' use t,e 0l /lo+er0case L1 option) >,en !ou gi-e multiple files to t,e grep as input' it displa!s t,e names of file +,ic, contains t,e text t,at matc,es t,e pattern' +ill e -er! ,and! +,en !ou tr! to find some notes in !our +,ole director! structure) 2 grep 0l t,is demoL]

demoLfile demoLfile% %7) S,o+ onl! t,e matc,ed string ?! default grep +ill s,o+ t,e line +,ic, matc,es t,e gi-en pattern/string' ut if !ou +ant t,e grep to s,o+ out onl! t,e matc,ed string of t,e pattern t,en use t,e 0o option) It mig,t not e t,at muc, useful +,en !ou gi-e t,e string straig,t for+ard) ?ut it ecomes -er! useful +,en !ou gi-e a regex pattern and tr!ing to see +,at it matc,es as 2 grep 0o Xis)]lineX demoLfile is line is t,e %st lo+er case line is line is is t,e last line %8) S,o+ t,e position of matc, in t,e line >,en !ou +ant grep to s,o+ t,e position +,ere it matc,es t,e pattern in t,e file' use t,e follo+ing options as S!ntax: grep 0o 0 XpatternX file 2 cat temp0file)txt %&784 %&784

2 grep 0o 0 X7X temp0file)txt &:7 ;:7 Note: .,e output of t,e grep command a o-e is not t,e position in t,e line' it is !te offset of t,e +,ole file) %4) S,o+ line num er +,ile displa!ing t,e output using grep 0n .o s,o+ t,e line num er of file +it, t,e line matc,ed) It does %0 ased line num ering for eac, file) Use 0n option to utiliVe t,is feature)

2 grep 0n XgoX demoLtext 4: ] e 0 go to t,e end of t,e current +ord) 3: ] E 0 go to t,e end of t,e current >E$@) 7: ] 0 go to t,e pre-ious / efore1 +ord)

;: ] ? 0 go to t,e pre-ious / efore1 >E$@) =: ] + 0 go to t,e next +ord) %(: ] > 0 go to t,e next >E$@) EP.IENS Eptio n 0 0c 0, @escription

@ispla! t,e loc* num er at t,e eginning of eac, line) @ispla! t,e num er of matc,ed lines) @ispla! t,e matc,ed lines' ut do not displa! t,e filenames) Ignore case sensiti-it!) @ispla! t,e filenames' ut do not displa! t,e matc,ed lines) @ispla! t,e matc,ed lines and t,eir line num ers) Silent mode) @ispla! all lines t,at do NE. matc,) Matc, +,ole +ord)

0i 0l

0n 0s 00+

ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ)) .EP Command Examples in Linux

?! $a-i Sai-e Under: CentES' 5edora' Linux Commands' Linux @istros' $edJat En: Marc, 8' &(%7 @o+nload Cour 5ree e?oo*s NE> 0 %( 5ree Linux e?oo*s for "dministrators .,is is t,e part of our on0going series of commands in Linux) >e ,a-e co-ered asic ls command and cat command) In t,is article' +e are tr!ing to explore top command +,ic, is one of t,e most freDuentl! used commands in our dail! s!stem administrati-e Mo s) topcommand displa!s processor acti-it! of !our Linux ox and also displa!s tas*s managed ! *ernel in real0 time) ItBll s,o+ processor and memor! are eing used and ot,er information li*e running processes) .,is ma! ,elp !ou to ta*e correct action) top command found in UNIX0li*e operating s!stems)

Linux .op Command Examples Cou mig,t also e interested in follo+ing tutorials : Jtop /Linux Process Monitoring1 tool for $JEL' CentES c 5edora Iotop /Monitor Linux @is* I/E1 in $JEL' CentES and 5edora %) @ispla! of .op Command In t,is example' it +ill s,o+ information li*e tas*s' memor!' cpu and s+ap) Press ADA to Duit +indo+) P top

Linux .op Command &) Sorting +it, 0E /Uppercase Letter AEB1) Press /S,ift\E1 to Sort field -ia field letter' for example press AaA letter to sort process +it, PI@ /Process I@1)

Sorting Process I@Bs +it, .op .!pe an! *e! to return to main top +indo+ +it, sorted PI@ order as s,o+n in elo+ screen) Press ADA to Duit exit t,e +indo+)

Sorting Process I@Bs 7) @ispla! Specific User Process Use top command +it, AuA option +ill displa! specific User process details) P top 0u tecmint

.op +it, Specific User Processes 8) Jig,lig,t $unning Process in .op Press AVA option in running top command +ill displa! running process in color +,ic, ma! ,elp !ou to identified running process easil!)

.op Process +it, Colorful 4) S,o+s " solute Pat, of Processes Press AcA option in running top command' it +ill displa! a solute pat, of running process)

.op +it, Specific Process Pat, 3) C,ange @ela! or Set AScreen $efres, Inter-alB in .op ?! default screen refres, inter-al is 7)( seconds' same can e c,ange pressing AdA option in running top command and c,ange it as desired as s,o+n elo+)

.op I Set $efres, .ime 7) #ill running process +it, argument A*B Cou can *ill a process after finding PI@ of process ! pressing A*A option in running top command +it,out exiting from top +indo+ as s,o+n elo+)

.op I #ill Process I@ ;) Sort ! CPU Utilisation Press /S,ift\P1 to sort processes as per CPU utiliVation) See screens,ot elo+)

.op I Jig, CPU UtiliVation =) $enice a Process Cou can use ArA option to c,ange t,e priorit! of t,e process also called $enice)

.op I $enice Process %() Sa-e .op Command $esults Press /S,ift\>1 to sa-e t,e running top command results under /root/)toprc)

.op Command Sa-e $esults %%) Wetting .op Command Jelp Press A,A option to o tain t,e top command ,elp)

.op Command Jelp %&) Exit .op Command "fter Specific repetition .op output *eep refres,ing until !ou press ADA) >it, elo+ command top command +ill automaticall! exit after %( num er of repetition) P top 0n %( .,ere are num er of arguments to *no+ more a out top command !ou ma! refer man page of top command) Please s,are it if !ou find t,is article useful t,roug, our comment ox elo+)

EP.IENS pid))) Specif! t,e list of processes t,at *ill s,ould signal) Eac, pid can e one of fi-e t,ings: n

+,ere n is larger t,an () .,e process +it, pid n +ill e signaled) ( "ll processes in t,e current process group are signaled) 0% "ll processes +it, pid larger t,an % +ill e signaled) 0n +,ere n is larger t,an %) "ll processes in process group n are signaled) >,en an argument of t,e form d0n^ is gi-en' and it is meant to denote a process group' eit,er t,e signal must e specified first' or t,e argument must e preceded ! a d00^ option' ot,er+ise it +ill e ta*en as t,e signal to send) commandname "ll processes in-o*ed using t,at name +ill e signaled) 0s signal Specif! t,e signal to send) .,e signal ma! e gi-en as a signal name or num er) 0l Print a list of signal names) .,ese are found in /usr/include/linux/signal), 0a @o not restrict t,e commandname0to0pid con-ersion to processes +it, t,e same uid as t,e present process) 0p Specif! t,at *ill s,ould onl! print t,e process id /pid1 of t,e named processes' and not send an! signals) 7 Linux fdis* Command Examples to Manage Jard @is* Partition ! ?"L"#$ISJN"N M"$IC"PP"N on SEP.EM?E$ %8' &(%(

En Linux distri utions' fdis* is t,e est tool to manage dis* partitions) fdis* is a text ased utilit!) Using fdis* !ou can create a ne+ partition' delete an existing partition' or c,ange existing partition) Using fids* !ou are allo+ed to create a maximum of four primar! partition' and an! num er of logical partitions' ased on t,e siVe of t,e dis*) #eep in mind t,at an! single partition reDuires a minimum siVe of 8(M?) In t,is article' let us re-ie+ ,o+ to use fdis* command using practical examples) >arning: @onBt delete' modif!' or add partition' if !ou donBt *no+ +,at !ou are doing) Cou +ill lose !our datae %) Sie+ "ll Existing @is* Partitions Using fdis* 0l ?efore !ou create a ne+ partition' or modif! an existing partition' !ou mig,t +ant to -ie+ all a-aila le partition in t,e s!stem) Use fdis* 0l to -ie+ all a-aila le partitions as s,o+n elo+) P fdis* 0l

@is* /de-/sda: ;()( W?' ;((&373%;43 !tes &44 ,eads' 37 sectors/trac*' =7&= c!linders Units N c!linders of %3(34 ] 4%& N ;&&4&;( !tes @is* identifier: (xf3edf3ed

@e-ice ?oot /de-/sda% /de-/sda& /de-/sda7 /de-/sda8 /de-/sda4 ] /de-/sda3 /de-/sda7 /de-/sda; /de-/sda=

Start % %=3( 4&;8 34&= %=3( &33& &=(4 7%8; 7&34

End %=4= 4&;7 34&; =7&= &33% &=(8 7%87 7&38 4&;7

?loc*s Id S!stem %4774373 &37(((7( c >=4 5".7& /L?"1 f >=4 Ext^d /L?"1

%((((83&\ 7 JP5S/N.5S &47%&(7&\ c >=4 5".7& /L?"1 437;74& ;7 Linux %=4%;33 ;7 Linux %=4%;33 ;7 Linux =7=77% ;& Linux s+ap / Solaris %3&%74;3 >=4 5".7&

.,e a o-e +ill list partitions from all t,e connected ,ard dis*s) >,en !ou ,a-e more t,an one dis* on t,e s!stem' t,e partitions list are ordered ! t,e de-iceBs /de- name) 5or example' /de-/sda' /de-/sd ' /de-/sdc and so on) &) Sie+ Partitions of a Specific Jard @is* using fdis* 0l /de-/sd_a` .o -ie+ all partitions of t,e /de-/sda ,ard dis*' do t,e follo+ing) P fdis* 0l /de-/sda Sie+ all fdis* Commands Using fdis* Command m Use fdis* command m' to -ie+ all a-aila le fdis* commands as s,o+n elo+) P fdis* /de-/sda

.,e num er of c!linders for t,is dis* is set to =7&=)

.,ere is not,ing +rong +it, t,at' ut t,is is larger t,an %(&8' and could in certain setups cause pro lems +it,: %1 soft+are t,at runs at oot time /e)g)' old -ersions of LILE1 &1 ooting and partitioning soft+are from ot,er ESs /e)g)' @ES 5@IS#' ES/& 5@IS#1

Command /m for ,elp1: m Command action a toggle a oota le flag edit sd dis*la el c toggle t,e dos compati ilit! flag d delete a partition l list *no+n partition t!pes m print t,is menu n add a ne+ partition o create a ne+ empt! @ES partition ta le p print t,e partition ta le D Duit +it,out sa-ing c,anges s create a ne+ empt! Sun dis*la el t c,ange a partition^s s!stem id u c,ange displa!/entr! units - -erif! t,e partition ta le + +rite ta le to dis* and exit x extra functionalit! /experts onl!1 7) @elete a Jard @is* Partition Using fdis* Command d

Let us assume t,at !ou li*e to com ine se-eral partitions /for example' /de-/sda3' /de-/sda7 and /de-/sda;1 into a single dis* partition) .o do t,is' !ou s,ould first delete all t,ose indi-idual partitions' as s,o+n elo+) P fdis* /de-/sda

.,e num er of c!linders for t,is dis* is set to =7&=) .,ere is not,ing +rong +it, t,at' ut t,is is larger t,an %(&8' and could in certain setups cause pro lems +it,: %1 soft+are t,at runs at oot time /e)g)' old -ersions of LILE1 &1 ooting and partitioning soft+are from ot,er ESs /e)g)' @ES 5@IS#' ES/& 5@IS#1

Command /m for ,elp1: p

@is* /de-/sda: ;()( W?' ;((&373%;43 !tes &44 ,eads' 37 sectors/trac*' =7&= c!linders Units N c!linders of %3(34 ] 4%& N ;&&4&;( !tes @is* identifier: (xf3edf3ed

@e-ice ?oot /de-/sda% /de-/sda& /de-/sda7 /de-/sda8 /de-/sda4 ] /de-/sda3 /de-/sda7

Start % %=3( 4&;8 34&= %=3( &33& &=(4

End %=4= 4&;7 34&; =7&= &33% &=(8 7%87

?loc*s Id S!stem %4774373 &37(((7( c >=4 5".7& /L?"1 f >=4 Ext^d /L?"1

%((((83&\ 7 JP5S/N.5S &47%&(7&\ c >=4 5".7& /L?"1 437;74& ;7 Linux %=4%;33 ;7 Linux %=4%;33 ;7 Linux

/de-/sda; /de-/sda=

7%8; 7&34

7&38 4&;7

=7=77% ;& Linux s+ap / Solaris %3&%74;3 >=4 5".7&

Command /m for ,elp1: d Partition num er /%0=1: ;

Command /m for ,elp1: d Partition num er /%0;1: 7

Command /m for ,elp1: d Partition num er /%071: 3

Command /m for ,elp1: + .,e partition ta le ,as een alterede

Calling ioctl/1 to re0read partition ta le)

>"$NINW: $e0reading t,e partition ta le failed +it, error %3: @e-ice or resource us!) .,e *ernel still uses t,e old ta le) .,e ne+ ta le +ill e used at t,e next re oot or after !ou run partpro e/;1 or *partx/;1 S!ncing dis*s) 8) Create a Ne+ @is* Partition +it, Specific SiVe Using fdis* Command n Ence !ouB-e deleted all t,e existing partitions' !ou can create a ne+ partition using all a-aila le space as s,o+n elo+) P fdis* /de-/sda

.,e num er of c!linders for t,is dis* is set to =7&=)

.,ere is not,ing +rong +it, t,at' ut t,is is larger t,an %(&8' and could in certain setups cause pro lems +it,: %1 soft+are t,at runs at oot time /e)g)' old -ersions of LILE1 &1 ooting and partitioning soft+are from ot,er ESs /e)g)' @ES 5@IS#' ES/& 5@IS#1

Command /m for ,elp1: n 5irst c!linder /&33&04&;7' default &33&1: Using default -alue &33& Last c!linder' \c!linders or \siVe_#'M'W` /&33&07&38' default 7&381: Using default -alue 7&38 In t,e a o-e example' fdis* n command is used to create ne+ partition +it, t,e specific siVe) >,ile creating a ne+ partition' it expects follo+ing t+o inputs) Starting c!linder num er of t,e partition to e create /5irst c!linder1) SiVe of t,e partition /or1 t,e last c!linder num er /Last c!linder' \c!linders or \siVe 1) Please *eep in mind t,at !ou s,ould issue t,e fdis* +rite command /+1 after an! modifications) Command /m for ,elp1: + .,e partition ta le ,as een alterede

Calling ioctl/1 to re0read partition ta le)

>"$NINW: $e0reading t,e partition ta le failed +it, error %3: @e-ice or resource us!) .,e *ernel still uses t,e old ta le) .,e ne+ ta le +ill e used at t,e next re oot or after !ou run partpro e/;1 or *partx/;1 S!ncing dis*s) "fter t,e partition is created' format it using t,e m*fs command as s,o+n elo+) P m*fs)ext7 /de-/sda7

4) Sie+ t,e SiVe of an existing Partition Using fdis* 0s "s s,o+n elo+' fdis* 0s displa!s t,e siVe of t,e partition in loc*s) P fdis* 0s /de-/sda7 8;87433 .,e a o-e output corresponds to a out 8=((M?) 3) .oggle t,e ?oot 5lag of a Partition Using fdis* Command a 5dis* command displa!s t,e oot flag of eac, partition) >,en !ou +ant to disa le or ena le t,e oot flag on t,e corresponding partition' do t,e follo+ing) If !ou donBt *no+ +,! are !ou are doing t,is' !ouBll mess0up !our s!stem) P fdis* /de-/sda

.,e num er of c!linders for t,is dis* is set to =7&=) .,ere is not,ing +rong +it, t,at' ut t,is is larger t,an %(&8' and could in certain setups cause pro lems +it,: %1 soft+are t,at runs at oot time /e)g)' old -ersions of LILE1 &1 ooting and partitioning soft+are from ot,er ESs /e)g)' @ES 5@IS#' ES/& 5@IS#1

Command /m for ,elp1: p

@is* /de-/sda: ;()( W?' ;((&373%;43 !tes &44 ,eads' 37 sectors/trac*' =7&= c!linders Units N c!linders of %3(34 ] 4%& N ;&&4&;( !tes @is* identifier: (xf3edf3ed

@e-ice ?oot /de-/sda%

Start %

End %=4=

?loc*s Id S!stem %4774373 c >=4 5".7& /L?"1

/de-/sda& /de-/sda7 /de-/sda8 /de-/sda4 ] /de-/sda3 /de-/sda7

%=3( 4&;8 34&= %=3( 7&34 &33&

4&;7 34&; =7&= &33% 4&;7 7&38

&37(((7(

f >=4 Ext^d /L?"1

%((((83&\ 7 JP5S/N.5S &47%&(7&\ c >=4 5".7& /L?"1 437;74& ;7 Linux %3&%74;3 >=4 5".7&

8;87433 ;7 Linux

Partition ta le entries are not in dis* order

Command /m for ,elp1: a Partition num er /%071: 4

Command /m for ,elp1: p

@is* /de-/sda: ;()( W?' ;((&373%;43 !tes &44 ,eads' 37 sectors/trac*' =7&= c!linders Units N c!linders of %3(34 ] 4%& N ;&&4&;( !tes @is* identifier: (xf3edf3ed

@e-ice ?oot /de-/sda% /de-/sda& /de-/sda7 /de-/sda8 /de-/sda4 /de-/sda3

Start % %=3( 4&;8 34&= %=3( 7&34

End %=4= 4&;7 34&; =7&= &33% 4&;7

?loc*s Id S!stem %4774373 &37(((7( c >=4 5".7& /L?"1 f >=4 Ext^d /L?"1

%((((83&\ 7 JP5S/N.5S &47%&(7&\ c >=4 5".7& /L?"1 437;74& ;7 Linux %3&%74;3 >=4 5".7&

/de-/sda7

&33&

7&38

8;87433 ;7 Linux

Partition ta le entries are not in dis* order

Command /m for ,elp1: "s seen a o-e' t,e oot flag is disa led on t,e partition /de-/sda4) 7) 5ix Partition .a le Erder Using fdis* Expert Command f >,en !ou delete a logical partition' and recreate it again' !ou mig,t see t,e Fpartition out of orderH issue) i)e FPartition ta le entries are not in dis* orderH error message) 5or example' +,en !ou delete t,ree logical partitions /sda3' sda7 and sda;1' and create a ne+ partition' !ou mig,t expect t,e ne+ partition name to e sda3) ?ut' t,e s!stem mig,tB-e created t,e ne+ partition as sda7) .,is is ecause' after t,e partitions are deleted' sda= partition ,as een mo-ed as sda3 and t,e free space is mo-ed to t,e end) .o fix t,is partition order issue' and assign sda3 to t,e ne+l! created partition' execute t,e expert command f as s,o+n elo+) 2 fdis* /de-/sda

.,e num er of c!linders for t,is dis* is set to =7&=) .,ere is not,ing +rong +it, t,at' ut t,is is larger t,an %(&8' and could in certain setups cause pro lems +it,: %1 soft+are t,at runs at oot time /e)g)' old -ersions of LILE1 &1 ooting and partitioning soft+are from ot,er ESs /e)g)' @ES 5@IS#' ES/& 5@IS#1

Command /m for ,elp1: p

@is* /de-/sda: ;()( W?' ;((&373%;43 !tes &44 ,eads' 37 sectors/trac*' =7&= c!linders

Units N c!linders of %3(34 ] 4%& N ;&&4&;( !tes @is* identifier: (xf3edf3ed

@e-ice ?oot /de-/sda% /de-/sda& /de-/sda7 /de-/sda8 /de-/sda4 ] /de-/sda3 /de-/sda7

Start % %=3( 4&;8 34&= %=3( 7&34 &33&

End %=4= 4&;7 34&; =7&= &33% 4&;7 7&38

?loc*s Id S!stem %4774373 &37(((7( c >=4 5".7& /L?"1 f >=4 Ext^d /L?"1

%((((83&\ 7 JP5S/N.5S &47%&(7&\ c >=4 5".7& /L?"1 437;74& ;7 Linux %3&%74;3 >=4 5".7&

8;87433 ;7 Linux

Partition ta le entries are not in dis* order

Command /m for ,elp1: x

Expert command /m for ,elp1: f @one)

Expert command /m for ,elp1: + .,e partition ta le ,as een alterede

Calling ioctl/1 to re0read partition ta le)

>"$NINW: $e0reading t,e partition ta le failed +it, error %3: @e-ice or resource us!) .,e *ernel still uses t,e old ta le) .,e ne+ ta le +ill e used at

t,e next re oot or after !ou run partpro e/;1 or *partx/;1 S!ncing dis*s) Ence t,e partition ta le order is fixed' !ouBll not get t,e FPartition ta le entries are not in dis* orderH error message an!more) P fdis* 0l

@is* /de-/sda: ;()( W?' ;((&373%;43 !tes &44 ,eads' 37 sectors/trac*' =7&= c!linders Units N c!linders of %3(34 ] 4%& N ;&&4&;( !tes @is* identifier: (xf3edf3ed

@e-ice ?oot /de-/sda% /de-/sda& /de-/sda7 /de-/sda8 /de-/sda4 ] /de-/sda3 /de-/sda7

Start % %=3( 4&;8 34&= %=3( &33& 7&34

End %=4= 4&;7 34&; =7&= &33% 7&38 4&;7

?loc*s Id S!stem %4774373 &37(((7( c >=4 5".7& /L?"1 f >=4 Ext^d /L?"1

%((((83&\ 7 JP5S/N.5S &47%&(7&\ c >=4 5".7& /L?"1 437;74& ;7 Linux 8;87433 ;7 Linux %3&%74;3 >=4 5".7&

Jo+.o: Linux List @is* Partitions Command ! NIX C$"5. on 5E?$U"$C &8' &(%& f 4 CEMMEN.Sf L"S. UP@".E@ EC.E?E$ 7' &(%& in LINUX

Jo+ do I list all ,ard dis* partitions under Linux operating s!stems6 Usuall!' !our ,ard dis* dri-e di-ided into one or more logical dis*s called partitions) .,is di-ision is descri ed in t,e partition ta le found in sector ( of t,e ,ard dis*) .utorial details @ifficult! $oot pri-ileges $eDuirements Estimated completion time Eas! /rs s1 Ces None N/"

.,e de-ice is usuall! /de-/sda' /de-/sd or so) " de-ice name refers to t,e entire dis* and t,e de-ice name +ill e as follo+s: /de-/,d] 0 I@E dis*s) /de-/,da +ill e first I@E ,ard dis*' /de-/,d +ill e second I@E ,ard dis*' and so on) /de-/sd] 0 SCSI or S"." dis*s) /de-/sda +ill e first S"."/SCSI ,ard dis*' /de-/sd +ill e second S"."/SCSI ,ard dis*' and so on) >"$NINWe .,ese examples ma! cras, !our computer if NE. executed +it, proper care) ?E EX.$EMELC C"$E5UL >I.J .JE 5ELLE>INW CEMM"N@S) ENE .CPINW MIS."#E "N@ "LL CEU$ @"." IS LES.) ls l* Command .o list all loc* de-ices' run: P ls l* Sample outputs: N"ME M"U:MIN $M SITE $E .CPE MEUN.PEIN.

sda

;:(

% 44;W ( dis* % 7(7M ( part / oot % &4(W ( part /+e root % % 3W ( part 9S>"P: %# ( part

gsda% ;:% gsda& ;:& gsda7 ;:7 gsda8 ;:8 hgsda4 ;:4 sr( %%:(

% 7(%)7W ( part / % %(&8M ( rom

List Partitions Under Linux Epen a terminal +indo+ /select "pplications b "ccessories b .erminal1) S+itc, to t,e root user ! t!ping su 0 and entering t,e root pass+ord' +,en prompted) Er use sudo command: 2 su 0 P fdis* 0l E$ 2 sudo fdis* 0l Sample outputs: @is* /de-/sda: &4%)% W?' &4%(4=488(38 !tes &44 ,eads' 37 sectors/trac*' 7(4&& c!linders Units N c!linders of %3(34 ] 4%& N ;&&4&;( !tes Sector siVe /logical/p,!sical1: 4%& !tes / 4%& !tes I/E siVe /minimum/optimal1: 4%& !tes / 4%& !tes @is* identifier: (x(((;fcd7 @e-ice ?oot /de-/sda% ] Start % End %8 ?loc*s Id S!stem %(888; ;7 Linux

Partition % does not end on c!linder oundar!) /de-/sda& /de-/sda7 /de-/sda8 /de-/sda4 %8 %7(3; %7%=; %7%=; %7(3; %(8;473(( ;7 Linux %7%=; %(8;473 ;& Linux s+ap / Solaris 4 Extended

7(4&7 %7=%3738;

7(4&7 %7=%3&3&8 ;7 Linux

.,e 0l options s,o+s t,e partition ta les for t,e specified de-ices and t,en exit) If no de-ices are gi-en' t,ose mentioned in /proc/partitions /if t,at exists1 are used) Cou can specif! de-ice name as follo+s /in t,is example list partitions for /de-/sda1: P fdis* 0l sfdis* Command .,e sfdis* command act as a partition ta le manipulator for Linux) Cou can use t,is tool to list partitions too: P sfdis* 0l /de-/sda P sfdis* 0lu /de-/sda P sfdis* 0ls /de-/sda Sample outputs: 7%33=73( @is* /de-/sda: ;=&& c!linders' &44 ,eads' 37 sectors/trac* Units N c!linders of ;&&4&;( !tes' loc*s of %(&8 !tes' counting from ( @e-ice ?oot Start /de-/sda% ] /de-/sda& /de-/sda7 /de-/sda8 >,ere' 0l : List t,e partitions of a de-ice) 0s : List t,e siVe of a partition) 0u or 0uS or 0u? or 0uC or 0uM : "ccept or report in units of sectors / loc*s' c!linders' mega !tes' respecpi-el!1) .,e default is c!linders' at least +,en t,e geometr! is *no+n) Listing Linux a Partition SiVe Larger .,an &.? .,e fdis* or sfdis* command +ill not list an! partition siVe larger t,an &.?) .o sol-e t,is pro lem !ou need to use WNU parted command +it, WP. partitions) It supports Intel E5I/WP. partition ta les) Partition .a le /WP.1 is a standard for t,e la!out of t,e partition ta le on a p,!sical ,ard dis*) It is a part of t,e Extensi le 5irm+are Interface /E5I1 standard proposed ! Intel as a replacement for t,e outdated PC ?IES' one of t,e fe+ remaining relics of t,e original I?M PC) E5I uses WP. +,ere ?IES uses a Master ?oot $ecord /M?$1) In t,is example list partitions on /de-/sd using t,e parted command: (\ %(8\ End Pc!ls %(80 &740 %(40 P loc*s Id S!stem ;7;343 ;7 Linux

%7%0 %(8;473 ;& Linux s+ap / Solaris

&74\ ;=&&0 ;3;;0 3=7;%4(8 ;7 Linux ( 0 ( ( ( Empt!

P parted /de-/sd Sample outputs: WNU Parted &)7 Using /de-/sd >elcome to WNU Partede .!pe ^,elp^ to -ie+ a list of commands) /parted1 Set unit t!pe to .? or W? ! t!ping ^unit .?^ or ^unit W?^ at t,e /parted1 prompt: /parted1 unit .? E$ /parted1 unit W? .o list partitions t!pe print command at t,e /parted1 prompt: /parted1 print Sample outputs: Model: "." S.77(((34%"S /scsi1 @is* /de-/sd : 7((%W? Sector siVe /logical/p,!sical1: 4%&?/4%&? Partition .a le: gpt Num er Start End % SiVe 5ile s!stem Name primar! 5lags

()((W? 7((%W? 7((%W? ext8

/parted1 .o exit from parted session t!pe ^Duit^ at t,e /parted1 prompt: /parted1 Duit Jo+ @o I List "ll Partitions La!out En "ll ?loc* @e-ices6 Pass t,e 0l E$ 00list option to t,e parted command to lists partition la!out on all loc* de-ices: P parted 0l Sample outputs:

5ig)(%: S,o+ Linux @is* Partitions >it, WNU parted Command lssci command Use t,e lsscsi command to s,o+ SCSI de-ices /or ,osts1 and t,eir attri utes: P lsscsi Sample outputs: 9(:(:(:(: 9%:(:(:(: 9&:(:(:(: dis* "." .ESJI?" M#4(3%WS M5(( /de-/sda %)%( /de-/sr(

cd/d-d M".SJI." ?@0$E UU&7&" dis* "." S.=4((8&("SW

(((8 /de-/sd

Jo+.o: Use grep Command In Linux / UNIX I Examples ! NIX C$"5. on "UWUS. &' &((7 f &33 CEMMEN.Sf L"S. UP@".E@ UULC 7(' &(%7 in ?"SJ SJELL' LINUX' UNIX

Jo+ do I use grep command on Linux' "pple ES X' and Unix0li*e operating s!stems6 Can !ou gi-e me a simple examples of t,e grep command6 .,e grep command is used to searc, text or searc,es t,e gi-en file for lines containing a matc, to t,e gi-en strings or +ords) ?! default' grep displa!s t,e matc,ing lines) Use grep to searc, for lines of text t,at matc, one or man! regular expressions' and outputs onl! t,e matc,ing lines) grep is considered as one of t,e most useful commands on Unix and ot,er Linux operating s!stems) .utorial details @ifficult! $oot pri-ileges $eDuirements Estimated completion time @id !ou *no+6 .,e name' XgrepX' deri-es from t,e command used to perform a similar operation' using t,e Unix/Linux text editor ed: g/re/p .,e grep command s!ntax .,e s!ntax is as follo+s: Eas! /rss1 No grep %( minutes

grep ^+ord^ filename grep ^+ord^ file% file& file7 grep ^string% string&^ filename cat ot,erfile G grep ^somet,ing^ command G grep ^somet,ing^ command option% G grep ^data^ grep 00color ^data^ fileName

Jo+ do I use grep command to searc, a file6

Searc, /etc/pass+d file for oo user' enter: 2 grep oo /etc/pass+d Sample outputs: foo:x:%(((:%(((:foo''':/,ome/foo:/ in/*s, Cou can force grep to ignore +ord case i)e matc, oo' ?oo' ?EE and all ot,er com ination +it, t,e 0i option: 2 grep 0i X ooX /etc/pass+d Use grep recursi-el! Cou can searc, recursi-el! i)e) read all files under eac, director! for a string X%=&)%3;)%)4X 2 grep 0r X%=&)%3;)%)4X /etc/ E$ 2 grep 0$ X%=&)%3;)%)4X /etc/ Sample outputs: /etc/ppp/options:P ms0+ins %=&)%3;)%)4( /etc/ppp/options:P ms0+ins %=&)%3;)%)4% /etc/Net+or*Manager/s!stem0connections/>ired connection %:addresses%N%=&)%3;)%)4Y&8Y%=&)%3;)%)&Y Cou +ill see result for %=&)%3;)%)4 on a separate line preceded ! t,e name of t,e file /suc, as /etc/ppp/options1 in +,ic, it +as found) .,e inclusion of t,e file names in t,e output data can e suppressed ! using t,e 0, option as follo+s: 2 grep 0, 0$ X%=&)%3;)%)4X /etc/ E$ 2 grep 0,$ X%=&)%3;)%)4X /etc/ Sample outputs: P ms0+ins %=&)%3;)%)4( P ms0+ins %=&)%3;)%)4% addresses%N%=&)%3;)%)4Y&8Y%=&)%3;)%)&Y Use grep to searc, +ords onl! >,en !ou searc, for oo' grep +ill matc, foo oo' oo%&7' arfoo74 and more) Cou can force t,e grep command to select onl! t,ose lines containing matc,es t,at form +,ole +ords i)e) matc, onl! oo +ord: 2 grep 0+ X ooX file Use grep to searc, & different +ords

Use t,e egrep command as follo+s: 2 egrep 0+ ^+ord%G+ord&^ /pat,/to/file Count line +,en +ords ,as een matc,ed .,e grep can report t,e num er of times t,at t,e pattern ,as een matc,ed for eac, file using0 c /count1 option: 2 grep 0c ^+ord^ /pat,/to/file Pass t,e 0n option to precede eac, line of output +it, t,e num er of t,e line in t,e text file from +,ic, it +as o tained: 2 grep 0n ^root^ /etc/pass+d Sample outputs: %:root:x:(:(:root:/root:/ in/ as, %(8&:rootdoor:x:(:(:rootdoor:/,ome/rootdoor:/ in/cs, 77%=:initrootapp:x:(:(:initrootapp:/,ome/initroot:/ in/*s, Wrep in-ert matc, Cou can use 0- option to print in-erts t,e matc,Y t,at is' it matc,es onl! t,ose lines t,at do not contain t,e gi-en +ord) 5or example print all line t,at do not contain t,e +ord ar: 2 grep 0- ar /pat,/to/file UNIX / Linux pipes and grep command grep command often used +it, s,ell pipes) In t,is example' s,o+ t,e name of t,e ,ard dis* de-ices: P dmesg G egrep ^/sG,1d9a0V:^ @ispla! cpu model name: P cat /proc/cpuinfo G grep 0i ^Model^ Jo+e-er' a o-e command can e also used as follo+s +it,out s,ell pipe: P grep 0i ^Model^ /proc/cpuinfo Sample outputs: model model name model model name : 7( : Intel/$1 Core/.M1 i7 CPU : 7( : Intel/$1 Core/.M1 i7 CPU i ;&( < %)77WJV i ;&( < %)77WJV

Jo+ do I list Must t,e names of matc,ing files6 Use t,e 0l option to list file name +,ose contents mention main/1: 2 grep 0l ^main^ ])c 5inall!' !ou can force grep to displa! output in colors' enter:

2 grep 00color -i-e* /etc/pass+d Sample outputs:

%( Useful du /@is* Usage1 Commands to 5ind @is* Usage of 5iles and @irectories ?! $a-i Sai-e Under: CentES' 5edora' Linux Commands' $edJat En: Uanuar! &%' &(%7 @o+nload Cour 5ree e?oo*s NE> 0 %( 5ree Linux e?oo*s for "dministrators .,e Linux FduH /@is* Usage1 is a standard Unix/Linux command' used to c,ec* t,e information of dis* usage of files and directories on a mac,ine) .,e du command ,as man! parameter options t,at can e used to get t,e results in man! formats) .,e du command also displa!s t,e files and director! siVes in a recursi-el! manner)

C,ec* @is* Usage of 5iles and 5olders In Linux .,is article explains %( useful FduH commands +it, t,eir examples' t,at mig,t ,elps !ou to find out t,e siVes of files and directories in Linux) .,e information pro-ided in t,is article are ta*en from t,e man pages of du command) $ead "lso: %& FdfH Command to C,ec* Linux S!stem @is* Space

%) .o find out t,e dis* usage summar! of a /,ome/tecmint director! tree and eac, of its su directories) Enter t,e command as: 9root<tecmint:P du /,ome/tecmint

8( 8 8 %& %&

/,ome/tecmint/do+nloads /,ome/tecmint/)moVilla/plugins /,ome/tecmint/)moVilla/extensions /,ome/tecmint/)moVilla /,ome/tecmint/)ss,

3;=%%& /,ome/tecmint/U untu0%&)%( 3;=73( /,ome/tecmint .,e output of t,e a o-e command displa!s t,e num er of dis* loc*s in t,e /,ome/tecmintdirector! along +it, its su 0directories) &) Using F0,H option +it, FduH command pro-ides results in FJuman $eada le 5ormatF) Means !ou can see siVes in ?!tes' #ilo !tes' Mega !tes' Wiga !tes etc) 9root<tecmint:P du 0, /,ome/tecmint

8(# 8)(# 8)(# %&# %&# 377M 378M

/,ome/tecmint/do+nloads /,ome/tecmint/)moVilla/plugins /,ome/tecmint/)moVilla/extensions /,ome/tecmint/)moVilla /,ome/tecmint/)ss, /,ome/tecmint/U untu0%&)%( /,ome/tecmint

7) .o get t,e summar! of a grand total dis* usage siVe of an director! use t,e option F0sH as follo+s) 9root<tecmint:P du 0s, /,ome/tecmint

378M

/,ome/tecmint

8) Using F0aH flag +it, FduH command displa!s t,e dis* usage of all t,e files and directories) 9root<tecmint:P du 0a /,ome/tecmint

8 %& &8 8( %& 8 8 %& 8

/,ome/tecmint/) as,Llogout /,ome/tecmint/do+nloads/uploadprogress0%)()7)%)tgV /,ome/tecmint/do+nloads/P,pfiles0org)tar) V& /,ome/tecmint/do+nloads /,ome/tecmint/uploadprogress0%)()7)%)tgV /,ome/tecmint/)moVilla/plugins /,ome/tecmint/)moVilla/extensions /,ome/tecmint/)moVilla /,ome/tecmint/) as,rc

3;=%(; /,ome/tecmint/U untu0%&)%(/u untu0%&)%(0ser-er0i7;3)iso 3;=%%& /,ome/tecmint/U untu0%&)%( 3;=73( /,ome/tecmint 4) Using F0aH flag along +it, F0,H displa!s dis* usage of all files and folders in ,uman readea le format) .,e elo+ output is more eas! to understand as it s,o+s t,e files in#ilo !tes' Mega !tes etc) 9root<tecmint:P du 0a, /,ome/tecmint

8)(# %&# &8# 8(# %&# 8)(#

/,ome/tecmint/) as,Llogout /,ome/tecmint/do+nloads/uploadprogress0%)()7)%)tgV /,ome/tecmint/do+nloads/P,pfiles0org)tar) V& /,ome/tecmint/do+nloads /,ome/tecmint/uploadprogress0%)()7)%)tgV /,ome/tecmint/)moVilla/plugins

8)(# %&# 8)(# 377M 377M 378M

/,ome/tecmint/)moVilla/extensions /,ome/tecmint/)moVilla /,ome/tecmint/) as,rc /,ome/tecmint/U untu0%&)%(/u untu0%&)%(0ser-er0i7;3)iso /,ome/tecmint/U untu0%&)%( /,ome/tecmint

3) 5ind out t,e dis* usage of a director! tree +it, its su tress in #ilo !te lco*s) Use t,e F0*H /displa!s siVe in %(&8 !tes units1) 9root<tecmint:P du 0* /,ome/tecmint 8( 8 8 %& %& /,ome/tecmint/do+nloads /,ome/tecmint/)moVilla/plugins /,ome/tecmint/)moVilla/extensions /,ome/tecmint/)moVilla /,ome/tecmint/)ss,

3;=%%& /,ome/tecmint/U untu0%&)%( 3;=73( /,ome/tecmint 7) .o get t,e summar! of dis* usage of director! tree along +it, its su trees in Mega !tes/M?1 onl!) Use t,e option F0m,H as follo+s) .,e F0mH flag counts t,e loc*s in M? units and F0,H stands for ,uman reada le format) 9root<tecmint:P du 0m, /,ome/tecmint

8(# 8)(# 8)(# %&# %&# 377M 378M

/,ome/tecmint/do+nloads /,ome/tecmint/)moVilla/plugins /,ome/tecmint/)moVilla/extensions /,ome/tecmint/)moVilla /,ome/tecmint/)ss, /,ome/tecmint/U untu0%&)%( /,ome/tecmint

;) .,e F0cH flag pro-ides a grand total usage dis* space at t,e last line) If !our director! ta*en378M? space' t,en t,e last last t+o line of t,e output +ould e) 9root<tecmint:P du 0c, /,ome/tecmint

8(# 8)(# 8)(# %&# %&# 377M 378M 378M

/,ome/tecmint/do+nloads /,ome/tecmint/)moVilla/plugins /,ome/tecmint/)moVilla/extensions /,ome/tecmint/)moVilla /,ome/tecmint/)ss, /,ome/tecmint/U untu0%&)%( /,ome/tecmint total

=) .,e elo+ command calculates and displa!s t,e dis* usage of all files and directories' ut excludes t,e files t,at matc,es gi-en pattern) .,e elo+ command excludes t,e F)txtH files +,ile calculating t,e total siVe of diretor!) So' t,is +a! !ou can exclude an! file formats ! using flag F0IexcludeF) See t,e output t,ere is no txt files entr!) 9root<tecmint:P du 0a, 00excludeNX])txtX /,ome/tecmint

8)(# %&# &8# 8(# %&# 8)(# 8)(# 8)(# 8)(# %&#

/,ome/tecmint/) as,Llogout /,ome/tecmint/do+nloads/uploadprogress0%)()7)%)tgV /,ome/tecmint/do+nloads/P,pfiles0org)tar) V& /,ome/tecmint/do+nloads /,ome/tecmint/uploadprogress0%)()7)%)tgV /,ome/tecmint/) as,L,istor! /,ome/tecmint/) as,Lprofile /,ome/tecmint/)moVilla/plugins /,ome/tecmint/)moVilla/extensions /,ome/tecmint/)moVilla

8)(# &8# 8)(# 8)(# %&(# 377M 377M 378M

/,ome/tecmint/) as,rc /,ome/tecmint/P,pfiles0org)tar) V& /,ome/tecmint/geoipupdate)s, /,ome/tecmint/)Vs,rc /,ome/tecmint/goaccess0()8)&)tar)gV)% /,ome/tecmint/U untu0%&)%(/u untu0%&)%(0ser-er0i7;3)iso /,ome/tecmint/U untu0%&)%( /,ome/tecmint

%() @ispla! t,e dis* usage ased on modification of time' use t,e flag FItimeH as s,o+n elo+) 9root<tecmint:P du 0,a 00time /,ome/tecmint

8)(# %&# &8# 8(# %&# 8)(# 8)(# ( ( 8)(# 8)(# %&# 8)(# &8# 8)(#

&(%&0%(0%& &&:7& &(%70(%0%= %;:8; &(%70(%0%= %;:8; &(%70(%0%= %;:8; &(%70(%0%= %;:7& &(%&0%(0%7 ((:%% &(%&0%(0%& &&:7& &(%70(%0%= %;:7& &(%70(%0%= %;:7& &(%&0%(0%& &&:7& &(%&0%(0%& &&:7& &(%&0%(0%& &&:7& &(%&0%(0%& &&:7& &(%70(%0%= %;:7& &(%70(%0%= %;:7&

/,ome/tecmint/) as,Llogout /,ome/tecmint/do+nloads/uploadprogress0%)()7)%)tgV /,ome/tecmint/do+nloads/P,pfiles0org)tar) V& /,ome/tecmint/do+nloads /,ome/tecmint/uploadprogress0%)()7)%)tgV /,ome/tecmint/) as,L,istor! /,ome/tecmint/) as,Lprofile /,ome/tecmint/x!V)txt /,ome/tecmint/a c)txt /,ome/tecmint/)moVilla/plugins /,ome/tecmint/)moVilla/extensions /,ome/tecmint/)moVilla /,ome/tecmint/) as,rc /,ome/tecmint/P,pfiles0org)tar) V& /,ome/tecmint/geoipupdate)s,

8)(# %&(# 377M 377M 378M

&(%&0%(0%& &&:7& &(%70(%0%= %;:7& &(%70(%0%= %;:4% &(%70(%0%= %;:4% &(%70(%0%= %;:4&

/,ome/tecmint/)Vs,rc /,ome/tecmint/goaccess0()8)&)tar)gV)% /,ome/tecmint/U untu0%&)%(/u untu0%&)%(0ser-er0i7;3)iso /,ome/tecmint/U untu0%&)%( /,ome/tecmint

%& Useful FdfH Commands to C,ec* @is* Space in Linux ?! $a-i Sai-e Under: Clear ES' 5edora' Linux Commands' $edJat En: Uanuar! %4' &(%7 @o+nload Cour 5ree e?oo*s NE> 0 %( 5ree Linux e?oo*s for "dministrators En t,e internet !ou +ill find plent! of tools for c,ec*ing dis* space utiliVation in Linux) Jo+e-er' Linux ,as a strong uilt in utilit! called AdfA) .,e AdfA command stand for Fdis* files!stemF' it is used to get full summar! of a-aila le and used dis* space usage of file s!stem on Linux s!stem) Using A0,A parameter +it, /df 0,1 +ill s,o+s t,e file s!stem dis* space statistics in F,uman reada leH format' means it gi-es t,e details in !tes' mega !tes and giga !te)

Useful df Command Examples .,is article explain a +a! to get t,e full information of Linux dis* space usage +it, t,e ,elp of AdfA command +it, t,eir practical examples) So' !ou could etter understand t,e usage of df command in Linux) %) C,ec* 5ile S!stem @is* Space Usage .,e FdfH command displa!s t,e information of de-ice name' total loc*s' total dis* space' used dis* space' a-aila le dis* space and mount points on a file s!stem) 9root<tecmint j:P df

5iles!stem

%#0 loc*s

Used "-aila le UseQ Mounted on

/de-/cciss/c(d(p& /de-/cciss/c(d(p4 /de-/cciss/c(d(p7 /de-/cciss/c(d(p% tmpfs

7;73%%=& &7%;4;8( 4%%7(4;; 7&Q / &87=77;( &&&7787& %&87=7& =4Q /,ome &=7474;; &44(77=& &7%7=;8 =%Q /data &=443% ( &%47% &4;77( ;Q / oot

&47873

&47873 (Q /de-/s,m

&) @ispla! Information of all 5ile S!stem @is* Space Usage .,e same as a o-e' ut it also displa!s information of dumm! file s!stems along +it, all t,e file s!stem dis* usage and t,eir memor! utiliVation) 9root<tecmint j:P df 0a

5iles!stem

%#0 loc*s

Used "-aila le UseQ Mounted on

/de-/cciss/c(d(p& proc s!sfs de-pts /de-/cciss/c(d(p4 /de-/cciss/c(d(p7 /de-/cciss/c(d(p% tmpfs none sunrpc

7;73%%=& &7%;3%%3 4%%7(7%& 7&Q / ( ( ( ( ( ( ( 0 /proc ( 0 /s!s ( 0 /de-/pts

&87=77;( &&&7787& %&87=7& =4Q /,ome &=7474;; &44(77=& &7%7=;8 =%Q /data &=443% ( ( ( &%47% &4;77( ;Q / oot

&47873 ( (

&47873 (Q /de-/s,m ( 0 /proc/s!s/fs/ infmtLmisc ( 0 /-ar/li /nfs/rpcLpipefs

7) S,o+ @is* Space Usage in Juman $eada le 5ormat Ja-e !ou noticed t,at a o-e commands displa!s information in !tes' +,ic, is not reada le !et all' ecause +e are in a ,a it of reading t,e siVes in mega !tes' giga !tes etc) as it ma*es -er! eas! to understand and remem er)

.,e df command pro-ides an option to displa! siVes in Juman $eada le formats ! using A0,B /prints t,e results in ,uman reada le format /e)g)' %# &M 7W11) 9root<tecmint j:P df 0,

5iles!stem /de-/cciss/c(d(p& /de-/cciss/c(d(p4 /de-/cciss/c(d(p7 /de-/cciss/c(d(p% tmpfs

SiVe Used "-ail UseQ Mounted on 74W &7W 8=W 7&Q / &8W &&W %)&W =4Q /,ome &=W &4W &)3W =%Q /data &;=M &&M &47M ;Q / oot ( &4&M (Q /de-/s,m

&4&M

8) @ispla! Information of /,ome 5ile S!stem .o see t,e information of onl! de-ice /,ome file s!stem in ,uman reada le format use t,e follo+ing command) 9root<tecmint j:P df 0,. /,ome

5iles!stem /de-/cciss/c(d(p4

.!pe ext7

SiVe Used "-ail UseQ Mounted on &8W &&W %)&W =4Q /,ome

4) @ispla! Information of 5ile S!stem in ?!tes .o displa! all file s!stem information and usage in %(&80 !te loc*s' use t,e option A0*A /e)g) I loc*0siVeN%#1 as follo+s) 9root<tecmint j:P df 0*

5iles!stem

%#0 loc*s

Used "-aila le UseQ Mounted on

/de-/cciss/c(d(p& /de-/cciss/c(d(p4 /de-/cciss/c(d(p7 /de-/cciss/c(d(p% tmpfs

7;73%%=& &7%;7&%& 4%%&=&%3 7&Q / &87=77;( &&&7787& %&87=7& =4Q /,ome &=7474;; &44(77=& &7%7=;8 =%Q /data &=443% ( &%47% &4;77( ;Q / oot

&47873

&47873 (Q /de-/s,m

3) @ispla! Information of 5ile S!stem in M? .o displa! information of all file s!stem usage in M? /Mega ?!te1 use t,e option as A0mA) 9root<tecmint j:P df 0m

5iles!stem

%M0 loc*s 734&4 &8&%7 &=(47 &;= &4& (

Used "-aila le UseQ Mounted on &&388 &%74& &8=(7 && 8==7% 7&Q / %&%4 =4Q /,ome &34% =%Q /data &47 ;Q / oot

/de-/cciss/c(d(p& /de-/cciss/c(d(p4 /de-/cciss/c(d(p7 /de-/cciss/c(d(p% tmpfs

&4& (Q /de-/s,m

7) @ispla! Information of 5ile S!stem in W? .o displa! information of all file s!stem statistics in W? /Wiga !te1 use t,e option as Adf 0,A) 9root<tecmint j:P df 0,

5iles!stem /de-/cciss/c(d(p& /de-/cciss/c(d(p4 /de-/cciss/c(d(p7 /de-/cciss/c(d(p% tmpfs

SiVe Used "-ail UseQ Mounted on 74W &7W 8=W 7&Q / &8W &&W %)&W =4Q /,ome &=W &4W &)3W =%Q /data &;=M &&M &47M ;Q / oot ( &4&M (Q /de-/s,m

&4&M

;) @ispla! 5ile S!stem Inodes Using A0iA s+itc, +ill displa! t,e information of num er of used inodes and t,eir percentage for t,e file s!stem) 9root<tecmint j:P df 0i

5iles!stem /de-/cciss/c(d(p&

Inodes IUsed I5ree IUseQ Mounted on &(&7(;8; %77%87 &((=77(4 %Q /

/de-/cciss/c(d(p4 /de-/cciss/c(d(p7 /de-/cciss/c(d(p% tmpfs

38(77%& 7=;3%7 43(4(== %7Q /,ome 73;488( %7;;&8% 3&=7%== %=Q /data 737(8 8( 73&38 %Q / oot

3873=

% 3873;

%Q /de-/s,m

=) @ispla! 5ile S!stem .!pe If !ou notice all t,e a o-e commands output' !ou +ill see t,ere is no file s!stem t!pe mentioned in t,e results) .o c,ec* t,e file s!stem t!pe of !our s!stem use t,e option A.A) It +ill displa! file s!stem t!pe along +it, ot,er information) 9root<tecmint j:P df 0.

5iles!stem /de-/cciss/c(d(p& /de-/cciss/c(d(p4 /de-/cciss/c(d(p7 /de-/cciss/c(d(p% tmpfs

.!pe %#0 loc*s Used ext7 ext7 ext7 ext7

"-aila le UseQ Mounted on

7;73%%=& &7%;;;%& 4%%&73%3 7&Q / &87=77;( &&&7787& %&87=7& =4Q /,ome &=7474;; &44(77=& &7%7=;8 =%Q /data &=443% &%47% ( &4;77( &47873 ;Q / oot

tmpfs &47873

(Q /de-/s,m

%() Include Certain 5ile S!stem .!pe If !ou +ant to displa! certain file s!stem t!pe use t,e A0tA option) 5or example' t,e follo+ing command +ill onl! displa! ext7 file s!stem) 9root<tecmint j:P df 0t ext7

5iles!stem

%#0 loc*s

Used "-aila le UseQ Mounted on

/de-/cciss/c(d(p& /de-/cciss/c(d(p4 /de-/cciss/c(d(p7 /de-/cciss/c(d(p%

7;73%%=& &7%=((7& 4%%&3743 7&Q / &87=77;( &&&7787& %&87=7& =4Q /,ome &=7474;; &44(77=& &7%7=;8 =%Q /data &=443% &%47% &4;77( ;Q / oot

%%) Exclude Certain 5ile S!stem .!pe

If !ou +ant to displa! file s!stem t!pe t,at doesnBt elongs to ext7 t!pe use t,e option as A0xA) 5or example' t,e follo+ing command +ill onl! displa! ot,er file s!stems t!pes ot,er t,anext7) 9root<tecmint j:P df 0x ext7

5iles!stem tmpfs

%#0 loc*s &47873

Used "-aila le UseQ Mounted on ( &47873 (Q /de-/s,m

%&) @ispla! Information of df Command) Using AI,elpA s+itc, +ill displa! a list of a-aila le option t,at are used +it, df command) 9root<tecmint j:P df 00,elp

Usage: df 9EP.IEN:))) 95ILE:))) S,o+ information a out t,e file s!stem on +,ic, eac, 5ILE resides' or all file s!stems ! default)

Mandator! arguments to long options are mandator! for s,ort options too) 0a' 00all include dumm! file s!stems

0?' 00 loc*0siVeNSITE use SITE0 !te loc*s 0,' 00,uman0reada le print siVes in ,uman reada le format /e)g)' %# &78M &W1 0J' 00si 0i' 00inodes 0* 0l' 00local 00no0s!nc 0P' 00porta ilit! 00s!nc 0t' 00t!peN.CPE 0.' 00print0t!pe li*e+ise' ut use po+ers of %((( not %(&8 list inode information instead of loc* usage li*e 00 loc*0siVeN%# limit listing to local file s!stems do not in-o*e s!nc efore getting usage info /default1 use t,e PESIX output format in-o*e s!nc efore getting usage info limit listing to file s!stems of t!pe .CPE print file s!stem t!pe

0x' 00exclude0t!peN.CPE limit listing to file s!stems not of t!pe .CPE 000,elp /ignored1 displa! t,is ,elp and exit

00-ersion output -ersion information and exit

SITE ma! e /or ma! e an integer optionall! follo+ed !1 one of follo+ing: *? %(((' # %(&8' M? %(((]%(((' M %(&8]%(&8' and so on for W' .' P' E' T' C)

$eport ugs to a ug0coreutils<gnu)orgb)

E@ CEMM"N@ IN UNIX "N@ LINUX EX"MPLES Sed is a Stream Editor used for modif!ing t,e files in unix /or linux1) >,ene-er !ou +ant to ma*e c,anges to t,e file automaticall!' sed comes in ,and! to do t,is) Most people ne-er learn its po+erY t,e! Must simpl! use sed to replace text) Cou can do man! t,ings apart from replacing text +it, sed) Jere I +ill descri e t,e features of sed +it, examples) Consider t,e elo+ text file as an input)

bcat file)txt unix is great os) unix is opensource) unix is free os) learn operating s!stem) unixlinux +,ic, one !ou c,oose)

SE@ CEMM"N@ EX"MPLES %) $eplacing or su stituting string Sed command is mostl! used to replace t,e text in a file) .,e elo+ simple sed command replaces t,e +ord XunixX +it, XlinuxX in t,e file)

bsed ^s/unix/linux/^ file)txt linux is great os) unix is opensource) unix is free os) learn operating s!stem) linuxlinux +,ic, one !ou c,oose) Jere t,e XsX specifies t,e su stitution operation) .,e X/X are delimiters) .,e XunixX is t,e searc, pattern and t,e XlinuxX is t,e replacement string) ?! default' t,e sed command replaces t,e first occurrence of t,e pattern in eac, line and it +on^t replace t,e second' t,ird)))occurrence in t,e line) &) $eplacing t,e nt, occurrence of a pattern in a line) Use t,e /%' /& etc flags to replace t,e first' second occurrence of a pattern in a line) .,e elo+ command replaces t,e second occurrence of t,e +ord XunixX +it, XlinuxX in a line)

bsed ^s/unix/linux/&^ file)txt unix is great os) linux is opensource) unix is free os) learn operating s!stem) unixlinux +,ic, one !ou c,oose) 7) $eplacing all t,e occurrence of t,e pattern in a line) .,e su stitute flag /g /glo al replacement1 specifies t,e sed command to replace all t,e occurrences of t,e string in t,e line)

bsed ^s/unix/linux/g^ file)txt linux is great os) linux is opensource) linux is free os) learn operating s!stem) linuxlinux +,ic, one !ou c,oose) 8) $eplacing from nt, occurrence to all occurrences in a line)

Use t,e com ination of /%' /& etc and /g to replace all t,e patterns from t,e nt, occurrence of a pattern in a line) .,e follo+ing sed command replaces t,e t,ird' fourt,' fift,))) XunixX +ord +it, XlinuxX +ord in a line)

bsed ^s/unix/linux/7g^ file)txt unix is great os) unix is opensource) linux is free os) learn operating s!stem) unixlinux +,ic, one !ou c,oose) 4) C,anging t,e slas, //1 delimiter Cou can use an! delimiter ot,er t,an t,e slas,) "s an example if !ou +ant to c,ange t,e +e url to anot,er url as

bsed ^s/,ttp:K/K//+++/^ file)txt In t,is case t,e url consists t,e delimiter c,aracter +,ic, +e used) In t,at case !ou ,a-e to escape t,e slas, +it, ac*slas, c,aracter' ot,er+ise t,e su stitution +on^t +or*) Using too man! ac*slas,es ma*es t,e sed command loo* a+*+ard) In t,is case +e can c,ange t,e delimiter to anot,er c,aracter as s,o+n in t,e elo+ example)

bsed ^sL,ttp://L+++L^ file)txt bsed ^sG,ttp://G+++G^ file)txt 3) Using c as t,e matc,ed string .,ere mig,t e cases +,ere !ou +ant to searc, for t,e pattern and replace t,at pattern ! adding some extra c,aracters to it) In suc, cases c comes in ,and!) .,e c represents t,e matc,ed string)

bsed ^s/unix/_c`/^ file)txt

_unix` is great os) unix is opensource) unix is free os) learn operating s!stem) _unix`linux +,ic, one !ou c,oose)

bsed ^s/unix/_cc`/^ file)txt _unixunix` is great os) unix is opensource) unix is free os) learn operating s!stem) _unixunix`linux +,ic, one !ou c,oose) 7) Using K%'K& and so on to K= .,e first pair of parent,esis specified in t,e pattern represents t,e K%' t,e second represents t,e K& and so on) .,e K%'K& can e used in t,e replacement string to ma*e c,anges to t,e source string) "s an example' if !ou +ant to replace t,e +ord XunixX in a line +it, t+ice as t,e +ord li*e XunixunixX use t,e sed command as elo+)

bsed ^s/K/unixK1/K%K%/^ file)txt unixunix is great os) unix is opensource) unix is free os) learn operating s!stem) unixunixlinux +,ic, one !ou c,oose) .,e parent,esis needs to e escaped +it, t,e ac*slas, c,aracter) "not,er example is if !ou +ant to s+itc, t,e +ords XunixlinuxX as XlinuxunixX' t,e sed command is

bsed ^s/K/unixK1K/linuxK1/K&K%/^ file)txt unix is great os) unix is opensource) unix is free os) learn operating s!stem) linuxunix +,ic, one !ou c,oose) "not,er example is s+itc,ing t,e first t,ree c,aracters in a line

bsed ^s/[K/)K1K/)K1K/)K1/K7K&K%/^ file)txt inux is great os) unix is opensource) unix is free os) aelrn operating s!stem) inuxlinux +,ic, one !ou c,oose) ;) @uplicating t,e replaced line +it, /p flag .,e /p print flag prints t,e replaced line t+ice on t,e terminal) If a line does not ,a-e t,e searc, pattern and is not replaced' t,en t,e /p prints t,at line onl! once)

bsed ^s/unix/linux/p^ file)txt linux is great os) unix is opensource) unix is free os) linux is great os) unix is opensource) unix is free os) learn operating s!stem) linuxlinux +,ic, one !ou c,oose) linuxlinux +,ic, one !ou c,oose) =) Printing onl! t,e replaced lines Use t,e 0n option along +it, t,e /p print flag to displa! onl! t,e replaced lines) Jere t,e 0n option suppresses t,e duplicate ro+s generated ! t,e /p flag and prints t,e replaced lines onl! one time)

bsed 0n ^s/unix/linux/p^ file)txt linux is great os) unix is opensource) unix is free os) linuxlinux +,ic, one !ou c,oose) If !ou use 0n alone +it,out /p' t,en t,e sed does not print an!t,ing)

%() $unning multiple sed commands) Cou can run multiple sed commands ! piping t,e output of one sed command as input to anot,er sed command)

bsed ^s/unix/linux/^ file)txtG sed ^s/os/s!stem/^ linux is great s!stem) unix is opensource) unix is free os) learn operating s!stem) linuxlinux +,ic, one !ou c,os!steme) Sed pro-ides 0e option to run multiple sed commands in a single sed command) .,e a o-e output can e ac,ie-ed in a single sed command as s,o+n elo+)

bsed 0e ^s/unix/linux/^ 0e ^s/os/s!stem/^ file)txt linux is great s!stem) unix is opensource) unix is free os) learn operating s!stem) linuxlinux +,ic, one !ou c,os!steme) %%) $eplacing string on a specific line num er) Cou can restrict t,e sed command to replace t,e string on a specific line num er) "n example is

bsed ^7 s/unix/linux/^ file)txt unix is great os) unix is opensource) unix is free os) learn operating s!stem) linuxlinux +,ic, one !ou c,oose) .,e a o-e sed command replaces t,e string onl! on t,e t,ird line) %&) $eplacing string on a range of lines)

Cou can specif! a range of line num ers to t,e sed command for replacing a string)

bsed ^%'7 s/unix/linux/^ file)txt linux is great os) unix is opensource) unix is free os) learn operating s!stem) linuxlinux +,ic, one !ou c,oose) Jere t,e sed command replaces t,e lines +it, range from % to 7) "not,er example is

bsed ^&'2 s/unix/linux/^ file)txt linux is great os) unix is opensource) unix is free os) learn operating s!stem) linuxlinux +,ic, one !ou c,oose) Jere 2 indicates t,e last line in t,e file) So t,e sed command replaces t,e text from second line to last line in t,e file) %7) $eplace on a lines +,ic, matc,es a pattern) Cou can specif! a pattern to t,e sed command to matc, in a line) If t,e pattern matc, occurs' t,en onl! t,e sed command loo*s for t,e string to e replaced and if it finds' t,en t,e sed command replaces t,e string)

bsed ^/linux/ s/unix/centos/^ file)txt unix is great os) unix is opensource) unix is free os) learn operating s!stem) centoslinux +,ic, one !ou c,oose) Jere t,e sed command first loo*s for t,e lines +,ic, ,as t,e pattern XlinuxX and t,en replaces t,e +ord XunixX +it, XcentosX)

%8) @eleting lines) Cou can delete t,e lines a file ! specif!ing t,e line num er or a range or num ers)

bsed ^& d^ file)txt bsed ^4'2 d^ file)txt %4) @uplicating lines Cou can ma*e t,e sed command to print eac, line of a file t+o times)

bsed ^p^ file)txt %3) Sed as grep command Cou can ma*e sed command to +or* as similar to grep command)

bgrep ^unix^ file)txt bsed 0n ^/unix/ p^ file)txt Jere t,e sed command loo*s for t,e pattern XunixX in eac, line of a file and prints t,ose lines t,at ,as t,e pattern) Cou can also ma*e t,e sed command to +or* as grep 0-' Must ! using t,e re-ersing t,e sed +it, NE. /e1)

bgrep 0- ^unix^ file)txt bsed 0n ^/unix/ ep^ file)txt .,e e ,ere in-erts t,e pattern matc,) %7) "dd a line after a matc,)

.,e sed command can add a ne+ line after a pattern matc, is found) .,e XaX command to sed tells it to add a ne+ line after a matc, is found)

bsed ^/unix/ a X"dd a ne+ lineX^ file)txt unix is great os) unix is opensource) unix is free os) X"dd a ne+ lineX learn operating s!stem) unixlinux +,ic, one !ou c,oose) X"dd a ne+ lineX %;) "dd a line efore a matc, .,e sed command can add a ne+ line efore a pattern matc, is found) .,e XiX command to sed tells it to add a ne+ line efore a matc, is found)

bsed ^/unix/ i X"dd a ne+ lineX^ file)txt X"dd a ne+ lineX unix is great os) unix is opensource) unix is free os) learn operating s!stem) X"dd a ne+ lineX unixlinux +,ic, one !ou c,oose) %=) C,ange a line .,e sed command can e used to replace an entire line +it, a ne+ line) .,e XcX command to sed tells it to c,ange t,e line)

bsed ^/unix/ c XC,ange lineX^ file)txt XC,ange lineX learn operating s!stem)

XC,ange lineX &() .ransform li*e tr command .,e sed command can e used to con-ert t,e lo+er case letters to upper case letters ! using t,e transform X!X option)

bsed ^!/ul/UL/^ file)txt Unix is great os) Unix is opensoUrce) Unix is free os) Learn operating s!stem) UnixLinUx +,ic, one !oU c,oose) Jere t,e sed command transforms t,e alp,a ets XulX into t,eir uppercase format XULX

.EP EX"MPLES E5 "># CEMM"N@ IN UNIX "+* is one of t,e most po+erful tools in Unix used for processing t,e ro+s and columns in a file) "+* ,as uilt in string functions and associati-e arra!s) "+* supports most of t,e operators' conditional loc*s' and loops a-aila le in C language) Ene of t,e good t,ings is t,at !ou can con-ert "+* scripts into Perl scripts using a&p utilit!) .,e asic s!ntax of ">#:

a+* ^?EWIN _startLaction` _action` EN@ _stopLaction`^ filename Jere t,e actions in t,e egin loc* are performed efore processing t,e file and t,e actions in t,e end loc* are performed after processing t,e file) .,e rest of t,e actions are performed +,ile processing t,e file) Examples:

Create a file inputLfile +it, t,e follo+ing data) .,is file can e easil! created using t,e output of ls 0l)

0r+0r00r00 % center center ( @ec ; &%:7= p% 0r+0r00r00 % center center %7 @ec ; &%:%4 t% 0r+0r00r00 % center center &3 @ec ; &%:7; t& 0r+0r00r00 % center center &4 @ec ; &%:7; t7 0r+0r00r00 % center center 87 @ec ; &%:7= t8 0r+0r00r00 % center center 8; @ec ; &%:7= t4 5rom t,e data' !ou can o ser-e t,at t,is file ,as ro+s and columns) .,e ro+s are separated ! a ne+ line c,aracter and t,e columns are separated ! a space c,aracters) >e +ill use t,is file as t,e input for t,e examples discussed ,ere) %) a+* ^_print 2%`^ inputLfile Jere 2% ,as a meaning) 2%' 2&' 27))) represents t,e first' second' t,ird columns))) in a ro+ respecti-el!) .,is a+* command +ill print t,e first column in eac, ro+ as s,o+n elo+)

0r+0r00r00 0r+0r00r00 0r+0r00r00 0r+0r00r00 0r+0r00r00 0r+0r00r00 .o print t,e 8t, and 3t, columns in a file use a+* ^_print 28'24`^ inputLfile Jere t,e ?egin and End loc*s are not used in a+*) So' t,e print command +ill e executed for eac, ro+ it reads from t,e file) In t,e next example +e +ill see ,o+ to use t,e ?egin and End loc*s) &) a+* ^?EWIN _sumN(` _sumNsum\24` EN@ _print sum`^ inputLfile

.,is +ill prints t,e sum of t,e -alue in t,e 4t, column) In t,e ?egin loc* t,e -aria le sum is assigned +it, -alue () In t,e next loc* t,e -alue of 4t, column is added to t,e sum -aria le) .,is addition of t,e 4t, column to t,e sum -aria le repeats for e-er! ro+ it processed) >,en all t,e ro+s are processed t,e sum -aria le +ill ,old t,e sum of t,e -alues in t,e 4t, column) .,is -alue is printed in t,e End loc*) 7) In t,is example +e +ill see ,o+ to execute t,e a+* script +ritten in a file) Create a file sumLcolumn and paste t,e elo+ script in t,at file

Pe/usr/ in/a+* 0f ?EWIN _sumN(` _sumNsum\24` EN@ _print sum` No+ execute t,e t,e script using a+* command as a+* 0f sumLcolumn inputLfile) .,is +ill run t,e script in sumLcolumn file and displa!s t,e sum of t,e 4t, column in t,e inputLfile) 8) a+* ^_ if/2= NN Xt8X1 print 2(Y`^ inputLfile .,is a+* command c,ec*s for t,e string Xt8X in t,e =t, column and if it finds a matc, t,en it +ill print t,e entire line) .,e output of t,is a+* command is

0r+0r00r00 % pcenter pcenter 87 @ec ; &%:7= t8 4) a+* ^?EWIN _ for/iN%YiaN4Yi\\1 print XsDuare ofX' i' XisX'i]iY `^ .,is +ill print t,e sDuares of first num ers from % to 4) .,e output of t,e command is

sDuare of % is % sDuare of & is 8

sDuare of 7 is = sDuare of 8 is %3 sDuare of 4 is &4 Notice t,at t,e s!ntax of FifH and FforH are similar to t,e C language) "+* ?uilt in Saria les: Cou ,a-e alread! seen 2(' 2%' 2&))) +,ic, prints t,e entire line' first column' second column))) respecti-el!) No+ +e +ill see ot,er uilt in -aria les +it, examples) 5S 0 Input field separator -aria le: So far' +e ,a-e seen t,e fields separted ! a space c,aracter) ?! default "+* assumes t,at fields in a file are separted ! space c,aracters) If t,e fields in t,e file are separted ! an! ot,er c,aracter' +e can use t,e 5S -aria le to tell a out t,e delimiter) 3) a+* ^?EWIN _5SNX:X` _print 2&`^ inputLfile E$ a+* 05: ^_print 2&` inputLfile .,is +ill print t,e result as 7= p% %4 t% 7; t& 7; t7 7= t8 7= t4 E5S 0 Eutput field separator -aria le: ?! default +,ene-er +e printed t,e fields using t,e print statement t,e fields are displa!ed +it, space c,aracter as delimiter) 5or example 7) a+* ^_print 28'24`^ inputLfile

.,e output of t,is command +ill e

center ( center %7 center &3 center &4 center 87 center 8; >e can c,ange t,is default e,a-ior using t,e E5S -aria le as a+* ^?EWIN _E5SNX:X` _print 28'24`^ inputLfile

center:( center:%7 center:&3 center:&4 center:87 center:8; Note: print 28'24 and print 2824 +ill not +or* t,e same +a!) .,e first one displa!s t,e output +it, space as delimiter) .,e second one displa!s t,e output +it,out an! delimiter) N5 0 Num er of fileds -aria le: .,e N5 can e used to *no+ t,e num er of fields in line ;) a+* ^_print N5`^ inputLfile .,is +ill displa! t,e num er of columns in eac, ro+) N$ 0 num er of records -aria le: .,e N$ can e used to *no+ t,e line num er or count of lines in a file)

=) a+* ^_print N$`^ inputLfile .,is +ill displa! t,e line num ers from %) %() a+* ^EN@ _print N$`^ inputLfile .,is +ill displa! t,e total num er of lines in t,e file) String functions in "+*: Some of t,e string functions in a+* are: index/string'searc,1 lengt,/string1 split/string'arra!'separator1 su str/string'position1 su str/string'position'max1 tolo+er/string1 toupper/string1 "d-anced Examples: %) 5iltering lines using "+* split function .,e a+* split function splits a string into an arra! using t,e delimiter) .,e s!ntax of split function is split/string' arra!' delimiter1 No+ +e +ill see ,o+ to filter t,e lines using t,e split function +it, an example) .,e input Xfile)txtX contains t,e data in t,e follo+ing format

% U'N'UNIX'((( & N'P'SJELL'%%% 7 I'M'UNIX'&&& 8 X'C'?"SJ'777 4 P'$'SC$IP.'888 $eDuired output: No+ +e ,a-e to print onl! t,e lines in +,ic, +,ose &nd field ,as t,e string XUNIXX as t,e 7rd field/ .,e &nd filed in t,e line is separated ! comma delimiter 1) .,e ouptut is:

% U'N'UNIX'((( 7 I'M'UNIX'&&& .,e a+* command for getting t,e output is:

a+* ^_ split/2&'arr'X'X1Y if/arr97: NN XUNIXX1 print 2( ` ^ file)txt Linux Cronta : %4 "+esome Cron Uo Examples ! S".JIC"MEE$.JC on UUNE %%' &((=

"n experienced Linux s!sadmin *no+s t,e importance of running t,e routine maintenance Mo s in t,e ac*ground automaticall!) Linux Cron utilit! is an effecti-e +a! to sc,edule a routine ac*ground Mo at a specific time and/or da! on an on0going asis) .,is article is part of t,e on0going Producti-it! .ips 5or Wee*s series) In t,is article' let us re-ie+ %4 a+esome examples of cronta Mo sc,eduling)

Linux Cronta 5ormat MIN JEU$ @EM MEN @E> CM@ .a le: Cronta 5ields and "llo+ed $anges /Linux Cronta S!ntax1 5ield MIN @escription Minute field "llo+ed Salue ( to 4= ( to &7 %07% %0%& (03 "n! command to e executed)

JEU$ Jour field @EM @a! of Mont, MEN Mont, field @E> @a! Ef >ee* CM@ Command

%) Sc,eduling a Uo 5or a Specific .ime .,e asic usage of cron is to execute a Mo in a specific time as s,o+n elo+) .,is +ill execute t,e 5ull ac*up s,ell script /full0 ac*up1 on %(t, Uune (;:7( "M) Please note t,at t,e time field uses &8 ,ours format) So' for ; "M use ;' and for ; PM use &() 7( (; %( (3 ] /,ome/rames,/full0 ac*up 7( I 7(t, Minute (; I (; "M %( I %(t, @a! (3 I 3t, Mont, /Uune1 ] I E-er! da! of t,e +ee* &) Sc,edule a Uo 5or More .,an Ene Instance /e)g) .+ice a @a!1 .,e follo+ing script ta*e a incremental ac*up t+ice a da! e-er! da!) .,is example executes t,e specified incremental ac*up s,ell script /incremental0 ac*up1 at %%:(( and %3:(( on e-er! da!) .,e comma separated -alue in a field specifies t,at t,e command needs to e executed in all t,e mentioned time)

(( %%'%3 ] ] ] /,ome/rames,/ in/incremental0 ac*up (( I (t, Minute /.op of t,e ,our1 %%'%3 I %% "M and 8 PM ] I E-er! da! ] I E-er! mont, ] I E-er! da! of t,e +ee* 7) Sc,edule a Uo for Specific $ange of .ime /e)g) Enl! on >ee*da!s1 If !ou +anted a Mo to e sc,eduled for e-er! ,our +it, in a specific range of time t,en use t,e follo+ing) Cron Uo e-er!da! during +or*ing ,ours .,is example c,ec*s t,e status of t,e data ase e-er!da! /including +ee*ends1 during t,e +or*ing ,ours = a)m I 3 p)m (( (=0%; ] ] ] /,ome/rames,/ in/c,ec*0d 0status (( I (t, Minute /.op of t,e ,our1 (=0%; I = am' %( am'%% am' %& am' % pm' & pm' 7 pm' 8 pm' 4 pm' 3 pm ] I E-er! da! ] I E-er! mont, ] I E-er! da! of t,e +ee* Cron Uo e-er! +ee*da! during +or*ing ,ours .,is example c,ec*s t,e status of t,e data ase e-er! +ee*da! /i)e excluding Sat and Sun1 during t,e +or*ing ,ours = a)m I 3 p)m) (( (=0%; ] ] %04 /,ome/rames,/ in/c,ec*0d 0status (( I (t, Minute /.op of t,e ,our1 (=0%; I = am' %( am'%% am' %& am' % pm' & pm' 7 pm' 8 pm' 4 pm' 3 pm ] I E-er! da! ] I E-er! mont, %04 0Mon' .ue' >ed' .,u and 5ri /E-er! >ee*da!1 8) Jo+ to Sie+ Cronta Entries6

Sie+ Current Logged0In UserBs Cronta entries .o -ie+ !our cronta entries t!pe cronta 0l from !our unix account as s,o+n elo+) rames,<de-0d 2 cronta 0l <!earl! /,ome/rames,/annual0maintenance ]/%( ] ] ] ] /,ome/rames,/c,ec*0dis*0space

9Note: .,is displa!s cronta of t,e current logged in user: Sie+ $oot Cronta entries Login as root user /su I root1 and do cronta 0l as s,o+n elo+) root<de-0d P cronta 0l no cronta for root Cronta Jo+.o: Sie+ Et,er Linux UserBs Cronta s entries .o -ie+ cronta entries of ot,er Linux users' login to root and use 0u _username` 0l as s,o+n elo+) root<de-0d P cronta 0u sat,i!a 0l <mont,l! /,ome/sat,i!a/mont,l!0 ac*up (( (=0%; ] ] ] /,ome/sat,i!a/c,ec*0d 0status 4) Jo+ to Edit Cronta Entries6 Edit Current Logged0In UserBs Cronta entries .o edit a cronta entries' use cronta 0e as s,o+n elo+) ?! default t,is +ill edit t,e current logged0in users cronta ) rames,<de-0d 2 cronta 0e <!earl! /,ome/rames,/centos/ in/annual0maintenance ]/%( ] ] ] ] /,ome/rames,/de ian/ in/c,ec*0dis*0space j X/tmp/cronta )XXXX!M>*J+X &L' ;7C

9Note: .,is +ill open t,e cronta file in Sim editor for editing) Please note cron created a temporar! /tmp/cronta )XX))) : >,en !ou sa-e t,e a o-e temporar! file +it, :+D' it +ill sa-e t,e cronta and displa! t,e follo+ing message indicating t,e cronta is successfull! modified) j Xcronta )XXXX!M>*J+X &L' ;7C +ritten cronta : installing ne+ cronta Edit $oot Cronta entries Login as root user /su I root1 and do cronta 0e as s,o+n elo+) root<de-0d P cronta 0e Edit Et,er Linux UserBs Cronta 5ile entries .o edit cronta entries of ot,er Linux users' login to root and use 0u _username` 0e as s,o+n elo+) root<de-0d P cronta 0u sat,i!a 0e <mont,l! /,ome/sat,i!a/fedora/ in/mont,l!0 ac*up (( (=0%; ] ] ] /,ome/sat,i!a/u untu/ in/c,ec*0d 0status j j j X/tmp/cronta )XXXX!M>*J+X &L' ;7C 3) Sc,edule a Uo for E-er! Minute Using Cron) Ideall! !ou ma! not ,a-e a reDuirement to sc,edule a Mo e-er! minute) ?ut understanding t,is example +ill +ill ,elp !ou understand t,e ot,er examples mentioned elo+ in t,is article) ] ] ] ] ] CM@ .,e ] means all t,e possi le unit k i)e e-er! minute of e-er! ,our t,roug, out t,e !ear) More t,an using t,is ] directl!' !ou +ill find it -er! useful in t,e follo+ing cases) >,en !ou specif! ]/4 in minute field means e-er! 4 minutes) >,en !ou specif! (0%(/& in minute field mean e-er! & minutes in t,e first %( minute)

.,us t,e a o-e con-ention can e used for all t,e ot,er 8 fields) 7) Sc,edule a ?ac*ground Cron Uo 5or E-er! %( Minutes) Use t,e follo+ing' if !ou +ant to c,ec* t,e dis* space e-er! %( minutes) ]/%( ] ] ] ] /,ome/rames,/c,ec*0dis*0space It executes t,e specified command c,ec*0dis*0space e-er! %( minutes t,roug, out t,e !ear) ?ut !ou ma! ,a-e a reDuirement of executing t,e command onl! during office ,ours or -ice -ersa) .,e a o-e examples s,o+s ,o+ to do t,ose t,ings) Instead of specif!ing -alues in t,e 4 fields' +e can specif! it using a single *e!+ord as mentioned elo+) .,ere are special cases in +,ic, instead of t,e a o-e 4 fields !ou can use < follo+ed ! a *e!+ord k suc, as re oot' midnig,t' !earl!' ,ourl!) .a le: Cron special *e!+ords and its meaning #e!+ord <!earl! <dail! <,ourl! <re oot EDui-alent ((%%] ((]]] (]]]] $un at startup)

;) Sc,edule a Uo 5or 5irst Minute of E-er! Cear using <!earl! If !ou +ant a Mo to e executed on t,e first minute of e-er! !ear' t,en !ou can use t,e <!earl! cron *e!+ord as s,o+n elo+) .,is +ill execute t,e s!stem annual maintenance using annual0maintenance s,ell script at ((:(( on Uan %st for e-er! !ear) <!earl! /,ome/rames,/red0,at/ in/annual0maintenance =) Sc,edule a Cron Uo ?eginning of E-er! Mont, using <mont,l! It is as similar as t,e <!earl! as a o-e) ?ut executes t,e command mont,l! once using <mont,l!cron *e!+ord) .,is +ill execute t,e s,ell script tape0 ac*up at ((:(( on %st of e-er! mont,) <mont,l! /,ome/rames,/suse/ in/tape0 ac*up

%() Sc,edule a ?ac*ground Uo E-er! @a! using <dail! Using t,e <dail! cron *e!+ord' t,is +ill do a dail! log file cleanup using cleanup0logs s,ell scriptat ((:(( on e-er! da!) <dail! /,ome/rames,/arc,0linux/ in/cleanup0logs Xda! startedX %%) Jo+ to Execute a Linux Command "fter E-er! $e oot using <re oot6 Using t,e <re oot cron *e!+ord' t,is +ill execute t,e specified command once after t,e mac,ine got ooted e-er! time) <re oot CM@ %&) Jo+ to @isa le/$edirect t,e Cronta Mail Eutput using M"IL *e!+ord6 ?! default cronta sends t,e Mo output to t,e user +,o sc,eduled t,e Mo ) If !ou +ant to redirect t,e output to a specific user' add or update t,e M"IL -aria le in t,e cronta as s,o+n elo+) rames,<de-0d 2 cronta 0l M"ILNXrames,X

<!earl! /,ome/rames,/annual0maintenance ]/%( ] ] ] ] /,ome/rames,/c,ec*0dis*0space

9Note: Cronta of t,e current logged in user +it, M"IL -aria le: If !ou +anted t,e mail not to e sent to an!+,ere' i)e to stop t,e cronta output to e emailed' add or update t,e M"IL -aria le in t,e cronta as s,o+n elo+) M"ILNXX %7) Jo+ to Execute a Linux Cron Uo s E-er! Second Using Cronta ) Cou cannot sc,edule a e-er!0second cronMo ) ?ecause in cron t,e minimum unit !ou can specif! is minute) In a t!pical scenario' t,ere is no reason for most of us to run an! Mo e-er! second in t,e s!stem) %8) Specif! P".J Saria le in t,e Cronta "ll t,e a o-e examples +e specified a solute pat, of t,e Linux command or t,e s,ell0script t,at needs to e executed)

5or example' instead of specif!ing /,ome/rames,/tape0 ac*up' if !ou +ant to Must specif! tape0 ac*up' t,en add t,e pat, /,ome/rames, to t,e P".J -aria le in t,e cronta as s,o+n elo+) rames,<de-0d 2 cronta 0l

P".JN/ in:/s in:/usr/ in:/usr/s in:/,ome/rames,

<!earl! annual0maintenance ]/%( ] ] ] ] c,ec*0dis*0space

9Note: Cronta of t,e current logged in user +it, P".J -aria le: %4) Installing Cronta 5rom a Cron 5ile Instead of directl! editing t,e cronta file' !ou can also add all t,e entries to a cron0file first) Ence !ou ,a-e all t,oese entries in t,e file' !ou can upload or install t,em to t,e cron as s,o+n elo+) rames,<de-0d 2 cronta 0l no cronta for rames,

2 cat cron0file)txt <!earl! /,ome/rames,/annual0maintenance ]/%( ] ] ] ] /,ome/rames,/c,ec*0dis*0space

rames,<de-0d 2 cronta cron0file)txt

rames,<de-0d 2 cronta 0l <!earl! /,ome/rames,/annual0maintenance ]/%( ] ] ] ] /,ome/rames,/c,ec*0dis*0space Note: .,is +ill install t,e cron0file)txt to !our cronta ' +,ic, +ill also remo-e !our old cron entries) So' please e careful +,ile uploading cron entries from a cron0file)txt)

Das könnte Ihnen auch gefallen