Ubuntu makes it very easy to record scripts into files that can be run anywhere from the command line, allowing you to script out common tasks and easily run them without always having to copy/paste or remember long, very technical commands.
Ubuntu will automatically look to see if there is a ~/.local/bin folder and will allow any script file in there to be run as a command.
For example, you might enter sudo mount /dev/nvme0n1p1 /media/8tb to mount an external drive. You can easily script that to run as a command.
First, check inside the .local folder:
ls ~/.localIf you do not see bin there, then you need to create it:
mkdir ~/.local/binSince you are only editing files in your home folder, you do not need to use sudo.
Then, create a file in that bin folder with the name of whatever you want the command to be. e.g.
touch ~/.local/bin/mount-drivesNext, edit the script file (~/.local/bin/mount-drives for our example) and add the command(s) that you want to run when the command is run. The first line just specifies that it is a bash file. Then, you can add any script lines that you need under it. e.g.
#!/bin/bash
sudo mount /dev/nvme0n1p1 /media/8tbFinally, you need to make sure that the file is executable. e.g.
chmod +x ~/.local/bin/mount-drivesIf you just created the ~/.local/bin folder, then you will need to make sure that it is loaded into the PATH (Ubuntu does this automatically for ~/.local/bin, but only if the folder exists) by reloading the .profile file.
source ~/.profileNow, you can just run mount-drives from anywhere in your terminal any time you need to mount the drives.