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
1 day 16 hours ago
1 day 18 hours ago
2 days 6 hours ago
2 days 9 hours ago
2 days 13 hours ago
2 days 19 hours ago
3 days 5 hours ago
3 days 7 hours ago
3 days 15 hours ago
3 days 16 hours ago