Tech Tips

 in
Making ps aux | grep Work Right

When using ps aux | grep to look for processes, I get annoyed when I find the grep process in my search. For example:

$ ps aux | grep firefox
user  ...  /usr/lib/firefox-3.5.8/firefox
user  ...  grep --color=auto firefox

To avoid this issue, I use a character class regular expression that is only one character long. Simply put, I enclose one of the letters in my search term in brackets, like this:

$ ps aux | grep firef[o]x
user  ...  /usr/lib/firefox-3.5.8/firefox

This prevents the grep process itself from matching the search term, because the search term is “firefox”, but the grep command contains “firef[o]x”.

—Ross Larson

Extract Audio from the pacpl (Perl Audio Converter) Command-Line Tool

The pacpl command-line tool allows you to extract the audio from any type of video format. The command usage is like so:

pacpl -to OUTPUT-FORMAT INPUT-FILE

For example, to extract the audio from an .mov video and store it in an .mp3 file, do the following:

$ pacpl -to mp3 2010-01-Five_Minutes_SpringRoo.mov

Perl Audio Converter - 4.0.5

Converting: [2010-01-Five_Minutes_SpringRoo.mov] -> [mp3] ..done.

Total files converted: 1, failed: 0

The output is stored in the 2010-01-Five_Minutes_SpringRoo.mp3 file in the same directory.

—Mahendran Natarajan

Convert PDF Documents to JPEG Images

If you want to convert a PDF document to a JPEG image, first use pdftoppm to convert it to a PPM (Portable Pixel Map) file, and then use ppmtojpeg to convert it to a JPEG file.

First, convert the PDF:

$ pdftoppm input.pdf output

This generates one PPM image per PDF page in files named output-N.ppm (where N is the page number). If you want only part of the document, specify the first page to convert with -f N and the last page to convert with -l N.

Finally, to convert all the PPM files to JPEG images, you can do something like this:

$ for file in *.ppm
> do
>   ppmtojpeg $file > ${file/.ppm/.jpg}
>   rm $file
> done

—Malick Khady DIA

Play Videos Packed in a RAR File without Extracting Them

Most DivX/Xvid movies you download from Torrent sites are packed in multiple RAR archives. It takes some time and space to extract each of them. If you don't want to wait, or use the space, you can use VLC and unrar to play the files without extracting them. You won't be able to rewind and fast-forward within the file, but you'll be able to play and stop the movie without actually unarchiving the video file. Here's how:

$ unrar p -inul /path/to/movie_folder/movie.name.r00 | vlc -

—Malick Khady DIA

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Another solution for Grep

feel's picture

In the first tip it's possible to use twice grep, like this:
ps aux | grep -v grep | grep firefox

The -v option. Invert the sense of matching, to select non-matching lines.
The first grep exclude lines which have a "grep" word.

Best practices: There probably should be quotes on var refer

dj's picture

Best practices: There probably should be quotes on variable references.

> ppmtojpeg $file > ${file/.ppm/.jpg}
> rm $file

Randall Schulz has detailed explanation here:
http://lists.opensuse.org/opensuse/2006-11/msg02249.html

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState