We all know the frustrations of being a developer- getting stuck on a simple piece of code for hours. Mental exhaustion of situations when bugs elude
I think it is important for a developer to save time wherever he/she can. I often found myself wasting time over simple things in Linux, and I have seen expert developers saving so much time and frustration just by having proper tools/ setup.
Here's a guide for beginner developers that'll definitely give you a programming productivity boost. Some of this may seem obvious to you, however, I wish had known them before starting my journey with development on Linux.
1. Shortcuts that will save time:
Use shortcuts. Don't waste time with a mouse for things like opening a terminal. Some shortcuts I find useful:
- Open terminal:
Ctrl + Alt+ T
- Line Navigation: You are wasting time if you use
→
or←
to navigate in terminal. Instead,- Skip a word:
Ctrl + →
orCtrl + ←
- End of line:
Ctrl + a
, Start of line:Ctrl + e
- Delete line:
Ctrl + u
- Skip a word:
- Command Search: Search through previously type command in the terminal with
ctrl + R
. Hit it multiple times to cycle through all matching commands you have typed.
Here's a cheat sheet of all linux shortcuts.
2. Show Git branches in Terminal:
I am talking about something like this:
I absolutely fell in love with this when I saw it in someone's terminal. You have two ways of doing this:
Use ZSH (Recommended): To do this, type following commands in the terminal:
sudo apt-get install zsh
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
ZSH has so much more to offer - user-friendly interface, spell checks, smart completions etc. For more details on setup, go through setting up ZSH on Linux.
Modify ~/.bashrc: Alternatively, edit your ~/.bashrc and add following lines at the end:
export force_color_prompt=yes
export color_prompt=yes
# Add git branch if its present to PS1
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ '
fi
unset color_prompt force_color_prompt
3. Start using aliases:
Aliasing allows shortening common commands to a keyword alias of your choice.
Can't stress this enough. Using aliases properly will definitely save you 30 mins each day. I used to cd into my project directory, then start server or other programs. Efficient developers use aliases for common commands, and export common variables and paths as bash variables.
For example, Instead of doing this to start your server every morning:
$ sudo /opt/nginx/sbin/nginx
Add this command to your ~/.bashrc
:
...
alias nginx-start='sudo /opt/nginx/sbin/nginx'
...
Next time, just hit nginx-start
on your terminal. Ideally, try to alias all commands longer than 2 keywords that you use more than 5 times daily.
Here's a detailed tutorial on using alias with unix systems.
4. Use Terminator or Tmux:
I often used to switch terminal screens to do different tasks. Here's what you can do instead.
To download, simply open your terminal and type:
$ sudo apt install terminator
You can right click on the terminator window and split your screen whichever way you want.
5. Learn & use insanely useful Linux commands:
Things like finding a file, reading a file etc. can be done with lightning speed on Linux. You need to get familiar with a few basic commands though:
- Find file by name:
sudo find -name <filename> <root dir to start search from>
- Scrolling through big file:
less <path to file>
. Faster than opening the file in gedit or something. - Print entire file on terminal:
cat <path to file>
- Print only lines containing some keyword:
grep <regex> <file>
- Open file explorer on current path:
nautilus .
- Print current directory structure as a tree with all subfolders and files:
tree .
- Print free memory:
free -m
- Stream a file, particularly log file in real time:
tail -f <filename>
Mastering commands such as less
,grep
, tail
will save you lot of time daily once you get used to it.
6. Show, Monitor, Kill Processes:
One of the more my frequent tasks is to monitor resources (RAM, CPU etc), and kill processes. Doing that in Linux could be perplexing for beginners.
I use something called htop
, and it looks like this:
You can monitor, sort, kill, search process in one window. You can install and get started with htop here.
7. Use a Badass code editor
I know this one's completely subjective. But I recommend using a kickass code editor, such as the ones by JetBrains. Master them to live a long and happy life as a developer.
Bonus: Live healthy, zero distractions
You probably know this, but just for the sake of completeness - live & eat healthy. Keep distractions low. Following tools could help you:
Redshift
: Sleep better with this on your computer screen.Self Control
: Control your habit of wandering off to FB, Twitter with this.
Think I missed something? Please leave your comments & feedback below.