Creating a simple Ubuntu Bash shortcut
. x
A daily routine of cd’ing in a directory and starting a server can easily be automated.
How to shortcut on Linux
- Save your script wihtout ending i.e. as “x” in any dir Best create a new folder for your custom scripts i.e. /home/dome/mycommands/
#!/bin/bash
function startr(){
cd /home/dome/app && rails s -b 0.0.0.0
}
startr
- Add permanent path to .bashrc file
nano ~/.bashrc
add line:
export PATH=$PATH:/home/dome/mycommands
Exit file and save with ctrl+x, then confirm with y.
- Add missing permissions with
sudo chmod a+rwx /home/dome/mycommands/x
- Ready! Now when executing your script as source (the dot) by typing
. x
it will cd and start the rails server.