Sandra Henry-Stocker

Author Archives: Sandra Henry-Stocker

Selectively reusing commands on Linux

The Linux command line allows your system to remember commands that you use—up to a limit set by your HISTSIZE variable. Since each user’s HISTSIZE is generally set to 1000, that means Linux can remember the last 1000 commands you entered and make it easy to reuse them without retyping them.Unless you configure your history settings differently, all of your commands will be remembered. You can put some restrictions on that behavior if you like. For example, you might not want to save every command you use to read a man page or every time you type pwd to ask where you’re currently sitting in the file system. How to restrict the commands that are remembered and which are not is covered here.To read this article in full, please click here

Smart ways to compare files on Linux

Commands for comparing files have proliferated since the early days of Linux. In this post, we'll look at a suite of commands available for comparing files and highlight the advantages that some of the newer ones provide.diff One of the oldest and still popular commands for detecting and reporting on file differences is the diff command. Comparing two lists of meeting attendees, the diff command will simply and clearly show you the differences.$ diff attendance-2020 attendance-2021 10,12c10 < Monroe Landry < Jonathon Moody < Donnell Moore --- > Sandra Henry-Stocker Only the lines that are different are displayed. The output precedes lines that are only in the first file with < and those only in the second file with >.To read this article in full, please click here

Smart ways to compare files on Linux

Commands for comparing files have proliferated since the early days of Linux. In this post, we'll look at a suite of commands available for comparing files and highlight the advantages that some of the newer ones provide.diff One of the oldest and still popular commands for detecting and reporting on file differences is the diff command. Comparing two lists of meeting attendees, the diff command will simply and clearly show you the differences.$ diff attendance-2020 attendance-2021 10,12c10 < Monroe Landry < Jonathon Moody < Donnell Moore --- > Sandra Henry-Stocker Only the lines that are different are displayed. The output precedes lines that are only in the first file with < and those only in the second file with >.To read this article in full, please click here

Random identity generation in Linux

If you need to generate a list of names and addresses to test an application or a script that you're working on, Linux can make that surprisingly easy. There's a command called "rig" that will create name, address and phone number listings. As far as I can tell, out of the box, it only works with U.S. addresses and area codes. However, if this is indeed the case, you might be able to work around this problem.To use the rig command, you can just type "rig" on the command line, and a single name and address will be generated. You will see something like this:$ rig Mavis English 1015 Tulip St Anderson, IN  46018 (317) xxx-xxxx To generate a list with many addresses, use the -c option and specify the number of addresses that you want to see.To read this article in full, please click here

Random identity generation in Linux

If you need to generate a list of names and addresses to test an application or a script that you're working on, Linux can make that surprisingly easy. There's a command called "rig" that will create name, address and phone number listings. As far as I can tell, out of the box, it only works with U.S. addresses and area codes. However, if this is indeed the case, you might be able to work around this problem.To use the rig command, you can just type "rig" on the command line, and a single name and address will be generated. You will see something like this:$ rig Mavis English 1015 Tulip St Anderson, IN  46018 (317) xxx-xxxx To generate a list with many addresses, use the -c option and specify the number of addresses that you want to see.To read this article in full, please click here

Factorials and unscrambling words with bash on Linux

In this post, we examine a bash script that takes a string of letters, rearranges them in every possible way and checks each permutation to identify those that are English words. In the process, we'll take a close look at the script and calculate how hard it might have to work.Note that, in the algorithm used, each letter arrangement must use all of the letters in the string provided. Words formed by substrings are not considered.How to loop forever in bash on Linux First, the script expects the scrambled string to be provided as an argument and prompts for it if none is provided. It then checks out each arrangement of letters to find those that exist in the system's words file – in this case, that's /usr/share/dict/words. Here are the first lines in the script:To read this article in full, please click here

Factorials and unscrambling words with bash on Linux

In this post, we examine a bash script that takes a string of letters, rearranges them in every possible way and checks each permutation to identify those that are English words. In the process, we'll take a close look at the script and calculate how hard it might have to work.Note that, in the algorithm used, each letter arrangement must use all of the letters in the string provided. Words formed by substrings are not considered.How to loop forever in bash on Linux First, the script expects the scrambled string to be provided as an argument and prompts for it if none is provided. It then checks out each arrangement of letters to find those that exist in the system's words file – in this case, that's /usr/share/dict/words. Here are the first lines in the script:To read this article in full, please click here

Serious 10-year-old flaw in Linux sudo command; a new version patches it

Linux users should immediately patch a serious vulnerability to the sudo command that, if exploited, can allow unprivileged users gain root privileges on the host machine.Called Baron Samedit, the flaw has been “hiding in plain sight” for about 10 years, and was discovered earlier this month by researchers at Qualys and reported to sudo developers, who came up with patches Jan. 19, according to a Qualys blog. (The blog includes a video of the flaw being exploited.)To read this article in full, please click here

Serious 10-year-old flaw in Linux sudo command; a new version patches it

Linux users should immediately patch a serious vulnerability to the sudo command that, if exploited, can allow unprivileged users gain root privileges on the host machine.Called Baron Samedit, the flaw has been “hiding in plain sight” for about 10 years, and was discovered earlier this month by researchers at Qualys and reported to sudo developers, who came up with patches Jan. 19, according to a Qualys blog. (The blog includes a video of the flaw being exploited.)To read this article in full, please click here

Using vim to quickly encrypt and decrypt files

Any time you have a text file on a Linux system that you want to keep private regardless of the privileges that other users with accounts on the system may have, you can resort to encryption. One easy way to do this is to use a feature that is built into the vim editor. You will have to provide a password that will you then need to remember or store in a password safe, but the process is straightforward. The file name will not be changed in any way, and the content of the file can be recovered in much the same way that it was encrypted.To begin, let's say that we have a file that begins like this:$ head -3 mysecret I feel the need to put my deepest darkest secret into a text file on my Linux system. While this likely isn't common practice, I'm not sure that I can trust anyone with it. But a penguin? That's a different story! So here goes ... Now, not wanting to risk your deepest darkest secret to fellow users, you use vim with its -x (encryption) option.To read this article in full, please click here

Using the vim editor in Linux to quickly encrypt and decrypt files

Any time you have a text file on a Linux system that you want to keep private regardless of the privileges that other users with accounts on the system may have, you can resort to encryption. One easy way to do this is to use a feature that is built into the vim editor. You will have to provide a password that will you then need to remember or store in a password safe, but the process is straightforward. The file name will not be changed in any way, and the content of the file can be recovered in much the same way that it was encrypted.To begin, let's say that we have a file that begins like this:$ head -3 mysecret I feel the need to put my deepest darkest secret into a text file on my Linux system. While this likely isn't common practice, I'm not sure that I can trust anyone with it. But a penguin? That's a different story! So here goes ... Now, not wanting to risk your deepest darkest secret to fellow users, you use vim with its -x (encryption) option.To read this article in full, please click here

Using the vim editor in Linux to quickly encrypt and decrypt files

Any time you have a text file on a Linux system that you want to keep private regardless of the privileges that other users with accounts on the system may have, you can resort to encryption. One easy way to do this is to use a feature that is built into the vim editor. You will have to provide a password that will you then need to remember or store in a password safe, but the process is straightforward. The file name will not be changed in any way, and the content of the file can be recovered in much the same way that it was encrypted.To begin, let's say that we have a file that begins like this:$ head -3 mysecret I feel the need to put my deepest darkest secret into a text file on my Linux system. While this likely isn't common practice, I'm not sure that I can trust anyone with it. But a penguin? That's a different story! So here goes ... Now, not wanting to risk your deepest darkest secret to fellow users, you use vim with its -x (encryption) option.To read this article in full, please click here

Looking into Linux user logins with lslogins

One convenient way to list details about user logins on a Linux system is to use the lslogins command. You'll get a very useful and nicely formatted display that includes quite a few important details.On my system and likely most others, user accounts will start with UID 1000. To list just these accounts rather than include all of the service accounts like daemon, mail and syslog, add the -u option as shown in the example below.$ sudo lslogins -u UID USER PROC PWD-LOCK PWD-DENY LAST-LOGIN GECOS 0 root 151 0 0 root 1000 shs 68 0 0 12:35 Sandra H-S 1001 nemo 0 0 0 2021-Jan05 Nemo Demo,,, 1002 dbell 0 0 1 Dory Bell 1003 shark 2 0 0 7:15 Sharon Hark 1004 tadpole 0 0 0 2020-Dec05 Ted Pole 1005 eel 0 0 0 2021-Jan11 Ellen McDay 1006 bugfarm 0 0 0 2021-Jan01 Bug Farm 1008 dorothy 0 0 1 Dorothy Reuben 1012 jadep 0 0 1 2021-Jan04 Jade Jones 1013 myself 0 0 0 2021-Jan12 My Self 1014 marym 0 0 0 2020-Mar20 Mary McShea 1017 gijoe 0 0 0 GI Joe 65534 nobody 0 0 1 nobody What the lslogins command does is grab Continue reading

Looking into Linux user logins with lslogins

One convenient way to list details about user logins on a Linux system is to use the lslogins command. You'll get a very useful and nicely formatted display that includes quite a few important details.On my system and likely most others, user accounts will start with UID 1000. To list just these accounts rather than include all of the service accounts like daemon, mail and syslog, add the -u option as shown in the example below.$ sudo lslogins -u UID USER PROC PWD-LOCK PWD-DENY LAST-LOGIN GECOS 0 root 151 0 0 root 1000 shs 68 0 0 12:35 Sandra H-S 1001 nemo 0 0 0 2021-Jan05 Nemo Demo,,, 1002 dbell 0 0 1 Dory Bell 1003 shark 2 0 0 7:15 Sharon Hark 1004 tadpole 0 0 0 2020-Dec05 Ted Pole 1005 eel 0 0 0 2021-Jan11 Ellen McDay 1006 bugfarm 0 0 0 2021-Jan01 Bug Farm 1008 dorothy 0 0 1 Dorothy Reuben 1012 jadep 0 0 1 2021-Jan04 Jade Jones 1013 myself 0 0 0 2021-Jan12 My Self 1014 marym 0 0 0 2020-Mar20 Mary McShea 1017 gijoe 0 0 0 GI Joe 65534 nobody 0 0 1 nobody What the lslogins command does is grab Continue reading

Automating responses to scripts on Linux using expect and autoexpect

The Linux expect command takes script writing to an entirely new level. Instead of automating processes, it automates running and responding to other scripts. In other words, you can write a script that asks how you are and then create an expect script that both runs it and tells it that you're ok.Here's the bash script:#!/bin/bash echo "How are you doing?" read ans [Get regularly scheduled insights by signing up for Network World newsletters.] Here's the expect script that provides the response to the query:#!/usr/bin/expect set timeout -1 spawn ./ask # ask is name of script to be run expect "How are you doing?\r" send -- "ok\r" expect eof When you run the script, you should see this:To read this article in full, please click here

Checking network connections with arp and ip neigh

Linux provides two very useful tools for diagnosing network troubles: arp and ip neigh.The arp command is a tool that allows you to display the IP-address-to-MAC-address mappings that a system has built so that it doesn't have to fetch the same information repeatedly for systems it communicates with. In doing this, arp allows you to discover and display details about systems on your network.The other is the arp command's younger brother, ip neigh, which can also display and manipulate arp tables. In this post, we'll take a look at how these commands work and what they can tell you.To read this article in full, please click here

2021 New Year’s resolutions for Linux users

It's a good idea to start each year with some ideas about how to make the new year better--even when it comes to working with Linux. This post offers some suggestions on how you might get more value and enjoyment from Linux in 2021.Commit favorite commands to aliases or scripts Linux commands make it easy to manipulate files and command output, but the cleverest commands can be very difficult to remember and reuse. Commit them to a script or alias, on the other hand, and you can give them meaningful names that are easy to remember  and use them easily  any time you need. Here's an example of a complicated Linux command turned into an alias:To read this article in full, please click here

Searching Wikipedia on the Linux command line with wikit

Have you ever imagined looking up some topic on Wikipedia while you're working on the Linux command line? What about displaying the results in a different language? Yes, it's possible. In fact, it's quite easy. The tool that provides this service is called wikit (Wikipedia IT).To check if wikit is installed on your system, just type "which wikit". If it is, you will get a response like this:$ which wikit /usr/local/bin/wikit If it's not, you can install it, but you might need to first install nodejs which wikit depends on and maybe npm as well with a command like one of these:To read this article in full, please click here