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

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix