Aggregator

Working with Linux File Links

6 days 22 hours ago

 LinuxTechlab: Connecting a filename to the actual data is managed by the filesystem using a table or data structure, which is called a title allocation table. I

Globbing and Regex: So Similar, So Different

1 week ago
by Shawn Powers

Grepping is awesome, as long as you don't glob it up! This article covers some grep and regex basics.

There are generally two types of coffee drinkers. The first type buys a can of pre-ground beans and uses the included scoop to make their automatic drip coffee in the morning. The second type picks single-origin beans from various parts of the world, accepts only beans that have been roasted within the past week and grinds those beans with a conical burr grinder moments before brewing in any number of complicated methods. Text searching is a bit like that.

For most things on the command line, people think of *.* or *.txt and are happy to use file globbing to select the files they want. When it comes to grepping a log file, however, you need to get a little fancier. The confusing part is when the syntax of globbing and regex overlap. Thankfully, it's not hard to figure out when to use which construct.

Globbing

The command shell uses globbing for filename completion. If you type something like ls *.txt, you'll get a list of all the files that end in .txt in the current directory. If you do ls R*.txt, you'll get all the files that start with capital R and have the .txt extension. The asterisk is a wild card that lets you quickly filter which files you mean.

You also can use a question mark in globbing if you want to specify a single character. So, typing ls read??.txt will list readme.txt, but not read.txt. That's different from ls read*.txt, which will match both readme.txt and read.txt, because the asterisk means "zero or more characters" in the file glob.

Here's the easy way to remember if you're using globbing (which is very simple) vs. regular expressions: globbing is done to filenames by the shell, and regex is used for searching text. The only frustrating exception to this is that sometimes the shell is too smart and conveniently does globbing when you don't want it to—for example:

grep file* README.TXT

In most cases, this will search the file README.TXT looking for the regular expression file*, which is what you normally want. But if there happens to be a file in the current folder that matches the file* glob (let's say filename.txt), the shell will assume you meant to pass that to grep, and so grep actually will see:

grep filename.txt README.TXT

Gee, thank you so much Mr. Shell, but that's not what I wanted to do. For that reason, I recommend always using quotation marks when using grep. 99% of the time you won't get an accidental glob match, but that 1% can be infuriating. So when using grep, this is much safer:

grep "file*" README.TXT

Because even if there is a filename.txt, the shell won't substitute it automatically.

Go to Full Article
Shawn Powers

Linus Torvalds Taking a Break, Help Krita Squash the Bugs, Vulnerability in Alpine Linux, Flatpak Now Works on Windows Subsystem for Linux and AnsibleFest 2018 Announced

1 week ago

News briefs for September 17, 2018.

Linus Torvalds is taking a break. In his rc4 email update over the weekend, he writes about his scheduling mix-up with the kernel summit and having a "look yourself in the mirror moment", and then (to summarize), he writes: "hey, I need to change some of my behavior, and I want to apologize to the people that my personal behavior hurt and possibly drove away from kernel development entirely. I am going to take time off and get some assistance on how to understand people's emotions and respond appropriately."

Krita announced its developer fundraiser "let's squash the bugs"! The goal this year for the open-source graphics editor is to "fix bugs, make Krita more stable and bring more polish and shine to all the features we have made possible together". Visit here to learn how you can help.

A vulnerability, has been discovered in Alpine Linux, which is commonly used in Docker images. Worst-case scenario, according to The Register, an "attacker could intercept apk's package requests during Docker image building, inject them with malicious code, and pass them along to the target machines that would unpack and run the code within their Docker container." Update apk and images now.

Alexander Larsson, lead developer and creator of the Flatpak package system, announced via Twitter that it now works on Windows Subsystem for Linux. See the post on Neowin for more on the story, and the "hacky workarounds" required.

Red Hat announces AnsibleFest 2018, which will be held October 2-3, in Austin, Texas and will cover many aspects of IT automation. See the AnsibleFest website for all the details.

News Linus Torvalds kernel Krita Alpine Linux Docker Security Windows Flatpak Ansible Red Hat
Jill Franklin