DEV Community

Cover image for Awesome Command-line tips to 10x your productivity
Nic
Nic

Posted on • Edited on • Originally published at coderscat.com

Awesome Command-line tips to 10x your productivity

Original Post: https://www.coderscat.com/awesome-linux-command-line-tips

Manage Your Configuration Like Code

Suppose you need to work on another machine, saving your configuration in GitHub will save you much time when re-customize your working environment.

Many developers already do the the same thing. Manage any configuration(.bashrc, .vimrc, .emacs etc) with Git is a good habit you should develop from the beginning of working on Linux/Mac.

The benefits of controlling configuration with Git is:

  1. Reviewing your change history, which is useful for troubleshooting.
  2. Accumulating the tips and configuration.
  3. Using it on multiple machines.

If you are not ready to share your configuration with others, use a private GitHub repo for security.

Currently, we can use private repo in GitHub without pay any fees.

Remember to add sensitive files into .gitignore, and DO NOT push files which contains password or secrets into GitHub.

I saw many developers pushed sensitive files into GitHub, and got security issues. Don’t be a fool.

How To Get Help

Don’t be afraid of so many commands options in the command line working environment.

Developers don’t need to remember everything,

The manual and documents are organized in the same pattern and Google is your final lifebuoy.

Whenever you need help for any command, try these:

Man To Query The Manuals

Command man used to display the user manual of any command that we can run on the terminal.

On Ubuntu/Debian, you need to install it from the terminal: sudo apt-get install man.

Except for querying the manual of command, you can also use man to read the manual and details of the function or files you are interested in.

man exec will display on screen:

2019_11_25_awesome-linux-commands.org_20191127_121607.png

Command With –Help/-H

Any command or script will come with a help message. Whenever you don’t know which option to use for your task, have a try on command --help. Linux/Unix help messages usually designed with similar format, you need to adapt to it.

2019_11_25_awesome-linux-commands.org_20191127_122357.png

Google Effectively

Learn how to google effectively as a developer, it needs time but rewarding for your development life.

You should know to use which keywords to search for command line issues.

For Linux commands “Linux command #keyword#” should be a good try.

Shell Alias

Shell aliases are the most useful tips when you working on Linux/Mac.

Whenever you think one command line will be repeated later(especially the long one), you should add it to your configuration as a alias.

Part of my configuration includes:

alias nis="npm install --save "
alias www='python -m SimpleHTTPServer 8000'
alias svim='sudo vim'
alias mkcd='mkdir_with_name(){ mkdir -p "$1"; cd "$1" }; makedir_with_name '
alias install='sudo apt get install'
alias update='sudo apt-get update; sudo apt-get upgrade'
alias ..="cd .."
alias ...="cd ..; cd .."
alias sock5='ssh -D 8080 -q -C -N -f user@your.server'
Enter fullscreen mode Exit fullscreen mode

Other handy aliases:

30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X

A few more of my favorite Bash aliases

Shell Tips

Go Back To The Previous Working Directory

Suppose you change the working directory into /tmp, finished some tasks and want to go back to the previous working directory, in this case, cd - will help you saving time.

Execute The Command In History

history will show the commands executed recently

2019_11_25_awesome-linux-commands.org_20191126_160158.png

From the output, !5 will re-execute command ‘pwd’ If you want to re-execute the last command, you could use !! to finish it.

Free/Top

free/top used to display the usage statistics of resources, like memory and CPU usage. A more friendly alternative is htop, which display all kind of statistics with visualization.

Netstat

netstat is a command-line network utility that displays network connections for Transmission Control Protocol, routing tables, and several network interface and network protocol statistics.

More usage examples listed here.

Combine Commands For Your Task

The best way to use the Linux/Unix is to use the commands like awk, sed, grep, xargs, find, sort, etc., combine them into the function you wanted. Just like what’s I have done for Git repo checking.

Most of the simple tasks like grep word from files, filter files with pattern can be finished with these tiny until commands.

cat/head/tail : show the content of files, bat is a Rust clone of cat, which supports syntax highlighting for a large number of programming and markup languages.

grep : Search any line that contains the keyword in a file.

sort : sorts the contents of a text file, line by line.

uniq : Remove duplicated parts from string or files.

find : Find or filter files with patterns.

xargs : Allows tools or commands to accept standard input as arguments.

awk : A scripting language used for manipulating data and generating reports.

Some Fancy Tools Which Power Your Productivity

Httpie

httpie is is a fancy command line HTTP client with an intuitive UI, it also supports JSON format, with highlighting, and many plugins. Maybe you have used curl or wget, you will forget them when you have tried httpie.

master

Tmux

tmux is a terminal multiplexer, it can manage windows and sessions in your terminal. You can split the screen into multiple sub-panels, you can also detach and re-attach sessions.

If you want to connect to remote servers frequently, this is an invaluable tool for you.

2019_11_25_awesome-linux-commands.org_20191127_223129.png

Which Shell To Use

Bash is the default shell on many Linux distributions today.

Zsh is a modern one with features of other Unix/GNU Linux shells such as bash, tcsh, and ksh.

Fish is a smart and user-friendly command-line shell for Linux, macOS. It supports powerful features like syntax highlighting, autosuggestions, and tab completions that just work, with nothing to learn or configure.

If you work on Mac: Zsh on iterm2 is my most recommended one.

Oh My Zsh is a delightful, open-source, community-driven framework for managing your Zsh configuration. With the configuration from the community, it saves much of your time.

Top comments (0)