7 Linux operators you should know about
Tags: linux
Published: 2020-04-01 12:03:08

---
title: 7 Linux operators you should know about
published: true
description: In today's post, We talk about Linux operators everyone using a command line should know.
tags: Linux
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/klsi9vwpgwmhg2bidclv.png
---

Hey devs from all over the world 😊

Okay! I know I am a Frontend developer, but I really like Linux. Just hear me out!

Today, I want to tell you guys about some Linux shell operators that you absolutely can't live without while chaining commands. 🤯

Going forward, we need an example of a command to explain the operators on. Due to our current situation and my absolute hatred, I am using this one :

``` shell
    kill covid19 --force 
```

I know it won't work! but, maybe because no one tried it before. 🙄

Let's dive right in, 🌊


## Are you after the output?

Starting off, We have the write operator `>` This one is used to write the output to a file. For example,

``` shell
    kill covid19 --force > res.txt
```

Wait a sec! This `>` will overwrite the content of the file. If you care about `res.txt` you will have to use the append `>>` operator which will append the output to the content of the file.

Actually, The output operator `>` is just a shorthand for `1>`  

Is there a `2>`? Yes! 

Is there a `3>`? Don't get carried away!✋  

`1>` is for standard program output, while `2>` is for error output. For example,

``` shell
    kill covid19 --force 1> res.txt 2> err.txt
```


## What if your program requires some input file?

I know you guessed it! Just flip it over `<`

``` shell
    kill covid19 --force < doctorsList.txt
```


## One command is not enough.

Okay, Let's say it's not that easy. What if we need more? You can chain commands one after the other using the AND operator `&&` like this :

``` shell
    kill covid19 --force && rebuild
```

This `&&` is an AND operator. It will only run the next program **if** the previous one exited successfully. 

We also have an OR operator `||`

``` shell
    kill covid19 || (I honestly don't know what to write here! 🤯)
```

This one will only run the next program **if** the previous one failed ( Let's hope It doesn't ).


## Is that it?

No! We still have more.

Killing covid19 is gonna take some time 😔 We can use the ampersand `&` at the end to make it run in the background. Leaving the terminal free to run any other programs like this :

``` shell
    kill covid19 & 
```

Wait! I am saving the best for last. The most awesome pipe operator `|` This one can pass the output of one program to the next. Let's try to count the number of lines killing covid19 will output. (cause why not!)

``` shell
    kill covid19 | wc -l
```

That's it for now. If you guys liked it, please let me know down in the comments section.

You could also check my `Know Your Linux` series here on dev.to.
{% link https://dev.to/bassemmohamed/know-your-linux-01-directory-structure-ad6 %}

Also, I have a small recommendation -unpaid- for you guys, I have been hacking away my quarantine days and you could too. Check out [tryhackme.com](http://tryhackme.com). It is super cool!

If you want to know more or if you would like a hacking wingman, hit me up on discord at `Bassem Mohamed#3921`

As always,
**Happy coding 🔥🔥**
**“كود بسعادة”**