Skip to main content

Posts

Showing posts with the label Bash

Practice Linux vim in Windows using gVim

Vim is a cool and powerful editor in Linux system. It is also available for Windows via this download page: https://www.vim.org/download.php Choose: gvim_9.2.0000_x64.exe (64bit installer) or any format of your choice. After downloading and installing, the installer it will create two desktop icons; something similar to the image shown below. Why there are two icons? As the name suggests "gVim Easy 9.2", gVim Easy is the filename suggests it's "easy", upon opening or clicking the icon it will open gVim in "insert" mode and start typing immediately. While the other icon "gVim Read only 9.2", upon clicking or opening this icon. This will open gVim on "read only" as it names suggest. It's quite good if you only need to review or read the file. However, it says "read only" it doesn't mean that you cannot edit, modify or add text to the file. While inside "gVim Read only", press "insert" key or pre...

Move specific log files via Bash

Log files are important, for audit purposes, to check what's going on and a file to consult when something doesn't work as expected. However, log files can fill up disk space easily especially if the application or server being monitored is quite buya, thus it will also record quite a few lines on the log file. Of course the easy way, is always to do an mv command and just move the file somewhere. This is not practical if you need to move hundreds of files. To make things easy and efficient is to use a group or series of commands. For example, if you need to move files other than the log files for the month of November, then ls and egrep can do it. Example: ls | egrep -iv "*2025-11*" | egrep -iv "2025-11-template"  Above will list all files except files for the month of November and the template for the month of November. -iv tells egrep insensitive case, and don't include the pattern specified and list all files Double check the output if the ls and egr...

Add SSH keys to known-hosts in Linux

Setting up a new environment of Linux boxes either Physical servers, VMs or Containers, one thing to consider is how you will login or manage those devices. In Linux world, SSH is the most common way to manage headless servers or VMs. SSH keys must be added to ~/.ssh/known_hosts to preload to the host keys before connecting to the new servers. There quite a few ways to do it, via bash script, or simply logging in and copying manually the key.but quite tedious and not the practical way if there are hundreds of more servers. ssh-keyscan server1 server2 server3 >> ~/.ssh/known_hosts This will suppress the question whether you want to add the keys or not, and type yes to continue. ssh-keyscan won't require any manual intervention once the connectivity is established it will just add all the keys available on the remote servers to known_hosts. Yes rather than typing ssh-keyscan server1 server2 it would be better to have a list on a text file and use while loop to read the file and...