Last updated: 2019 December 4
- Setting up additional internal drive
- Check if computer restart required, with a bash alias
- Command line history completion
- Prettier bash prompt
- Fix “System program problem detected” on every boot
- Make a shell command
- Automatic backups (with cron and rsync)
- Saving dotfiles with git
- Using Tilix as default terminal application (with Gnome, at least)
- Using Cisco AnyConnect VPN
I use gparted and set the whole thing to be a single ext4 partition with a gpt partition table. Note the partition ID (e.g., /dev/sda1) for the next step.
If you give your partition a label and name in this step, it’ll make it easier to identify/remember in the next step and later on. Setting the name will also mean it’s nicely labeled in your file explorer.
sudo blkid and copy the UUID for the partition from the previous step.
Choose a location where you want your drive to show up as, such as
/media/USERNAME/data. I don’t actually know if there’s a canonical way to choose the mount point. Since I’m generally creating a drive that’s only used by my user, I generally create the mount point under my username.
Now create this directory to mount at, such as: (with your username filled in)
sudo mkdir /media/USERNAME/data
Then change this location to be owned by your user and group:
sudo chown -R USERNAME:USERNAME /media/USERNAME/data
We’ll add an entry to the filesystem table to detect and mount the drive by its UUID when the computer boots, and give your user read and write access to the drive.
Warning: If you mess up this file, your computer will possibly not boot. I suggest making a backup of it so you can revert if necessary.
sudo nano /etc/fstab
Add a line to the end of the file, using the UUID you got before:
UUID=YOURUUID /media/USERNAME/data ext4 user=USERNAME,rw 0 2
A couple notes on this:
- Don’t put quotes around the UUID
- The second entry is the mount point you set up in the previous step
- ext4 is the journaling system you formatted your partition as. I think you can also use
auto, but why not be explicit if we know it? Also, if you set this wrong there’s a possibility your computer won’t boot.
rwoptions specify that it will be mounted for your user with read/write permissions. (I don’t really know much about all the configurations here. Check out the Ubuntu documentation wiki for more info about this and fstab in general.)
0is the “dump” flag. It’s not used for much and has something to do with automatic backups. When it doubt, it’s 0.
2is the “pass”. It means that fsck (filesystem check) will check this as a secondary partition. 0 means it will be skipped (common for external drives) and 1 will be checked first (usually used by your root partition).
Try manually mounting the drive:
sudo mount /dev/sda1 /media/USERNAME/data
Verify that it shows up in your terminal and file explorer and create a test file. (Checks that you can write as your user.)
And unmounting it:
sudo umount /media/USERNAME/data
Check that your test file isn’t in the mount location. Remount and check that it is. (aka check that you actually wrote to the disk.)
Then reboot (verify that you didn’t break fstab) and check that your drive mounted properly and your test file is there.
Sometimes you have to restart Linux after updates. If you do this with the software updater, it will tell you a restart is required. But I do my updates through the command line and am generally too lazy to restart my computer on a regular basis.
You can tell that a restart is required if the file
/var/run/reboot-required exists. But I also never remember what that file name and location are to check that. But I can remember
rr, so now I have an alias that uses that file to tell me if a restart is required based on the existence of that file. (This came from the AskUbuntu answer.)
Just add the following to your
alias rr='if [ -f /var/run/reboot-required ]; then echo "reboot required"; else echo "No reboot needed"; fi`
Note: this is useful for bash, but for ZSH, there’s a nicer approach.
In Matlab, you can start typing a command, hit the up arrow, and it’ll go through the history of commands that match what you’ve typed in. I like this feature and want to use it in my general command line.
Turns out this is easy to do in Linux. Open the .inputrc file:
Add this to the file:
## arrow up "\e[A":history-search-backward ## arrow down "\e[B":history-search-forward
Save and exit, then load the changes:
bind -f ~/.inputrc
There’s a simple, awesome tool to help you do that. There’s an interactive GUI to change color, boldness, and insert text. It will even show you a live preview of what your prompt will look like.
Below that on the page, there are a few lines of code to add this customization to your terminal. If you just want to try it out before finalizing, you can just copy and paste the
PS1=........ portion into your terminal. When you finalized what you want, open your
bashrc file with
nano ~/.bashrc and paste that entire block of code at the bottom. Then restart your terminal to make sure everything worked.
The command prompt customization is user-specific, which has a bunch of benefits: it will show up when you SSH into your user, it will show up no matter what terminal you use, and it lets you distinguish between users (so you don’t accidentally do everything as root, for example).
Currently, here’s what mine looks like (copy and paste into your terminal to check it out):
PS1="\[$(tput bold)\]\[$(tput setaf 2)\]\n\u@\h: \[$(tput setaf 7)\]\w\[$(tput setaf 3)\]\n\\$ \[$(tput sgr0)\]"
Contrary to what I thought, these errors popping up every time you turn the computer on doesn’t mean that there is always a bunch of stuff crashing on start up. It means that something crashed in the past and somehow never got cleared from the crash reports. So that means there is a simple fix!
All you have to do is clear the crash reports, which you can do with one line in the terminal:
sudo rm /var/crash/* And when you reboot, the pesky errors from before shouldn’t make a reappearance. If something does, it probably really does mean something is crashing on start up and needs to be investigated further.
Source: Ask Ubuntu
This creates a bash command that can be executed in the terminal (from any directory, as any user, without sh)
One-time setup: add this to your
if [ -d "$HOME/bin" ] ; then export PATH="$HOME/bin:$PATH" fi
For each script:
- Create your script file in
~/bin. Leave off the
.shfilename extension when you’re naming it so you don’t have to type it to run it.
- Start your script file with:
- Give it the correct permissions to be executed:
chmod 755 ~/bin/$SCRIPT
- Run it to make sure everything’s working.
You can now also add the scripts in this folder to your dotfiles.
Source: Unix Stack Exchange
I use this for creating a daily uncompressed backup of data of my internal data drive to an external hard drive.
Create a bash script somewhere (I have it in the main directory of what I’m backing up) containing the following:
rsync -av --delete SOURCE DESTINATION
Mine looks like this:
rsync -av --delete /media/jtebert/data /media/jtebert/data-backup/backup
Note that the
--delete flag means anything placed in the destination that’s not in the source will be deleted. In other words, use the backup as a backup, not to actually edit stuff.
Then make sure the script is executable:
chmod +x /path/to/backup-script.sh
You can now directly run this script to verify that it does what you expect.
Now we’ll create a cron table entry to automatically call this script at some time every day (this is set to 3 AM). Open the cron table with:
And add the following line:
0 3 * * * /path/to/backup-script.sh
Check back the next day and you should see a copy of everything from your original folder in the backup location.
Source: How-To Geek
I followed this tutorial to set up a repository containing my dotfiles.
Gnome defaults to
gnome-terminal for its system terminal, but Tilix lets you tile terminals and nice stuff like that.
To make Tilix be the terminal that opens with the shortcut
sudo update-alternatives --config x-terminal-emulator
and choose Tilix from the resulting list of options.
Depending on your Ubuntu version, you may need to fix a Virtual Terminal Emulator (VTE) setting. If this is the case, you’ll get a warning (“Configuration Issue Detected”) when you open the Tilix preferences. You need to add the following to your
~/.zshrc file. (This is already in my
.zshrc in my dotfiles repository.)
if [ $TILIX_ID ] || [ $VTE_VERSION ]; then source /etc/profile.d/vte.sh fi
You may also need to create a missing symlink, if the file
/etc/profile.d/vte.sh doesn’t exist:
sudo ln -s /etc/profile.d/vte-2.91.sh /etc/profile.d/vte.sh
Lastly, it’s useful to have the option to right click in Nautilus (file explorer) and open Tilix in that folder. To make sure that works, you have to install the
python nautilus package.
There’s pretty nice integration for this on Chrome OS. But the Linux client was ugly and constantly cut/lost my connection. Harvard’s IT people suggested this solution/alternative using openconnect and it actually worked.
sudo apt install network-manager-openconnect-gnome
Test that the VPN works by using it through the command line:
sudo openconnect VPNURL
In the case of the Harvard VPN, the url is
vpn.harvard.edu. Also for Harvard, you can leave the second password entry (the one for two-factor authentication) blank, in which case you’ll get the Duo mobile notification on your phone for approval.
Source: Ask Ubuntu