Get Your grep-fu On

More sysadmin goodness from damonparker.org.

Search for red OR green:

grep ‘red|green’ files

Search for searchtext at the beginning of a line in files:

grep ‘^searchtext’ files

Search for searchtext at the end of a line in files:

grep ‘searchtext$’ files

Search files for blank lines:

grep ‘^$’ files

Search files for US formatted phone numbers (###-###-####):

grep ‘[0-9][0-9][0-9]-[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]’ files

or:

grep ‘[0-9]{3}-[0-9]{3}-[0-9]{4}’ files

Search for e-commerce or ecommerce in files:

grep e-*commerce files

Search for searchtext case-insenstively in files:

grep -i searchtext files

Chain two grep commands together for more advanced searches. Search for lines in files that contain both partial_name and function:

grep partial_name files | grep function

That one is great for searching source directories for a function definition when you can’t remember the completely function name.

My Review of Taquito

Originally submitted at Timbuk2

A compressible toiletry bag that lets you see it all.

Finally a good toiletry travel bag

By Johnny Rad from San Diego, CA on 4/23/2012
4out of 5

Pros: Lightweight, Roomy but not too big, High Quality
Best Uses: Traveling
Describe Yourself: Classic, Stylish, Comfort-Oriented, Career, Practical, Modern
Primary use: Personal
Was this a gift?: No

What can I say, it’s a toiletry bag, but it’s a toiletry bag you don’t have to hassle with to get all your stuff rolling for a trip. I love that I can put everything in one large pouch as opposed to several. The clear material is also great for nosey TSA inspections and what not, and to make sure you have everything you need before hitting the road.

My Review of Copilot Roller

Originally submitted at Timbuk2

An ultra-lightweight roller with serious carryin’ capacity.

Best Suitcase I’ve owned to date.

By Johnny Rad from San Diego on 4/23/2012
4out of 5

Pros: High Quality, Lightweight, Lots of Pockets
Best Uses: Traveling
Describe Yourself: Practical, Classic, Comfort-Oriented, Career
Primary use: Personal
Was this a gift?: No

Bought this suitcase to replace a suitcase that was causing me troubles for years. I thought it was high time to pay the premium and try a Timbuk2 Suitcase since I’ve had great results with my Timbuk2 2011 Command Messenger Laptop bag.

I purchased the medium sized roller. This suitcase is large enough but small enough to fit in the overhead carry on compartment of an airplane. The product material is high quality, durable and light weight. I was able to pack 7 days worth of clothing to Puerto Vallarta for a 4 day trip with room to spare. The roller skate wheels give this suitcase a smooth ride. There’s no roll fuss at all when wheeling this suitcase around.

Linux-Fu Part 3 :: Determining physical CPU and core count

With multicore CPUs these days it’s becoming easier for SysAdmins and users to be confused with what’s actually configured within a system.

We sometimes ask these sorts of questions:

1. How many physical CPUs does this system have?
2. How many cores does this system have on each CPU?

Rather than parsing through the /var/log/dmesg file or the /proc/cpuinfo file. We can cat and grep against the cpuinfo file with some simple commands to see what we need.

Determining physical CPU count:

Run:

cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l

Example:

[root@deadbeef ~]# cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l

Output:

1

The value of 1 here denotes that there is one physical cpu.

Determining cores per CPU:

Run:

cat /proc/cpuinfo | grep "cpu cores" | uniq

Example:

[root@deadbeef ~]# cat /proc/cpuinfo | grep "cpu cores" | uniq

Output:

cpu cores: 4

The value of 4 here denotes that each physical CPU has 4 cores (Based on these example commands, this hypothetical deadbeef system has 1 physical cpu w/ 4 cores).