Retain X amount of files

I encountered an issue today where someone requested that we keep the 10 newest backup files, while the rest of them (the oldest) were deleted. So I made this little script:


NUMBER_OF_FILES="$(ls -t $FILE_DIR | wc -l)"

if [ "$NUMBER_OF_FILES" -ge "$RETAIN" ]; then
    cd $FILE_DIR
    ls -t | sed -e "1,$RETAIN d" | xargs rm -f

This can be modified to match with any type of file or filename.

Introduction to tmux

I have been working with Linux for years, and I've always used screen when working in the terminal. I even wrote a small introduction to screen over 10 years ago.

So you can imagine my surprise when I at a very late point found out about tmux. It has completely changed the way I work, and boy do I love it.

Delete files between two dates

To delete all files in a directory, between two dates, use the find command:

find /path/to/dir/ -type f -newermt 2022-01-01 \! -newermt 2023-01-01 -exec rm -fv '{}' +

Scan for newly added disks

To scan for newly added/modified disks, run the following command as root:

for f in /sys/class/scsci_host/*; do echo "---" > $f/scan; done

Ansible EX294 practice exam and solutions

I am hopefully going to take the second half of my RHCE exam this year, which is EX294. I have taken inspiration from and , and have decided to provide my own answers and explanations as I myself prepare for the exam.

I’ve also only used 4 VM’s in total, 1 controller and 3 nodes, and not 4 nodes as the practice exam suggests.

Here are the tips that I’ve found helpful so far:

How to unregister Viscosity

I was helping a colleague of mine set up VPN, with the client Viscosity to be specific, on macOS. During the process of setting it up, we noticed that remains of an old license, from another place, was still there. When she tried connecting to one of our remote servers, she got the following error:

This copy of Viscosity is registered using a license that does not allow connections to one or more of the remote servers for this connection. Please contact your VPN Provider for further details.

Tried searching for options to unregister the old license, but there was nothing visible in the GUI. I finally found a solution though, but it needs to be done in the terminal.

defaults delete com.viscosityvpn.Viscosity License

Then press Enter. Now start Viscosity again, and it should no longer give you that error. If your trial period has ended, you will have to enter a new valid license.

iTerm and alt+backspace

I recently changed jobs, going from a Linux environment to macOS. When I worked in the terminal in Linux, I got used to using alt+backspace to delete entire words. Unfortunately, it seems that this function isn’t native to the Terminal application that macOS has.However, in the application iTerm2 it’s possible to add your own key-combinations so that alt+backspace, or in this case cmd+backspace, works as it does in Linux.

Just follow these instructions:

  • Open up iTerm2 and head on over to Preferences
  • Go to Keys -> Key Mappings and press the +.
  • In the Action field, select Send Hex Code.
  • In the field Keyboard Shortcut, just press cmd+backspace.
  • In the field Hex code enter 0x1B 0x08.

And that’s it! cmd+backspace in iTerm2 should now have the same functionality as alt+backspace in Linux!