Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
I also have pseudo-aliases, for example a function that does service $1 start, which is otherwise impossible. Might save someone a lot of time.
Hi,
alias updateAliases="/etc/alternatives/editor ~/.bash_aliases; source ~/.bash_aliases"
Save the file and get out of the editor.
Run the following command to have your aliases updaded:
source ~/.bash_aliases
updateAliases
It will open the ~/.bash_aliases for you to write/update your aliases. Now you do what you need to do to regarding creating new aliases or updating existing ones;
Save the file and exit the editor;
PS: If doing all the above, when you enter a prompt, it does not find your aliases, do the following:
echo -e '\nsource ~/.bash_aliases' >> ~/.bashrc
Regards,
Good article, just remember that if you create a .bash_profile file to hold your aliases, it will override the .bashrc ones (at least in Ubuntu 14.04). In my case, I had a custom prompt for PS1 set in .bashrc and once I’ve created a .bash_profile with my custom aliases, my prompt change back to the long default one. Once I’ve removed the .bash_profile it started working. So I just put all my aliases in .bashrc
Some of my custom aliases are:
alias update='sudo apt-get update && sudo apt-get upgrade && sudo apt-get autoremove'
alias reboot='sudo shutdown -r now'
I like to manually manage my server and don’t want to depend on cron to do it. Also, can I just copy/paste my .bashrc across servers? As long as they’re the same distro? I just hate going into multiple servers to update my preferences.
Thanks for the article!
How can I add a file containing multiple shell functions to the path so that I can just run the functions from any location?
hi this was helpful but i encountered one confusing issue:
in all of your example shell ‘c-style’ functions, you’ve included a space between, ** function_name** and ().
my functions would not work unless this erroneous space was eliminated, not sure if this is because of strict bash syntax or something else but if anyone else comes across this issue and needs help resolving, viola.
I’ve been using simple aliases for years, but this tutorial was still instructive, and the “extract” function decided me to make a little effort, and create one “fuction” I’ve often found myself missing.
Since I’m still quite newbie at this, I finally opted for a script, but it works the same, could probably be translated to a function very easily, and more importantly, demonstrates that pretty useful things can be done without needing much skill or specific knowledge. (I don’t know bash scripting syntax at all, but with StackExchange, about anyone can code something)
I’ve created a simple script to show the different apache logs from a computer, with a selection menu letting the user choose one for a tail -f, typically useful for debugging. The script also accepts a single argument, for quicker use.
Here is it, in the form of copy/pastable shell code, intended to be both readable and maintainable. Just don’t forget to also put the alias in your .profile or .bashrc if you intend to use it.
mkdir -p $HOME/functions/ 2>/dev/null
FCT_APACHE_LOGS="$HOME/functions/show_apache_logs.sh"
echo '#!/bin/bash' > $FCT_APACHE_LOGS
echo '# Variables used' >> $FCT_APACHE_LOGS
echo 'unset log logFile logsList i choice' >> $FCT_APACHE_LOGS
echo '' >> $FCT_APACHE_LOGS
echo '# Retrieval of existing Apache logs list' >> $FCT_APACHE_LOGS
echo 'for logFile in /var/log/apache2/*.log; do # Whitespace-safe but not recursive.' >> $FCT_APACHE_LOGS
echo ' logsList[++i]="$logFile"' >> $FCT_APACHE_LOGS
echo 'done' >> $FCT_APACHE_LOGS
echo '' >> $FCT_APACHE_LOGS
echo '# If a parameter is set, menu is skipped' >> $FCT_APACHE_LOGS
echo 'if [ $1 ] ; then' >> $FCT_APACHE_LOGS
echo ' echo' >> $FCT_APACHE_LOGS
echo ' echo " Content of ${logsList[$1]} : "' >> $FCT_APACHE_LOGS
echo ' echo' >> $FCT_APACHE_LOGS
echo ' tailf ${logsList[$1]}' >> $FCT_APACHE_LOGS
echo 'else' >> $FCT_APACHE_LOGS
echo '# Else, the list of apache logs is displayed, and one can be chosen with a number.' >> $FCT_APACHE_LOGS
echo ' i=0' >> $FCT_APACHE_LOGS
echo ' echo' >> $FCT_APACHE_LOGS
echo ' echo "Logs availables :"' >> $FCT_APACHE_LOGS
echo ' echo' >> $FCT_APACHE_LOGS
echo ' for log in "${logsList[@]}" ; do' >> $FCT_APACHE_LOGS
echo ' ((++i))' >> $FCT_APACHE_LOGS
echo ' echo " $i) $log" ;' >> $FCT_APACHE_LOGS
echo ' done' >> $FCT_APACHE_LOGS
echo ' echo' >> $FCT_APACHE_LOGS
echo ' while true ; do' >> $FCT_APACHE_LOGS
echo ' read -p "Tailf which log file ? " choice' >> $FCT_APACHE_LOGS
echo ' if [ ! $choice ] ; then #Defaults to standard error log' >> $FCT_APACHE_LOGS
echo ' tailf /var/log/apache2/error.log' >> $FCT_APACHE_LOGS
echo ' else' >> $FCT_APACHE_LOGS
echo ' if [ "${logsList[$choice]+'isset'}" ] ; then' >> $FCT_APACHE_LOGS
echo ' echo " Content of ${logsList[choice]} : "' >> $FCT_APACHE_LOGS
echo ' echo' >> $FCT_APACHE_LOGS
echo ' tailf ${logsList[choice]}' >> $FCT_APACHE_LOGS
echo ' break' >> $FCT_APACHE_LOGS
echo ' else' >> $FCT_APACHE_LOGS
echo ' echo "Invalid choice"' >> $FCT_APACHE_LOGS
echo ' fi' >> $FCT_APACHE_LOGS
echo ' fi' >> $FCT_APACHE_LOGS
echo ' done' >> $FCT_APACHE_LOGS
echo 'fi;' >> $FCT_APACHE_LOGS
chmod +x $FCT_APACHE_LOGS
alias _al="$FCT_APACHE_LOGS"
https://www.npmjs.com/package/as-known-as A CLI tool which lets you access your aliases from all of your machines