Image: bash-logo.png

Custom cmds in Ubuntu

by on
1 minute read

Create custom commands in Ubuntu (and other Linux distros).

⚠️⚠️⚠️ This was done using Ubuntu 20.04 but it should work on most Linux distros the same way.

Create Folders

On the terminal create folder to save your customs scripts eg:

mkdir -p ~/bin

Create Scripts

Inside the new folder created create a new file,eg:
nano ~/bin/y2upgrade

Edit the Scripts

Edit the file with your commands and save, eg:

#!/bin/bash

sudo apt-get update
sudo apt-get upgrade -y

Set Access Permissions

Use chmod to set files permissions. (should ask twice for sudo password)

sudo chmod +x ~/bin/*;su -l $USER

Testing

Now you should be able to send your command from the terminal, the file name is the command name for example now when entering: y2upgrade it should first do sudo apt-get update and then sudo apt-get upgrade -y.

-y simply means it will not ask you Y/n if you want to accept installing the upgrades in case there is any.

Extra

SSH without asking for password.
Create file named sshnopwd and paste the contents of this file

now instead of using ssh username@ip and then entering password, simply run sshnopwd password username@ip and it will automatically login.

Small collection with more examples can be found here

comments powered by Disqus