Should I use Linux as a developer?

Payam Saderi
5 min readFeb 24, 2023

--

In this article, the term “Linux” refers to any of its distributions, which are operating systems based on Unix.

When I started writing this post, my wife Nasrin saw the title and commented:

No, It depends on what you’re developing.

However, in my opinion, it doesn’t matter whether you’re a back-end, front-end, or mobile developer. These days, a significant proportion of applications are deployed on Unix-based operating systems.

It’s important to note that you don’t have to use GNU/Linux as your desktop operating system. However, there are many benefits to knowing and being familiar with it.

In this post, we’ll explore why Linux is an essential tool for developers and how it can help you in your work.

File system ( Where are my files going ? )

At first glance, this may seem unnecessary, but knowing where your files are located and how the information is stored is very important. Knowing Linux’s file system gives you this vision.

https://en.wikipedia.org/wiki/Unix_filesystem

For example, if we save files in the /tmp path during the process, it is better to delete them after finishing the work. But why? Because usually, all programs can read and write to /tmp, so sensitive information may be read by other programs.

Here, I’ve just mentioned one simple example. If you dive deeper into this, you can find too many things.

Permissions ( To be, or not to be )

I’m sure many times you’ve encountered permission errors when trying to run a script, and the simplest way to fix the problem is chmod 777 , But what is this magic number? Where does it come from?

If you know how the permission and ownership of files and folders work in Linux, then you can use a more appropriate option instead of using 777. For example, you can use chown www-data

The best reference for this is: https://learning.lpi.org/en/learning-materials/101-500/104/104.5/104.5_01/

CLI ( My name is Neo )

When talking about the command-line interface (CLI), the first thing that may come to mind is The Matrix movie. You have to figure it all out just by looking at a black screen with green text, but the good news is it’s not true.

https://nmap.org/movies/

All the tools we use for programming have a CLI version. Yes, I know almost all of them have a graphical user interface (GUI) version too. In fact, the GUI executes the CLI commands in the background and shows you the result. But let’s take a look at the advantages of CLI:

Efficiency: CLI is often faster and more efficient than GUI, especially for experienced users. With CLI, you can quickly perform complex tasks with a few keystrokes, while GUI requires multiple clicks and navigation through menus and tabs.

Flexibility: CLI provides greater flexibility and control over the system. You can perform more advanced tasks and customize the system to your needs, whereas GUI limits you to predefined options.

Automation: CLI allows for easy automation of repetitive tasks, which can save time and effort. You can use bash scripts to automate tasks, whereas in GUI you can do it if its allow you.

With CLI you have full power and you can do anything you want !

Bash Scripts ( These is no Spoon )

Bash scripts are shell programs that use the Bash shell language to automate and execute commands, with the ability to incorporate control flow statements such as conditions and loops for conditional execution and repetition of commands.

For example, I want to know how many IPs are currently sending requests to my server via HTTP and HTTPS, for this I use the following set of commands.

netstat -anp | grep ':80\|:443' | awk '{print $5}' \
| cut -d: -f1 | sort | uniq -c | sort -n | wc -l

In the code above I used 7 different programs to get the result I wanted, Now we can put this code in a bash, This script will check the number of IPs connected to the server and send a message to slack if the number is greater than 500

#!/bin/bash


SLACK_CHANNEL='https://hooks.slack.com/services/XXXXXXXXXXXXXXXXX'
IP_COUNT=$(netstat -anp | grep ':80\|:443' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n | wc -l)

if [ $IP_COUNT -gt 500 ]; then
# send message to slack
curl -X POST -H 'Content-type: application/json' --data '{"text":"Too many IPs"}' $SLACK_CHANNEL
exit 1
fi

If we run this script every 5 minutes with cronjob we have a simple monitoring tools, I know its not perfect and we can use very professional tools instead of this dumpy script but its working and don’t forget this is just for example.

Automating repetitive tasks can save a lot of time and reduce the chance of errors that may occur when doing things manually

If you are repeating same task more than twice and you haven’t automated it in some way, you are definitely on the wrong track.

It’s always a good idea to automate repetitive tasks, and bash scripts are a great tool for that purpose.

Conclusion

For me, the deep learning of something only happens when I’m using it in a real project. However, having a basic understanding of the concepts and knowing what tools are available around me helps me to solve problems faster and more effectively.

While fully mastering all the concepts mentioned above would require the work of a genius, having a basic understanding of them enables me to move in the right direction when solving problems. This foundational knowledge also helps me to learn and apply more advanced techniques when necessary.

--

--

Payam Saderi

Now I am a DevOps engineer! I started to work as a front-end developer in 2000, aslo I have more than 16 years of experiences as a Linux system administrator