Quote:
|
Originally Posted by ckp212002
themachine,
i am a newbie too, can u pls explain the following line:
DST_BYTES=`du -cbs $DST_DIR | awk '/total/ {print $1}'`
thanks
|
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.
Recent comments
5 hours 21 min ago
14 hours 48 min ago
15 hours 38 min ago
19 hours 11 min ago
23 hours 35 min ago
23 hours 57 min ago
1 day 2 hours ago
1 day 12 hours ago
1 day 17 hours ago
1 day 18 hours ago