

The alias checks the response from the previous command. The sleep command will sleep for five seconds., The alert alias will then be called. It provides a graphical system alert at the top of the screen. It also indicates whether the command completed successfully or not. The alert AliasĪs a quick aside, and so that you know what it does, the alert alias is used to let you know when a command has finished. The body of this alias simply calls the grep command with the -color=auto option.

For all but very simple aliases, the body of the alias is enclosed within single quote marks '.

The equals sign connects the name of the alias to the body of the alias.The alias command is used to define an alias.Here is the definition of the grep alias. They can even contain the original command within themselves. They can have the same name as existing commands. This shows an important point with aliases.

The system will interpret it as: grep -color=auto For example, with these aliases defined, whenever you type: grep There’s a bunch of different aliases for the ls command, and there’s a group of aliases that provide color output to the grep family of commands. If I’d defined any custom aliases, these would show up in this list too.Īt the top of the listing, there’s a complicated-looking alias called alert. These are the aliases that are defined on the Ubuntu test machine this article was researched on. Aliases are perfect for holding shorter, more succinct, sets of commands. Scripts are better at holding longer and more elaborate chunks of code. The difference between an alias and a script is one of complexity and scale. Typing the name is easier and more convenient than having to type out all of the steps or commands each time you want to use them. They allow you to define-and name-a set of Bash shell functionality that is then callable by the name you’ve given to it. You can define your own commands suited to your specific needs, and to ease the burden of repetitive tasks.Īliases and shell scripts do the same sort of job. Tame repetitive tasks, truncate long-winded processes, and configure standard commands with the options you always use and struggle to remember.Īliases and shell scripts are powerful techniques in Linux and Unix-like operating systems that allow you to hone your command line experience to be just what you want. I'm working on my own profile, you can take a look at the gist here.Fatmawati Achmad Zaenuri/Ĭreate your own Linux commands using aliases and Bash shell functions. I ended up changing the command and endpoint a bit to this due to my memory needing things spelled out and his ip service not working. Thanks to NateLandau for some great command ideas which contain some great ideas like adding a what's my ip command. bash_profile to apply your changes or open a new terminal instance. If you’re using an earlier version you may need to then type source. Make the edits you want, some examples might be creating a command to go to a dev directory which would look like this alias dev=‘cd ~/dev/‘.Įxit while saving and things should work now. There are a few options, you could open the folder in your favorite IDE or just type in the terminal nano. If it doesn’t exist, or practically even if it does you can now edit it. You can see if it exists by entering the command ls -a ( ls is Linux’s list command), the -a option tells it to show hidden files (files that start with a. bash_profile for older versions of OS-X). This command sets your current location to your home directory. To do this enter cd ~/ inside of terminal. zshrc.įirst off we need to open Terminal.app and head over to your user directory. The process is similar depending on your OS but as I found out via ( Stack Overflow) that the latest version of OS-X, Monterey (version 12.0.1) the file you need to edit is now. The process for OS-X and Linux are really similar but in this example I’m going to be walking through setting this up in OS-X Monterey. Your bash profile lets you easily add new commands to your terminal.
