View Single Post
Old 4th April 2007, 15:50
drks drks is offline
Junior Member
Join Date: Aug 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts

Originally Posted by ckp212002

i am a newbie too, can u pls explain the following line:

DST_BYTES=`du -cbs $DST_DIR | awk '/total/ {print $1}'`


Certainly. Let me break this down:

DST_BYTES -> The variable we are setting. In Bash scripts you do not set a variable with the leading '$', however you do reference it as '$DST_BYTES' after you set.

`` -> The Backtick '`' (the one on the same key as tilde '~') signifies the execution of code. Bash will spawn a sub-shell, and anything within the back ticks will be executed. The output of the command is sent back, and becomes the value of our variable 'DST_BYTES'.

du -cbs $DST_DIR -> The 'du' bash command is used to show 'disk usage'. Therefore we are checking the disk usage of the directory $DST_DIR.

| -> The Bash pipe operator '|' (on the same key as the backspace) is used to pipe the output of the first command, and send it as arguments of the next command (awk).

awk '/total/ {print $1}' -> Awk is a beast to grand to explain in a simple one liner. However this command is doing a regular expression match for the line that has 'total' in it. Once it has that line, it prints the first ($1) word in that line.
drks -
Reply With Quote