5 Terminal commands every developer should know

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

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

> source ~/.bash_profile

2. Tree command

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

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

// For ignoring single folder
> tree -I Docker
// For ignoring folders which match the regex
> tree -I Dock*
// For ignoring multiple folders in single command
// Double quotes are mandatory for this

> tree -I "Dock*|Kubernetes"

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

// Sample output for history command
> history
540 clear541 sudo ~/.bash_profile542 vi ~/.bash_profile

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

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

> history | grep bash_profile

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

// Created alias called bedit
> alias bedit='sudo vi ~/.bash_profile'
// we can simply run bedit hereafter
> bedit
// If you want to remove the alias
> unalias bedit

Thats all folks !



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store