857011d3f5
git-svn-id: svn+ssh://atelier.inf.usi.ch/home/bevilj/group-1@234 a672b425-5310-4d7a-af5c-997e18724b81
40 lines
1 KiB
HTML
40 lines
1 KiB
HTML
---
|
|
layout: page
|
|
author: Domenico Votta
|
|
category-page: advanced
|
|
category-title: Advanced commands
|
|
tags: pipes redirect output input
|
|
title: Pipes
|
|
---
|
|
|
|
The <code>pipes</code> that in the shell are representend with the symbol | ,
|
|
they are used to join two commands on the terminal, taking the output of the first
|
|
command and using it as input of the second.<br>
|
|
It is usually common to see the command <code>grep</code> and <code>ps</code> together,
|
|
an example below.<br>
|
|
|
|
Example: lists all processes with your username
|
|
<pre>
|
|
ps aux | grep user
|
|
</pre>
|
|
|
|
Example: count the lines of a file, using the
|
|
<a href="{{ site.baseurl }}/pages/cmd/advanced/nl.html">nl</a> command
|
|
<pre>
|
|
cat example1.txt | nl
|
|
1 Car
|
|
2 Computer
|
|
3 Robot
|
|
4 Smartphone
|
|
5 Videogame
|
|
</pre>
|
|
|
|
Example: passing expressions to <a href="{{ site.baseurl }}/pages/cmd/advanced/bc.html">bc</a>
|
|
to do calculations
|
|
<pre>
|
|
echo "(12 / 2 - 3) * 3 + 1.5" | bc
|
|
10.5
|
|
</pre>
|
|
|
|
You can use the commands that you learned and put them together, always
|
|
respecting the logic of the command.
|