Hi again UNIX shell lovers, as we saw in our [last course](https://steemit.com/linux/@imil/command-line-101-feel-the-power-of-the-unix-shell), a _shell command_ outputs non-errors messages to a special file called `stdout`, which number is `1` and reads from another special file called `stdin` which number is `0`. Error messages are sent to `stderr` which number is `2`. To be clear, this means that the following command: ``` $ ls . .. foo bar baz ``` displayed its result to the special file `stdout`, or `1`. This output can actually be _captured_ by another program by using the `|` (pipe) symbol. To illustrate its usage, we will use the `grep` command, which filters the output by matching a _pattern_. For example, if I would like to output only the lines that contain the word `match` in a file called `myfile.txt`, I would do: ``` $ grep match myfile.txt beautiful match matching those matches ``` Instead of using a file as the input stream, we could use `stdout` from a previous command, which the `|` (pipe) command will transform to `grep`'s `stdin`! ``` $ echo 'I like to move it move it'|grep 'move' I like to move it move it $ echo 'this phrase won't match'|grep 'not present' ``` Think of `|` as a convenient way of filtering big outputs, for example you could very easily see if a directory contains a `.jpg` file by using `|grep '\.jpg'`. We won't go deep into `grep` patterns just yet to keep those courses nice and short :) In our next shell tip, we will speak about redirections. Stay tuned! Read more about standard streams in [Wikipedia's very well written documentation](https://en.wikipedia.org/wiki/Standard_streams).
author | imil |
---|---|
permlink | hack-like-a-pro-shell-pipe |
category | linux |
json_metadata | {"tags":["linux","hack","technology","tips"],"links":["https://steemit.com/linux/@imil/command-line-101-feel-the-power-of-the-unix-shell","https://en.wikipedia.org/wiki/Standard_streams"],"app":"steemit/0.1","format":"markdown"} |
created | 2017-06-29 14:46:27 |
last_update | 2017-06-29 14:46:27 |
depth | 0 |
children | 4 |
last_payout | 2017-07-06 14:46:27 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 1,657 |
author_reputation | 1,720,929,270 |
root_title | "Hack like a pro: shell `pipe`" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 6,632,258 |
net_rshares | 2,336,439,190 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
mikeill | 0 | 1,175,741,756 | 100% | ||
imil | 0 | 1,160,697,434 | 100% | ||
cosmicboy123 | 0 | 0 | 100% |
Very cool. I'm always using grep to search recursively: `grep -r 'something' somedirectory` so thanks for the reminder you can use it on a single file. I also like to use it to filter results of find: `ls -l | grep '2017'` Would be files from this year in the current directory. Following you.
author | mikeill |
---|---|
permlink | re-imil-hack-like-a-pro-shell-pipe-20170629t151116622z |
category | linux |
json_metadata | {"tags":["linux"],"app":"steemit/0.1"} |
created | 2017-06-29 15:11:15 |
last_update | 2017-06-29 15:12:39 |
depth | 1 |
children | 2 |
last_payout | 2017-07-06 15:11:15 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 297 |
author_reputation | 411,190,612,143 |
root_title | "Hack like a pro: shell `pipe`" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 6,635,264 |
net_rshares | 1,143,286,972 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
imil | 0 | 1,143,286,972 | 100% |
Thanks @mikeill, I'll eventually get to more difficult scenarios, my first target here are less fluent linux/unix users, I'd like to make them love the CLI ;) but comments from more educated users are really welcome too! Following you back
author | imil |
---|---|
permlink | re-mikeill-re-imil-hack-like-a-pro-shell-pipe-20170629t151529805z |
category | linux |
json_metadata | {"tags":["linux"],"users":["mikeill"],"app":"steemit/0.1"} |
created | 2017-06-29 15:15:30 |
last_update | 2017-06-29 15:16:54 |
depth | 2 |
children | 1 |
last_payout | 2017-07-06 15:15:30 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 239 |
author_reputation | 1,720,929,270 |
root_title | "Hack like a pro: shell `pipe`" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 6,635,865 |
net_rshares | 1,258,810,467 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
mikeill | 0 | 1,258,810,467 | 100% |
Sweet. See you around.
author | mikeill |
---|---|
permlink | re-imil-re-mikeill-re-imil-hack-like-a-pro-shell-pipe-20170630t121816540z |
category | linux |
json_metadata | {"tags":["linux"],"app":"steemit/0.1"} |
created | 2017-06-30 12:18:15 |
last_update | 2017-06-30 12:18:15 |
depth | 3 |
children | 0 |
last_payout | 2017-07-07 12:18:15 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 22 |
author_reputation | 411,190,612,143 |
root_title | "Hack like a pro: shell `pipe`" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 6,753,403 |
net_rshares | 0 |
Congratulations @imil! You have completed some achievement on Steemit and have been rewarded with new badge(s) : [](http://steemitboard.com/@imil) Award for the number of posts published Click on any badge to view your own Board of Honnor on SteemitBoard. For more information about SteemitBoard, click [here](https://steemit.com/@steemitboard) If you no longer want to receive notifications, reply to this comment with the word `STOP` By upvoting this notification, you can help all Steemit users. Learn how [here](https://steemit.com/steemitboard/@steemitboard/http-i-cubeupload-com-7ciqeo-png)!
author | steemitboard |
---|---|
permlink | steemitboard-notify-imil-20170630t171150000z |
category | linux |
json_metadata | {"image":["https://steemitboard.com/img/notifications.png"]} |
created | 2017-06-30 17:11:48 |
last_update | 2017-06-30 17:11:48 |
depth | 1 |
children | 0 |
last_payout | 2017-07-07 17:11:48 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 685 |
author_reputation | 38,975,615,169,260 |
root_title | "Hack like a pro: shell `pipe`" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 6,785,933 |
net_rshares | 1,160,697,434 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
imil | 0 | 1,160,697,434 | 100% |