Showing posts with label Emacs. Show all posts
Showing posts with label Emacs. Show all posts

Tuesday, April 6, 2021

Why use the Linux terminal

The command-line (aka terminal) is a scary thing for new Linux users. But understanding it can be a huge step in your Linux journey and a significant step in your career
Photo by Tianyi Ma on Unsplash

If you're new to Linux, the command-line interface (also known as CLI or terminal) may look scary. But it shouldn't. The CLI is a powerful and resourceful tool that every aspiring Linux user should learn and be comfortable with. On this article, let's review many reasons why you should learn and use the command line, commonly (and often incorrectly) referred to as terminal, shell, bash and CLI. 

Ubiquitous

The command-line interface (CLI) is available in every operating system, not only in Linux. Very frequently, developers and system administrators spend most of the time in them. If you want to work with Linux and technology in general, better start learning it.

Terminals are available in every operating system including Linux, Windows and Macs

Powerful

CLI-based apps are much more powerful than their GUI-based equivalents. That happens because usually GUIs are wrappers around libraries developed by developers. Very frequently, these libraries contain way more functionality than what's available in the graphical interface because, as you might expect, since software development takes time and costs money to produce, developers only add to GUI apps the most popular features. 

For example, these are some of the options that the GNU find tool provides us:

Does your GUI-based find tool has all those options?

Quicker

Common and repetitive tasks are also faster in the terminal with the advantage that you will be able to repeat and even schedule these tasks so they run automatically, releasing you to do actual work, leaving the repetitive tasks to computer.

For example, consider this standard development workflow:

  1. download code from GitHub
  2. make changes
  3. commit code locally
  4. push changes back to GitHub

If you were doing the above using a GUI-based git client (for example, Tortoise Git), the workflow would be similar to the below, taking you approximately 20 minutes to complete:

  1. Open Tortoise Git's web page
  2. Click Download
  3. Next -> Next -> Next -> Finish
  4. Right-click a folder in Nautilus (or Windows Explorer, or Finder) -> Select clone -> Paster the Url -> Click OK
  5. Wait for the download to Complete -> Click OK
  6. Back to Nautilus -> Find File -> Open it
  7. Make your changes (by probably using GEdit, KEdit or Visual Studio Code) -> Save
  8. Back to Nautilus
  9. Right Click -> Commit
  10. Right Click -> Push
  11. Take a deep breath

In the terminal (for example, in Ubuntu), the workflow would be equivalent to the below and could be completed in less than 2 minutes:

sudo apt update && sudo apt install git -y   # install git
git clone <url>     # clone the GitHub repo locally
vim/nano file -> save  # edit the file using a text-based editor
git commit -m <msg> # commits the file locally
git push  # push the changes back to our GitHub repo

Scriptable

Terminal/CLI-based tasks can be scripted (automated) and easily repeated meaning that you will be able to optimize a big part of your workflow. Another benefit is that these scripts can be easily shared, exactly as business and professional developers do!

So let's continue the above example. Our developer realized she is wasting too much time in the GUI and would like to speed up her workflow even more. She learned some bash scripting and wrote the function below:

gcp ()
{
    msg="More updates";
    if [ -n "$1" ]; then
        msg=$1;
    fi;
    git add ./ && git commit -m "$msg" && git push

She's happy because now she can run from the terminal, the below command as soon as she finishes her changes:

gcp <commit-msg>

What previously took 5 minutes is now is done in 2 seconds (1.8 seconds to write the commit message and 0.2 to push the code upstream). A huge advantage in her workflow. Imagine how much more productive she would be during the course of her career!

It's important to always think how can you optimize your workflow. These small optimizations add up to your productivity significantly over time.

Lightweight

Not only the CLI is faster and more lightweight than equivalent GUI-based applications but it's quicker to run the same commands. For example, consider a Git client like Tortoise Git. It was supposed to be lightweight (what most GUI apps aren't) but it takes 3s to completely load and uses 10Mb of memory:

Our GUI-based git client TortoiseGit

Meanwhile, its CLI equivalent, git status runs in 0.3s and consumes less than 1Mb. In other words, 20 times more efficient memory-wise and 10 times faster. 

A simple CLI command is 20x more efficient and 10x faster then its GUI equivalent

Disk Space Efficient

Another advantage of terminal apps over their GUI-equivalents is reduced disk space. For example, contrast these two popular apps. Can you spot the differences?

Application    Installation Size       Total Size       Memory Usage   
Visual Studio Code        80Mb 300Mb 500Mb (on sunny days)
Nano 0.2 Mb 0.8 Mb 3 Mb
400x more efficient 375x more efficient 160x more efficient

Extensible

Another important aspect is that the CLI is extensible. From it, skilled users could easily either extend its basic functionality using its built-in features like pipes and redirections combining inputs and outputs from different tools.

For example, sysadmins could list the first two users in the system who use Bash as a shell, ordered alphabetically with:

cat /etc/passwd | grep bash | cut -d : -f 1 | sort | head -2

What's interesting from the above command is how we combined 5 different tools to get the results we need. Once you master the Linux terminal, you'll too will be able to utilize these tools effectively to get work done significantly faster!

This is a more advanced topic. We'll see in future posts more details about it.

Customizable

As you might expect, the terminal is extremely customizable. Everything from the prompt to functions (as seen above) and even custom keybindings can be customized. For example, want to bind Ctrl+E to open the Nano text editor on the terminal? Simple. Add this to your .bashrc file:

bind '"\C-E":"nano\n"'

Extensive range of Apps

Contrary to what most newcomers thing, the terminal has apps too! You will find apps for pretty much any use case. For example:

Note: The above list is far from comprehensive. It's just to give you an idea of what you'd be able to find in there

For example, here's the Castero Podcast app running on a terminal:

Source; GitHub

Professional Development

Want to work with Linux? Another important aspect of using the terminal is that it will make you more ready for the job market. Since Linux servers usually don't have GUIs, you will end up having to use some of the above tools on your day-to-day work. So why not start now?

Learn more about Linux

Hopefully at this point you realize that you will learn way more about your Linux system and computers in general when you use the terminal. This is the secret sauce that the most productive developers want you to know!

It's also a huge win for testing new tools, maintaining your system, installing software, fixing issues and tweaking as you wish.

Getting Started

Ready to get started on your terminal/CLI journey? Watch the video below:

Note: We don't have any affiliation with the video above. We just want you to learn the terminal 😊

Conclusion

Every modern computer has a terminal. Learning it will save you time, allow you to automate common actions, make you learn more about your system, save time, grow professionally and be more comfortable with Linux. Well worth the effort, isn't it?

See Also

Tuesday, December 1, 2020

What is Open-Source?

Today, the term open-source is pretty popular. But it also means a lot of things. Would you like to understand more about it? Learn more on this post.
Photo by Chang Duong on Unsplash

Nowadays, the term open-source is pretty popular. But it also means a lot of things. Let's learn about its history and how it changed not only how we use software and services today, but also how it changed the society as a whole.

A little bit of History

The history of the free software/open-source mixes with the history of early computing and Unix itself so it's important to provide a little of context first.

Some say that it was Dr. Donald Knuth the first person to release a program's source code (TeX) to the public for free, but Richard Stallman, another brilliant developer who since his early years in the Harvard, then MIT labs believed (and later campaigned) that software should be open (ie., with its source code open to the public) and free (as in speech, not as in beer). His initiative soon would be known as the free software movement

The Free Software Movement

Before the term open-source became popular, the term "free software", created and popularized by Richard Stallman, was more prevalent. Stallman, who in 1983 started the the GNU operating system with the goal of creating a "complete Unix-compatible software system" composed entirely of free software.

Stallman who working in MIT's AI lab in the early 1970s became frustrated with the spread of proprietary software, saw it as a violation of people’s rights to innovate and improve existing software. His experiences with proprietary software made him an activist in defense of free software. Today it's difficult to imagine Linux, free and open-source software today without his contributions.

Speaking of contributions, some of Stallman's contributions to humankind are: the GNU Project, the Free Software Foundation, the GNU Compiler CollectionEmacs and the GPL / GNU General Public License.

Open-Source as a term

But Stallman's vision of free software had opposition from those who thought that the requirements imposed by the the free software movement were much too rigid. That group composed of influent people such as Todd Anderson, Larry Augustin, Jon Hall, Michael Tiemann and Eric S. Raymond endorsed the adoption of the term open-source proposed by Christine Peterson as a broader and better alternative.

Soon, other influential names such as Linus Torvalds, Phil Hughes, Larry Wall, Brian Behlendorf, Eric Allman, Guido van Rossum, Michael Tiemann, Paul Vixie, Jamie Zawinski, and Eric S. Raymond would be aligned with the new term raising awareness and industry-wide adoption.

Licenses

Licenses are an essential aspect of open-source software. The most common are:
  • GNU General Public License: the license created by Stallman himself. Today there are mainly three GNU licenses: AGPLv3, GPLv3, LGPLv3
  • Mozilla Public License 2.0: Permissions of this weak copyleft license are conditioned on making available source code of licensed files and modifications of those files under the same license
  • Apache License 2.0: A permissive license whose main conditions require preservation of copyright and license notices.
  • MIT License: A short and simple permissive license with conditions only requiring preservation of copyright and license notices.
Understanding the licenses is critical to any open-source project and is definitely a complex subject. We will address this in a more detailed post in the future.

Broader Open-Source Reach

Today, the term "open-source" goes beyond software and reaches many segments, including:

The world without Free/Open software

The world we live today would be drastically different if we didn't have these initiatives by Richard Stallman, Linux Torvalds, the others previously mentioned and millions of anonymous contributors worldwide.

Below, some of the ways in which free/open-source software changed the world:

  • the Internet: pretty much all the infrastructure of the internet today (routers, switches, firewalls, etc) runs Linux or open-source software. Not to mention the web servers (Apache, Nginx), databases (PostgreSQL, Redis, MySQL) and even most of the programming languages and libraries used to develop the tools and services you use are open-source.
  • Services: cloud services are built on top of the above list and use container technologies such as Docker, Kubernetes, containerd, KVM, QEMU which are also open-source.
  • Faster time to market: open-source also fosters and is essential for a faster time to market, critical to business today. 
  • Reduced development cost: it's probable that Google, Spotify, Tesla and even Amazon wouldn't exist today without open-source. It's impossible to imagine how to develop so complex products and services without the broad diversity of open tools available today.
  • Education: education also benefits significantly from free/open-source software. The contributions range from the device learners are using (Android, Chrome OS for example) to the services, infrastructure and broad range of technologies that support them.
  • IoT: the next age of computing will reach virtually every digital device around us. And Linux/open-source software is the 
  • Robotics: robotics also heavily utilizes open-source technologies (including hardware). 
  • Supercomputers: all of the supercomputers today run Linux. These computers are used for researches and are critical to the evolution of humankind.
  • And everything else: from agriculture to rockets, spaceships and nuclear plants, open-source runs everywhere.

Famous open-source initiatives

Today, there are many, many initiatives and projects that are extremely successful and follow the open-source. Some of the most biggest projects today are:

Linux and Open-Source

The GNU General Public License was the tool Linus Torvalds needed to grow his project. Without the open-source model, the distributed and collaborative nature of open-source and its ever growing audience of fellow contributors and sponsors, it's impossible to imagine that Linux would have have reached 30 million lines of code and US$ 5 billion in value.

And without the GNU operating system, we wouldn't have a solid foundation to build the fantastic Linux distributions we have available for free today.

Conclusion

The world as we know today would be radically different without the contributions of those pioneers back in the 80's. Between them, Richard Stallman was definitely the most important proponent of the free-software agenda which was later extended by the open-source movement reaching wider audiences and gaining corporate endorsement.

Today, Linux is the biggest open-source project in the world and rules the cloudthe Internet, mobiles phones and even supercomputers. Without Linux and open-source, it's difficult to imagine how far would the society be today. Definitely we'd be behind, way behind.

References

See Also

Featured Article

Free Software, Open-Source, Libre, FOSS and FLOSS: what are the differences?

Are these just different names for the same thing? Or there are differences? Photo by Romain Vignes on Unsplash We have been discussing...

Popular this Week