Tech Tips

by Staff
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

Send a tech tip to techtips@linuxjournal.com, and if we publish it in the magazine, we'll send you a free T-shirt.

Load Disqus comments