HOME ABOUT CONTACT ARTICLES

Special Chars: Command Group ()


Pipes pass the output (stdout) of a previous command to the input (stdin) of the next one, or to the shell.
This is a method of chaining commands together.

Examples

Encode a string in Base64

To encode something in Base64, we pipe the output with the command base64

# 'echo "Luke Pritchard"' will simply set 'Luke Pritchard' to be the output
# 'base64' takes the output 'Luke Pritchard' and encodes it in Base64
echo "Luke Pritchard" | base64

As an example:

luke@nebulae:~$ echo "Luke Pritchard" | base64
 THVrZSBQcml0Y2hhcmQK


Filter files in a directory

To encode something in Base64, we pipe the output with the command base64

# 'ls' will simply return all files in the directory to be the output
# 'grep ".html"' filters through the output and matching anything that contains '.html'
ls | grep ".html"

As an example:

ls | grep ".html"
 index.html
 error.html
 aritcles.html

Filter files in a directory, sorted by file size

To encode something in Base64, we pipe the output with the command base64

# 'ls -s' will simply return all files in the directory to be the output and its file size
# 'grep ".jpg"' filters through the output and matching anything that contains '.jpg'
# 'sort' sorts the text in ascending order
ls -s | grep ".jpg" | sort

As an example:

ls -s | grep ".jpg" | sort
 48 icon.jpg
 56 me.jpg
 92 background.jpg