Regex to extract text of C-style comments

I needed to extract comments from some files to use for documentation and settled on the below two regex flavors (which you use depends on the tool / programming language). Requirement was to match on the whole document as many times as comments appeared and only match the text and comments in case of mixed code and comments on one line.

You could extend this further by adding tokens to only fetch certain comments.

First version is for gnu-grep that accepts the “global” and “single-line” pcre (Perl Compatible Regular Expressions) modifiers:

\/ matches the character / literally
\* matches the character * literally
.*? matches any character
Quantifier: *? Between zero and unlimited times, as few times as possible, expanding as needed [lazy]
\* matches the character * literally
\/ matches the character / literally
g modifier: global. All matches (don't return on first match)
s modifier: single line. Dot matches newline characters


Second is for cases you can’t use the prior, like some terminal apps:

From the command line, use:

pcregrep -M -o "\/\*[\s\S]*?\*\/" File.php

Where the “-M” does multiline searching, “-o” only returns the matching part of the line, and the “[\s\S]” matches any character including line breaks.

Use sudo with echo in shell

You can’t use sudo directly with echo in shell scripts / command line, so you need to use tee with append (-a). For example (simplified script example to update /etc/hosts for localhost entries):

if [ $(cat /etc/hosts | egrep -c "\s$1") == 0 ]; then
	echo " $1" | sudo tee -a /etc/hosts

Yum update only security-related packages

yum -y install yum-plugin-security

# To display all updates that are security relevant, and get a reutrn code on whether there are security updates enter:
yum --security check-update

# To upgrade packages that have security errata (upgrades to the latest available package) use:
yum --security update

# To upgrade packages that have security errata (upgrades to the last security errata package) use:
yum --security update-minimal

# See yum-security man page for more information:
man 8 yum-security

thanks, cyberciti

Yum lock version

Want to make sure a specific package (e.g., apache, php, etc.) don’t accidentally get updated via Yum, you can do:

yum install yum-versionlock
yum versionlock packagename


yum versionlock php-5.4*
yum versionlock list

to remove specific package:
yum versionlock delete php-5.4*

to remove ALL packages:
yum versionlock clear

Get directory sizes via command-line

For Linux and Mac etc:

du -sh *

Docker credentials and other info

To see/manage your current login and other info, do:

docker info

you should use commands like docker login to update, but if in doubt, the config data is normally stored in: ~/.docker/config.json

« Previous Entries