Bash cheat sheet: Top 25 commands and creating custom commands

https://www.educative.io/blog/bash-shell-command-cheat-sheet

How to create your own custom Bash commands

Custom commands in Bash are known as “aliases”. Aliases are essentially an abbreviation, or a means to avoid typing a long command sequence. They can save a great deal of typing at the command line so you can avoid having to remember complex combinations of commands and options. There is one caveat to using aliases, and that is to be sure you don’t overwrite any keywords.

  • Syntax: alias alias_name = “command_to_run”

A very simple example would look like this:

alias c = “clear”

Now every time you want to clear the screen, instead of typing in clear, you can just type c and you’ll be good to go.

You can also get more complicated, such as if you wanted to set up a web server in a folder:

alias www = ‘python -m SimpleHTTPServer 8000’

Here’s an example of a useful alias for when you need to test a website in different web browsers:

alias ff4 = ‘/opt/firefox/firefox’

alias ff13 = ‘/opt/firefox13/firefox’

alias chrome = ‘/opt/google/chrome/chrome’

Apart from creating aliases that make use of one command, you can also use aliases to run multiple commands such as:

alias name_goes_here = ‘activator && clean && compile && run’

While you can use aliases to run multiple commands, it’s recommended that you use functions as they’re considerably more flexible and allow you to do more complex logic and are great for writing scripts.