Difference Between Functions and Aliases

Learn cases when we should declare a function instead of an alias.

If we want to shorten a long command, we use an alias.

When using the shell, we need a function in two cases only:

  1. We need a conditional statement, loop, or code block to perform our command.
  2. The input parameters are not at the end of the command.

The second case needs an example. Let’s shorten the find utility call. It should search for files in the specified directory. When we search them in the home directory, the find call looks like this:

find ~ -type f

Run the commands discussed in this lesson in the terminal below.

Get hands-on with 1200+ tech skills courses.