loading...
Cover image for Why you need Terminal

Why you need Terminal

nrobinson2000 profile image Nathan Robinson Originally published at blog.nrobinson2000.me ・4 min read

The Terminal, also known as the command line or a Terminal emulator, is an essential component of any useful operating system. It is by far one of the most important applications on Mac and Linux. The Terminal provides an efficient interface to access the true power of a computer better than any graphical interface.

When opening a terminal you are presented with a shell. On Mac and Linux this shell is Bash, but other shells can be used. (I'll be using Terminal and Bash interchangeably from now on.)



The interactive prompt is one of the primary methods of using a shell. The most convenient feature of a shell is that it operates with a working directory, which means you can navigate your file system and the shell will keep track of where you are. Bash can create directories (folders) and files with ease, and it is more straightforward than using a graphical file manager.

You can use Bash to run many programs and execute many many files. Often executable files are called commands. Commands can take input in the form of arguments or interactively, and can perform operations and print output. Bash is powerful because of the methods it has to link and chain commands together.

Bash is also a scripting language, which means you can create executable files called scripts that can run multiple commands, support control structures, variables and much more. Scripts are useful for automating processes or creating an easy way to perform many tasks with a single command.

Bash can be used to do amazing things but at the cost of responsibility. If you command it to do an undesired command sequence it will proceed and execute without hesitation, which may lead to unintentional or damaging effects. When using Bash you are executing the power you have over the computer. Use Bash responsibly, and if you are unsure what something does, don't paste it into your terminal. Be smart and google it, or read the manual for the command. Use caution. The last thing you want to do is compromise your computer.

The Terminal is a tool, not an application, meaning that it can be regarded as a lifestyle. I always have a terminal or two open in the directory of a project. I navigate to the project in a terminal, and then use the terminal to launch graphical applications with the project as the current directory. This is much quicker and less cumbersome than the reverse, which can take much longer. Imagine the time that is wasted and the clicks that are used to open a graphical code editor, click File->Open, navigate to the project, click Open, wait for the folder to be opened, and then finally open a terminal and jump to the project directory so you can run your code. With my method, I can run atom . in my terminal to launch Atom. My terminal remains in the background, and I can come back to it to run the code and debug.


Terminal fluency is an essential skill that no developer should go without. Using a computer without using terminal is like driving a car without using the steering wheel. (I hate it when people use vehicles to make computer analogies but they're an efficient way to get a point across.) Every developer should take the time to familiarize themself with terminal if they haven't done so already, as it is a truly rewarding skill. You'll amaze yourself with what you can achieve and the time you can save by creating scripts and commands to automate or expedite tasks in your workflow.

Using terminal puts you in full control of your computer and your workflow, and I highly recommend using it whenever possible. I use it every day and I love it.


Why Bash is important to me

My most popular open source project is a Bash script, and has over 70 unique users. It's called po-util, and provides an easy method for installing and using the local Particle toolchain to compile code for Particle's entire suite of Wi-Fi, and cellular IoT development boards. It includes many features for project, library, and device management, and can be installed on Mac and Linux by running the following command:

$ bash <(curl -sL master.po-util.com/install)

Check it out on GitHub, or on po-util.com.


Originally Published on my Blog

More about me: nrobinson2000.me

Posted on Oct 12 '17 by:

nrobinson2000 profile

Nathan Robinson

@nrobinson2000

Maker, Hacker, Student. I love building websites and developing on embedded devices.

Discussion

markdown guide
 

I love this.

I remember putting it off for a long time. Now, I too have terminal in the background.

I managed to make a snippet manager with bash, it was so cool. I also added my most used git commands in one mash method. So when I'm working, after the initial setup, I just run gitit "commit message" and bash adds, commits and pushes the code.

I'd love to know a bit more about it though, for example, why is it that now it feels slower that it used to be.

 

I have this function in my .bashrc for quickly committing and pushing my changes in a repo.


function update()
{
  cd "$(pwd)"
  git add -A
  #git commit -S -m "$1 at $(date +"%H:%M") of $(date +"%Y-%m-%d")" # Replace the line below with this one for GPG signed commits
  git commit -m "$1 at $(date +"%H:%M") of $(date +"%Y-%m-%d")"
  git push -u origin $(git rev-parse --abbrev-ref HEAD)
}

I can just do update “message” and all changes will be committed using my GPG key, the commit message gets appended with a timestamp, and gets pushed immediately.

I also have this function will lets me do a git pull for all repositories in a directory.

function pull-all()
{
  CWD="$PWD"

  for OUTPUT in $(ls -1 "$CWD")
  do
    if [ -d "$CWD/$OUTPUT/.git" ]; # Only do git pull if it is a repository
    then
      cd "$CWD/$OUTPUT"
      echo "Pulling $OUTPUT..."
      git pull
      echo
    fi
  done
  cd "$CWD"
}

It’s very convinient because I can cd to my central git directory and run pull-all to git pull all the repos.

 

That's a lot more sophisticated than what I have. I didn't even think of adding the time stamp. I'll definitely borrow that :)

I might borrow the pull-all though to be honest I do not understand it at all. Though I use git daily for my private repos, I haven't yet contributed to any open source (which if I'm not mistaken is what pull is mostly used for).

Pull is also used if you are working on a repo on multiple devices (even if they are your own and it’s a private repo).

 

This is a very concise article explaining the importance of the Terminal since most people are usually in favor of the GUI [due to the assumption the CLI is only for hackers ;) ]

One more way to do a Git pull on your multiple Git repos without ever changing to your central git directory is by installing and using gitup. I personally have used it for 8 repos which worked flawlessly.

It's just a one time setup and on every pull, it'll show you all the objects that were updated for each repository right in your terminal (depending on any color scheme you use, this is a very cool thing to have :D ]

Hope this helps, cheers!

 
 

I like your engagement. And I also like the direction of your engagement: motivating developers to get used to the shell / terminal.

You could, however, add some more concrete and compelling examples to highlight what the shell is doing for you that other tools cannot do. Or add some neat tricks you are aware of. Developers are always keen on neat tricks :-)

In my day jobs, I have always been a developer using Windows OS. Having a background on linux, I have always looked for solutions to leverage a powerful, bash style command line on windows. I used cygwin for a decade. I built a virtual machine running ubuntu that shares the data partition with the windows host. Currently, I use git bash most of the time, which is fast, lightweight and easy to install on a new box.

Junior (Windows) developers are often not used to the idea to leave the IDE, open a shell, running cryptic commands. But they are willing to learn the advantages. Cryptic commands can be saved in scripts. Scripts can be parameterized to make them available for broader use. Those scripts can be shared using git. A whole new shiny world. A set of tools to make you more efficient. An environment that supports platform independence and tool chain (think of Continuous Integration, automated installation and upgrade etc.)

 

If you guys want to help support po-util you can use my link to preorder some of Particle's next generation of IoT boards:
particle.io/mesh/?referral=5XC8JC

 

I want a shell that works with non-proportional fonts. Somehow I need to convince all the tools authors to stop aligning things with space output though. :/