Skip to content

Instantly share code, notes, and snippets.

@xdrkush
Last active April 4, 2022 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xdrkush/1f8e21b1348beaeebf4180c26a454be1 to your computer and use it in GitHub Desktop.
Save xdrkush/1f8e21b1348beaeebf4180c26a454be1 to your computer and use it in GitHub Desktop.

For create a command (Alias)

Docs:

For start:

Create folder "~/scripts"

mkdir ~/scripts

Create file "~/scripts/update.sh"

nano ~/scripts/update.sh

Copy this code below and pas on "update.sh":

#! /bin/bash

echo "UPDATE: processing ..."

sudo apt update && sudo apt upgrade -y && sudo apt clean && sudo apt autoremove && sudo apt autoclean

echo "UPDATE: Termined with Success ..."

(quit nano ctrl + x enter enter)

For exec "update.sh"

chmod +x ~/scripts/update.sh

Now copy .bashrc (save)

Warn .bashrc file is very important file !!!

sudo cp ~/.bashrc ~/bashrc.copy
sudo nano ~/.bashrc

add this line at the top on ".bashrc"

# Alias
alias update="~/scripts/update.sh"

(quit nano ctrl + x enter enter)

Source the file:

source ~/.bashrc

And test your command (alias):

update

if all is ok delete your bashrc.copy

Best practice

The best practice want edit (or create) the ~/.bash_aliases

└──╼  $ cat .bash_aliases 
alias update='sudo apt update'

Warn you cant add similary alias on .bashrc and .bash_aliases !!!

if you look on .bashrc you read this

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

Enjoy'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment