Can I make my own commands?
Solution 1:
Yes - create a file named music and put the following inside it:
#!/bin/bash
echo "Hello world"
Next, type chmod +x music
- this makes the file executable. You can now type ./music
to run this script.
It's a good idea to type echo $PATH
and copy the script into one of those directories. I would suggest creating $HOME/bin
and adding that to your PATH via ~/.bash_profile
or ~/.profile
. This can be done by adding (to one of those files): export PATH="$HOME/bin:$PATH"
. You will then need to run source .bash_profile
(assuming you put that in that file) to reload it.
Another alternative would be to add the command you want to run as a bash alias. You can do this by adding the following to a file named .bash_aliases
in your home directory:
alias music='vlc --some-option --foo'
Run source ~/.bash_aliases
or logout and login and it should work :-)
Solution 2:
The best way to do this is to modify (or create) a file called .bash_aliases
in your home folder.
The Syntax is fairly simple:
alias install='sudo apt-get -y install'
With this command, if you type install
in a terminal, it will instead be interpreted as
sudo apt-get -y install
However, these commands will not work anywhere outside of a terminal.