Sandra Henry-Stocker

Author Archives: Sandra Henry-Stocker

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

Running a Linux terminal in your Windows browser

If you want to try using a Linux terminal and aren’t sitting anywhere near a Linux system, don’t despair. There are some services that will allow you to run a Linux terminal inside a browser. This post examines some of these and should give you a feel for what you can do and the performance you might experience.The Linux terminal sessions described here were all run on a Windows system using a Chrome browser. While you could as easily run a Linux terminal in a browser on a Linux system, you’d likely be less motivated to do so.JSLinux JSLinux is essentially a computer that’s implemented in JavaScript. So, all you need to do is open a browser and type the right URL to get started.To read this article in full, please click here

Running a Linux terminal in your Windows browser

If you want to try using a Linux terminal and aren’t sitting anywhere near a Linux system, don’t despair. There are some services that will allow you to run a Linux terminal inside a browser. This post examines some of these and should give you a feel for what you can do and the performance you might experience.The Linux terminal sessions described here were all run on a Windows system using a Chrome browser. While you could as easily run a Linux terminal in a browser on a Linux system, you’d likely be less motivated to do so.JSLinux JSLinux is essentially a computer that’s implemented in JavaScript. So, all you need to do is open a browser and type the right URL to get started.To read this article in full, please click here

Using strace and ltrace to help with troubleshooting on Linux

Both strace and ltrace are powerful command-line tools for debugging and troubleshooting programs on Linux: Strace captures and records all system calls made by a process as well as the signals received, while ltrace does the same for library calls.If a program acts differently than you expect, you can use these tools to see “behind the curtain” and maybe get some clues as to what is going on. [ Get regularly scheduled insights by signing up for Network World newsletters. ] Be forewarned, though. When you use either of these commands, you will end up with a lot of output to look through. Still, that can tell you quite a bit about how a process is working and sometimes give you important insights.To read this article in full, please click here

Using strace and ltrace to help with troubleshooting on Linux

Both strace and ltrace are powerful command-line tools for debugging and troubleshooting programs on Linux: Strace captures and records all system calls made by a process as well as the signals received, while ltrace does the same for library calls.If a program acts differently than you expect, you can use these tools to see “behind the curtain” and maybe get some clues as to what is going on. [ Get regularly scheduled insights by signing up for Network World newsletters. ] Be forewarned, though. When you use either of these commands, you will end up with a lot of output to look through. Still, that can tell you quite a bit about how a process is working and sometimes give you important insights.To read this article in full, please click here

How to cheat on Wordle using Linux

Wordle—the online game that gives you six tries to guess a five-letter word—has gone viral recently, and while it’s fun, it can also be pretty hard. So, as a bash-scripting enthusiast, I figured I'd see if I could come up with a script that would help me cheat.The game itself is fairly simple. After you enter a five-letter guess, the game indicates which of its letters are not in the mystery word by setting them off on a gray background, which ones are in the word but in the wrong location (orange background), and which ones are in the word and located in the right place (green background). Each guess must be a known English word, no capitals, no punctuation.To read this article in full, please click here

How to cheat on Wordle using Linux

Wordle—the online game that gives you six tries to guess a five-letter word—has gone viral recently, and while it’s fun, it can also be pretty hard. So, as a bash-scripting enthusiast, I figured I'd see if I could come up with a script that would help me cheat.The game itself is fairly simple. After you enter a five-letter guess, the game indicates which of its letters are not in the mystery word by setting them off on a gray background, which ones are in the word but in the wrong location (orange background), and which ones are in the word and located in the right place (green background). Each guess must be a known English word, no capitals, no punctuation.To read this article in full, please click here

Using whereis, whatis, and which to find out about commands on Linux

When you're trying to find your way around the Linux file system and want some information on specific commands, the whereis, whatis, and which commands can help. Each provides a different view of the command you're asking about. In this post, I'll compare these commands and explain what they tell us and what they don't tell us.which The which command is the simplest of the three. When you use it to ask about a Linux command, it will run down your search path looking for executable files by the name you specify. These can be commands that are available on your system as well as scripts. As long as the files provide you with execute privilege, they fit the bill. Here are some examples:To read this article in full, please click here

Using whereis, whatis, and which to find out about commands on Linux

When you're trying to find your way around the Linux file system and want some information on specific commands, the whereis, whatis, and which commands can help. Each provides a different view of the command you're asking about. In this post, I'll compare these commands and explain what they tell us and what they don't tell us.which The which command is the simplest of the three. When you use it to ask about a Linux command, it will run down your search path looking for executable files by the name you specify. These can be commands that are available on your system as well as scripts. As long as the files provide you with execute privilege, they fit the bill. Here are some examples:To read this article in full, please click here

Creating a quick calculation function on Linux

Anytime you're planning to do a lot of calculations on a Linux system, you can use the power of bash to create a quick function and then use it repeatedly to do the calculations for you. In this post, we'll look at how this trick works and what you need to be aware of to ensure that your calculations are correct.Let's start with this mathematical function as an example:$ ? () { echo "$*" | bc ; } Troubleshooting your bash scripts in Linux   This command sets up a function that will pass the values and mathematical operators that you provide as arguments to the bc calculator command. Note that to call the function, you simply type a "?" followed by the arguments. In the first example below, the arguments are 1, followed by the multiplication character "*", followed by a 2, a "+" sign and a 3. The result is 5.To read this article in full, please click here

Creating a quick calculation function on Linux

Anytime you're planning to do a lot of calculations on a Linux system, you can use the power of bash to create a quick function and then use it repeatedly to do the calculations for you. In this post, we'll look at how this trick works and what you need to be aware of to ensure that your calculations are correct.Let's start with this mathematical function as an example:$ ? () { echo "$*" | bc ; } Troubleshooting your bash scripts in Linux   This command sets up a function that will pass the values and mathematical operators that you provide as arguments to the bc calculator command. Note that to call the function, you simply type a "?" followed by the arguments. In the first example below, the arguments are 1, followed by the multiplication character "*", followed by a 2, a "+" sign and a 3. The result is 5.To read this article in full, please click here

Demystifying &&, ||, and ! on Linux

The &&, ||, and ! operators allow you to run a lot of useful commands on Linux, but you first need to get used to syntax that is a little trickier than the if-then-else command you might normally use.To get started, I should explain that one thing the command examples in this post have in common is the use of something that I might call a shorthand “if” test. Here’s an example:$ [ -f donuts ] $ echo %?1 The -f donuts command asks if there is a file (-f) named “donuts”. Unless we display the return code afterwards with "echo $?", the result of the test is not displayed. In this case, it’s false (i.e., not zero), so we know the file doesn’t exist. No donuts for us!To read this article in full, please click here

Demystifying &&, ||, and ! on Linux

The &&, ||, and ! operators allow you to run a lot of useful commands on Linux, but you first need to get used to syntax that is a little trickier than the if-then-else command you might normally use.To get started, I should explain that one thing the command examples in this post have in common is the use of something that I might call a shorthand “if” test. Here’s an example:$ [ -f donuts ] $ echo %?1 The -f donuts command asks if there is a file (-f) named “donuts”. Unless we display the return code afterwards with "echo $?", the result of the test is not displayed. In this case, it’s false (i.e., not zero), so we know the file doesn’t exist. No donuts for us!To read this article in full, please click here

2 ways to remove duplicate lines from Linux files

There are many ways to remove duplicate lines from a text file on Linux, but here are two that involve the awk and uniq commands and that offer slightly different results.Remove duplicate lines with awk The first command we'll examine in this post is a very unusual awk command that systematically removes every line in the file that is encountered more than once. It leaves the first instance of the line intact, but "remembers" it and removes any duplicates encountered afterwards.Here's an example. Initially, the file looks like this:To read this article in full, please click here

2 ways to remove duplicate lines from Linux files

There are many ways to remove duplicate lines from a text file on Linux, but here are two that involve the awk and uniq commands and that offer slightly different results.Remove duplicate lines with awk The first command we'll examine in this post is a very unusual awk command that systematically removes every line in the file that is encountered more than once. It leaves the first instance of the line intact, but "remembers" it and removes any duplicates encountered afterwards.Here's an example. Initially, the file looks like this:To read this article in full, please click here

Using the btrfsck file-checing command on Linux

The btrfsck command is a filesystem-check command like fsck, but it works with the btrfs file system.First a little bit about btrfs. As the name implies, btrfs uses a B-tree data structure that is self-balancing and maintains sorted data, facilitating searches, sequential access, insertions, and deletions. It is also often referred to as the “better file system”. Oracle developed it and first used it about 15 years ago. By November 2013, it was declared adequately stable and began to be used by other distributions as well, and now its use is quite common.Benefits of btrfs The benefits of btrfs are impressive, although it’s still a work in progress and some concerns have kept it from playing a more dominant role on Linux systems. It keeps 2 copies of metadata on a volume, allowing for data recovery if and when the hard drive is damaged or suffers from bad sectors. It uses checksums and verifies them with each read. In addition, compared to ext4 volumes, btrfs does not require double the storage space to accommodate file versioning and history data.To read this article in full, please click here

Using the btrfsck file-checing command on Linux

The btrfsck command is a filesystem-check command like fsck, but it works with the btrfs file system.First a little bit about btrfs. As the name implies, btrfs uses a B-tree data structure that is self-balancing and maintains sorted data, facilitating searches, sequential access, insertions, and deletions. It is also often referred to as the “better file system”. Oracle developed it and first used it about 15 years ago. By November 2013, it was declared adequately stable and began to be used by other distributions as well, and now its use is quite common.Benefits of btrfs The benefits of btrfs are impressive, although it’s still a work in progress and some concerns have kept it from playing a more dominant role on Linux systems. It keeps 2 copies of metadata on a volume, allowing for data recovery if and when the hard drive is damaged or suffers from bad sectors. It uses checksums and verifies them with each read. In addition, compared to ext4 volumes, btrfs does not require double the storage space to accommodate file versioning and history data.To read this article in full, please click here

Using the ldd command on Linux

Shared object files streamline programs by providing information applications need to do their jobs, but that don't have to be part of the application itself. To find out which of these files a Linux command calls on, use the ldd command.What is a shared object file? Shared object files (designated as .so) are libraries that are automatically linked into a program when the program starts, yet exist as a standalone files. They contain information that can be used by one or more programs to offload resources so that any program calling a .so file doesn't itself have to actually provide all the needed tools. These files can be linked to any program and be loaded anywhere in memory.To read this article in full, please click here

Using the ldd command on Linux

Shared object files streamline programs by providing information applications need to do their jobs, but that don't have to be part of the application itself. To find out which of these files a Linux command calls on, use the ldd command.What is a shared object file? Shared object files (designated as .so) are libraries that are automatically linked into a program when the program starts, yet exist as a standalone files. They contain information that can be used by one or more programs to offload resources so that any program calling a .so file doesn't itself have to actually provide all the needed tools. These files can be linked to any program and be loaded anywhere in memory.To read this article in full, please click here

1 2 3 23