Cool way of sharing your Linux terminal session with named pipe/FIFO

Cool way of sharing your Linux terminal session with named pipe/FIFO

's avatar
Bobby Iliev ・July 5, 2020
2 minute read ・Updated January 22, 2021

Introduction

In Linux and other Unix systems, a pipe is a way of redirecting the output of one command or a process to another. This is also known as an unnamed pipe. For example, you could combine the following two commands:

ls -lah | grep some_string

With the above command, you would forward the output of the ls -lah command to a grep command, which will search for some_string.

A named pipe on the other side is an extension of the traditional pipe concept. Names pipes are also known as FIFO, which stands for First In, First Out. The named pipes are actually files on the file system itself.

You can tell if a file is a named pipe by the p bit in the file permissions section.

prw-r--r-- 1 root root 0 Jul  4 19:17 file_name

Or you could use the file command to check the type of the file:

file file_name
file_name: fifo (named pipe)

In this tutorial, I'll show you how you could use named pipes to share your screen, without using any software like Zoom or Google Hangouts, with one of your students or co-workers!

Prerequisites

You and the person that you want to share your screen with would need to have access to the same Linux machine via SSH for example.

You could use a DigitalOcean Droplet to achieve that.

You can use my referral link to get a free $100 credit that you could use to deploy your virtual machines and test the guide yourself on a few DigitalOcean servers:

Checkout our latest product - the ultimate tailwindcss page creator 🚀

DigitalOcean $100 Free Credit

Creating a named pipe (FIFOs)

Let's first start by creating a named pipe on your Linux machine.

You can create named pipes (FIFOs) by using the mkfifo command.

The syntax that you would need to use is:

mkfifo file_name

After that if you run ls -l you will see the following output:

prw-r--r-- 1 root root 0 Jul  4 19:17 file_name

Start sharing your terminal session

In order to achieve the sharing effect, we will use the script command.

The script command is a tool that lets you records your terminal session. Once you have your named pipe ready, all you need to do is run the following script command:

script -f file_name

After that, without closing your current session, open a second terminal session, or ask the person that you would like to share your terminal session with, to just use the cat command followed by your FIFO:

cat file_file

Once you have that ready, whatever you run on your main screen will be outputted on the second screen in real-time!

Here is a quick video example:

Conclusion

This is a cool way of using named pipes to share your terminal session with a colleague that you are working with or with a student without having to deal with the video delays of conference apps!

Hope that this helps you and you get to have some fun with it!

Bobby

Comments (0)