Skip to main content

Posts

Recent posts

Linux variables to get UID/GID

User ID(UID), GID (Group ID) in Linux are numerical identifiers to set access to files, directories and system resources, just like rwx which in octal equivalent is r=4, w=2, x=1 and the desperate permission which will equal to 777.  777 is quite useful when nothing is working and an easy way out but yes use sparingly. UID and GID can be used also to restrict permissions or access. Quite a few ways to get UID value for the current login user. At terminal typing: echo "$UID" id -u echo/run/user/$UID All commands above are the same, get the user id of the currently logged in user. To get the GID, or the group membership of the currently logged in user is quite straight forward, at terminal type: id The output will be the  group-id(name of the group) and those are the group membership of the currently logged in user. id -Gn will just list the groups without the GID. id -G will just list the GIDs without name group Another quite useful variable, if let's say someone is asking...

Move selected files in Linux

How to move selected files in Linux via a one liner.command? Moving files is quite straight forward with mv command, if need to move a hundred or more files is another story. However, a group of commands like piping the output of the command to another command will make life easier. First, do an ls or list the files before moving the files to make sure those are the files that needs to be moved. ls | egrep -iv "*2025-11*" | egrep -iv "*2025-11-template*" After checking or listing the files then do the actual move. Here's an example: ls | egrep -iv "*2025-11*" | egrep -iv "*2025-11-template*" | xargs -I {} mv {} /my backup/logfiles The -iv parameters tells egrep to filter case insensitively and only shows files that doesn't match the pattern. That's it make life easier, work smart not hard. Let the technology work for you. Trust in God, Pray and don't worry. God is in Control, Be still.

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

Systemd *-ctl commands to manage Linux system

Systemd ecosystem provides tools to manage the Linux system. Here are some quick commands to check Linux system status. systemctl -  manage system services and units timedatctl - check system time, date and NTP localectl - quickly check system locale, language, kb layout hostnamectl - check static hostname, OS, kernel, architecture x86 or x64 resolvectl - quickly check DNS IP networkctl - quickly check interfaces names, operational status of interfaces, and setup whether managed or unmanaged loginctl - check session if, username, and for how long the user is logged in journalctl - to check services logs why some services are not starting  Those are the basic and most common ones. Enjoy Linux-ing. Keep the Faith alive, Trust Jesus! God bless!

Android Studio view XML code layout

View XML code in Android Studio. By default, in Android Studio Narwhal | 2025.1.1 Patch 1 what is shown is the layout of the XML. Android Studio, provides 3 options for previewing the XML. 1 - View by code Only 2 - View with XML code and the output or the layout 3 - View only the output of the XML or view the design only To select these options once an XML or layout file is opened. The options can be found on the top right of the screen, just beside the current XML file that os being viewed. See this screenshot below on how it looks like: Hope it helps. Life is a gift. Life is a journey. Trust the Almighty, Pray always.