5 Terminal commands every developer should know

Image taken from https://itnext.io/upgrading-bash-on-macos-7138bd1066ba

1. Source command

Source command executes the contents of the file which is passed as the argument to it

Let’s say we have two Java versions — Java 8 & Java 11

We often switch between the versions by changing the JAVA_HOME in ~/.bash_profile

~/.bash_profile pointing to Java 11
~/.bash_profile pointing to Java 8

If we edit the ~/.bash_profile file, we need to restart our terminal for the changes to reflect

But with source command, we can see the changes reflect in current terminal session itself. Just do

2. Tree command

Most of us are familiar with tree command which displays content of a directory in a tree-like format

tree command in action

But there can be a scenario where you may want to skip few folders as they have so many files in it. Best example is node_modules folder in Node based applications

So lets see how to ignore a folder in tree command

tree command ignoring Docker folder

Refer to other interesting tree command flags here — https://www.computerhope.com/unix/tree.htm

3. Sudo Previous Command

Sometimes the command we run fails because of lack of permission. The obvious solution would be to run the same command with sudo prefix

But do we really need to edit the previous command and add the sudo prefix to it ? We don’t have to

You can do sudo !! command which will rerun the previous command with sudo prefix

4. History Command

history command is a familiar for most of us. Thats how at least I manage to survive in this industry with such poor memory power

history command list down all previous commands we run in terminal

Let’s say we want to rerun the command vi ~/.bash_profile from above result. We don’t have to copy paste the command again

Simply run

542 is the number given for vi ~/.bash_profile command

Note: All commands listed by history command are numbered

We can also search for a particular command among history by doing grep on history command

5. Alias Command

Alias command help us avoid typing lengthy commands again and again

Let’s say we often edit .bash_profile with sudo vi ~/.bash_profile

Instead of typing the command every time, we can create an alias for it

Thats all folks !

Twitter @IamVickyAV