Sandra Henry-Stocker

Author Archives: Sandra Henry-Stocker

The Linux fold command breaks up text, drives loops

The Linux fold command enables you to break a string of characters into same-size chunks, but it can also be used to provide a series of characters or strings to drive a loop. This post reviews the basic command and then demonstrates how you can use it to loop through the characters or strings that it creates.The basic use of the fold command is to take long lines of text and break them into shorter pieces. One common use is to shorten lines in a text file so that they display well in a terminal window. Lines wider than the terminal width might otherwise wrap in inconvenient places.The fold command can also be used to create a narrower file from a file with lines that are inconveniently long.To read this article in full, please click here

The Linux fold command breaks up text, drives loops

The Linux fold command enables you to break a string of characters into same-size chunks, but it can also be used to provide a series of characters or strings to drive a loop. This post reviews the basic command and then demonstrates how you can use it to loop through the characters or strings that it creates.The basic use of the fold command is to take long lines of text and break them into shorter pieces. One common use is to shorten lines in a text file so that they display well in a terminal window. Lines wider than the terminal width might otherwise wrap in inconvenient places.The fold command can also be used to create a narrower file from a file with lines that are inconveniently long.To read this article in full, please click here

Open-sourced tool speeds up Linux scripts via parallelization

MIT has open-sourced pa.sh (also called pash), a tool that can dramatically speed up Linux scripts by using parallelization, saving time and without risk of introducing errors.The process of parallelization first examines a script for code that can be run separately and independently, so not all scripts can benefit from the tool. But when pa.sh does find portions that can run independently, it runs them in parallel on separate CPUs. It also uses other techniques to get the code to run faster.Below is a demonstration I ran on my home Fedora box, first running a script on its own and then again using pa.sh. Note that this script was provided with the pa.sh tool and lends itself to parallelization. It’s not nearly as demanding as scripts that might process gigabytes of data in a scientific or artificial-intelligence lab, so the results are not dramatic.To read this article in full, please click here

Open-sourced tool speeds up Linux scripts via parallelization

MIT has open-sourced pa.sh (also called pash), a tool that can dramatically speed up Linux scripts by using parallelization, saving time and without risk of introducing errors.The process of parallelization first examines a script for code that can be run separately and independently, so not all scripts can benefit from the tool. But when pa.sh does find portions that can run independently, it runs them in parallel on separate CPUs. It also uses other techniques to get the code to run faster.Below is a demonstration I ran on my home Fedora box, first running a script on its own and then again using pa.sh. Note that this script was provided with the pa.sh tool and lends itself to parallelization. It’s not nearly as demanding as scripts that might process gigabytes of data in a scientific or artificial-intelligence lab, so the results are not dramatic.To read this article in full, please click here

Counting the days on Linux

Have you ever wondered how many days it’s been since you started your diet, begun your daily jogs, or were first working with Linux? If you can remember the start date, a simple Linux script can count the days for you. All you need is the date command and a calculation that turns your dates into seconds, subtracts the start date from the end date and then divides the result by the appropriate number to turn the seconds into the corresponding number of days.Why seconds? The reason for the conversion to days is that the date command can display a date as the number of seconds since the start of the Linux epoch—10=970-01-01. This is the only option date provides for looking at the time difference between two calendar dates.To read this article in full, please click here

Counting the days on Linux

Have you ever wondered how many days it’s been since you started your diet, begun your daily jogs, or were first working with Linux? If you can remember the start date, a simple Linux script can count the days for you. All you need is the date command and a calculation that turns your dates into seconds, subtracts the start date from the end date and then divides the result by the appropriate number to turn the seconds into the corresponding number of days.Why seconds? The reason for the conversion to days is that the date command can display a date as the number of seconds since the start of the Linux epoch—10=970-01-01. This is the only option date provides for looking at the time difference between two calendar dates.To read this article in full, please click here

Removing duplicate characters from a string on Linux with awk

The awk command can make it easy to remove duplicate characters from a string even when those characters aren’t sequential, especially when the process is turned into a script.First, the awk command that we’ll be using starts by running through each letter in the string. In a more common command, you might see awk doing something like this:$ echo one:two:three | awk ‘BEGIN {FS =":"} ; { print $2 }’ two [ Get regularly scheduled insights by signing up for Network World newsletters. ]   The FS portion of that command specifies the field separator—the character that is used to separate the fields in the string so that they can be processed separately.To read this article in full, please click here

Removing duplicate characters from a string on Linux with awk

The awk command can make it easy to remove duplicate characters from a string even when those characters aren’t sequential, especially when the process is turned into a script.First, the awk command that we’ll be using starts by running through each letter in the string. In a more common command, you might see awk doing something like this:$ echo one:two:three | awk ‘BEGIN {FS =":"} ; { print $2 }’ two [ Get regularly scheduled insights by signing up for Network World newsletters. ]   The FS portion of that command specifies the field separator—the character that is used to separate the fields in the string so that they can be processed separately.To read this article in full, please click here

Using htop to check performance on Linux

While it's one of the best tools for examining performance on Linux, htop still requires some explanation before you'll be ready to take advantage of all the data it displays. It’s an excellent tool, but you need to understand the coloring scheme, how to scroll up and down through the processes displayed, and how to change your view of what’s happening on the system.It may take some time to get used to the type of information shown and be ready to quickly notice performance problems. That, of course, means that you have to know what normal behavior looks like on your system, and this generally requires spending time with the tool on a relatively frequent basis. In other words, use htop when you’re not at all concerned about how your system is performing and you’ll likely be able to make good use of it when you are.To read this article in full, please click here

Using htop to check performance on Linux

While it's one of the best tools for examining performance on Linux, htop still requires some explanation before you'll be ready to take advantage of all the data it displays. It’s an excellent tool, but you need to understand the coloring scheme, how to scroll up and down through the processes displayed, and how to change your view of what’s happening on the system.It may take some time to get used to the type of information shown and be ready to quickly notice performance problems. That, of course, means that you have to know what normal behavior looks like on your system, and this generally requires spending time with the tool on a relatively frequent basis. In other words, use htop when you’re not at all concerned about how your system is performing and you’ll likely be able to make good use of it when you are.To read this article in full, please click here

Connecting to your Linux system with your Android phone

While using your cell phone to connect to your Linux system might not seem like much of a priority, it is possible and you might have a good reason to do this from time to time. If you have an Android cell phone, you can install a tool that will allow you to connect, open a terminal session on your Linux box and run commands just like you would if you were sitting in front of the system. Well, almost.The tool that I recommend is called JuiceSSH. It installs easily and leaves an icon with an image of a lemon with its name below it on your screen. Click on that icon and select Quick Connect to set up your connection.To read this article in full, please click here

Connecting to your Linux system with your Android phone

While using your cell phone to connect to your Linux system might not seem like much of a priority, it is possible and you might have a good reason to do this from time to time. If you have an Android cell phone, you can install a tool that will allow you to connect, open a terminal session on your Linux box and run commands just like you would if you were sitting in front of the system. Well, almost.The tool that I recommend is called JuiceSSH. It installs easily and leaves an icon with an image of a lemon with its name below it on your screen. Click on that icon and select Quick Connect to set up your connection.To read this article in full, please click here

Change an IP address from dynamic to static with a bash script

Changing the IP address of a Linux system from dynamic to static is not difficult, but requires a little care and a set of commands that you likely rarely use. This post provides a bash script that will run through the process, collect the needed information and then issue the commands required to make the changes while asking as little as possible from the person running it.The bulk of the script focusses on making sure that the correct settings are used. For example, it collects the 36-charater universally unique identifier (UUID) from the system so that you never have to type it in or copy and paste it into place. [ Get regularly scheduled insights by signing up for Network World newsletters. ]To read this article in full, please click here

Change an IP address from dynamic to static with a bash script

Changing the IP address of a Linux system from dynamic to static is not difficult, but requires a little care and a set of commands that you likely rarely use. This post provides a bash script that will run through the process, collect the needed information and then issue the commands required to make the changes while asking as little as possible from the person running it.The bulk of the script focusses on making sure that the correct settings are used. For example, it collects the 36-charater universally unique identifier (UUID) from the system so that you never have to type it in or copy and paste it into place. [ Get regularly scheduled insights by signing up for Network World newsletters. ]To read this article in full, please click here

Use bash to change an IP address from dynamic to static on Linux

Changing the IP address of a Linux system from dynamic to static is not difficult, but requires a little care and a set of commands that you likely rarely use. This post provides a bash script that will run through the process, collect the needed information and then issue the commands required to make the changes while asking as little as possible from the person running it.The bulk of the script focusses on making sure that the correct settings are used. For example, it collects the 36-charater universally unique identifier (UUID) from the system so that you never have to type it in or copy and paste it into place. [ Get regularly scheduled insights by signing up for Network World newsletters. ]To read this article in full, please click here

Use bash to change an IP address from dynamic to static on Linux

Changing the IP address of a Linux system from dynamic to static is not difficult, but requires a little care and a set of commands that you likely rarely use. This post provides a bash script that will run through the process, collect the needed information and then issue the commands required to make the changes while asking as little as possible from the person running it.The bulk of the script focusses on making sure that the correct settings are used. For example, it collects the 36-charater universally unique identifier (UUID) from the system so that you never have to type it in or copy and paste it into place. [ Get regularly scheduled insights by signing up for Network World newsletters. ]To read this article in full, please click here

Concatenating strings and using += in bash

It's quite easy to get bash to concatenate strings and do simple math on Linux, but there are a number of options for you to use. This post focusses on concatenating strings, but also shows how one of the operators (+=) also plays a primary role in incrementing numbers.Concatenating strings In general, the only time that you'd want to concatenate strings on Linux is when one string is already defined and you want to add more to it. For example, if you have a script that greets the person running it, you might set up a string in the script to prepare the greeting and then add the person's username or name before displaying it. [ Get regularly scheduled insights by signing up for Network World newsletters. ]To read this article in full, please click here

Concatenating strings and using += in bash

It's quite easy to get bash to concatenate strings and do simple math on Linux, but there are a number of options for you to use. This post focusses on concatenating strings, but also shows how one of the operators (+=) also plays a primary role in incrementing numbers.Concatenating strings In general, the only time that you'd want to concatenate strings on Linux is when one string is already defined and you want to add more to it. For example, if you have a script that greets the person running it, you might set up a string in the script to prepare the greeting and then add the person's username or name before displaying it. [ Get regularly scheduled insights by signing up for Network World newsletters. ]To read this article in full, please click here

Extracting substrings on Linux

There are many ways to extract substrings from lines of text using Linux and doing so can be extremely useful when preparing scripts that may be used to process large amounts of data. This post describes ways you can take advantage of the commands that make extracting substrings easy.Using bash parameter expansion When using bash parameter expansion, you can specify the starting and ending positions for the text that you want to extract. For example, you can create a variable by assigning it a value and then use syntax like that shown below to select a portion of it.To read this article in full, please click here

Extracting substrings on Linux

There are many ways to extract substrings from lines of text using Linux and doing so can be extremely useful when preparing scripts that may be used to process large amounts of data. This post describes ways you can take advantage of the commands that make extracting substrings easy.Using bash parameter expansion When using bash parameter expansion, you can specify the starting and ending positions for the text that you want to extract. For example, you can create a variable by assigning it a value and then use syntax like that shown below to select a portion of it.To read this article in full, please click here