Skip to main content

Posts

Showing posts from October, 2025

vim or vi searching for whole words or string

Search for a whole word or string in VI or VIM, can be done easily and a time savee so no need to keep pressing next or 'n' for the next match. How to search for a whole word or string in VI or VIM? Example open a file with a list of IP addresses. vim list-of-local-ips.txt Example contents: 192.168.13.130 192.168.13.131 192.168.13.1 192.168.13.135 192.168.13.137 192.168.13.23 192.168.13.13 192.168.13.100 If vi or vim is insert mode, press ESC until it's in command mode, If need to search for 192.168.13.1, or just 13.1 In comand-line mode type:  :/\<13.1\> and press enter  Or see picture below: After pressing enter it will go directly to 192.168.13.1,  if /13.1 is type then it will match also 192.168.13.135, 192.168.13.131 etc.. But with the /\<word or string\> syntax it will find the whole word. That's it, explore vi/vim for time saver tips. Cheers! Lift up your needs in Prayer; with a humble and contrite heart. God listens to the broken hearted....

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...

Linux Bash rename multiple files

Bash script/command below shows how to rename multiple files. If the filename shows some pattern, then it will be easier to rename.  Example filename: file_text_a.txt file_text_b.txt file_text_c.txt file_text_etc... ... .txt Script/command below, shows some magic to rename files all at once. The command below can be integrated to a script or simply run the command on the terminal. Create some dummy files for testing before running on actual files to be renamed or in production. find . -name "*.txt" -exec sh -c '   for file; do       newf=$(echo "$file" | sed "s/text/tested/" )  &&   mv "$file" "$newf"   done ' sh {} + Output is: file_tested_a.txt file_tested_b.txt Since the command uses sed, replace 'text' with any string to be searches and replace 'tested' also with any new string for the filename. Till next time.. Enjoy Linux and scripting... Put your trust in God and have Faith. Exodus 14:14, "The...