You are herecommand-line

command-line


Grabbing all the PDF files from a website

I found a website (not listed) below that had the whole service manual for my car at no charge (normally about $300 US). The site gave me 74 links to PDF files! As excited as I was, I wasn't in the mood to click on 74 links. So I googled around and found the following one-liner.

wget `lynx -dump URL | grep .pdf$ | sed 's/[[:blank:]]\+[[:digit:]]\+\. //g'`
where URL is the URL where all the PDF files are.

11 seconds later I had all 74 PDF files. Cheers!

Linux: Find large files

Finds all files over 20,000KB (roughly 20MB) in size and presents their names and size in a human readable format:

find / -type f -size +20000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }' 

Installing the Sysinternals Suite

From: http://remstate.com/2008/06/13/sysinternals-suite/

More, more, more little tools. The Sysinternals Suite is a large collection of handy little tools — including such famous tools as PsExec. It’s just a zip file, so it’s easy to install.

First grab the zip file from the Microsoft Sysinternal web site: http://download.sysinternals.com/Files/SysinternalsSuite.zip

Assuming you have 7-zip's Command Line Version (http://www.7-zip.org/download.html) you can type the following:

7za x -o"D:\program files\sysinternals\" SysinternalsSuite.zip

You can also use whichever compression utility you please.

Then, simply add it to the path.

PATH %PATH%;D:\Program Files\sysinternals
SETX PATH “%PATH%” -m

Done. :)

Using stunnel to telnet into GMail IMAP

Here is a case study of how stunnel can be used to test an SSL based protocol. We will create an stunnel configuration that reroutes the IMAP port (TCP 143) to the Secure IMAP port (TCP 993) on GMail's IMAP server (imap.gmail.com). We will than test the setup by using telnet.

I will be using Ubuntu 8.10 (Intrepid Ibex).

First, let's install stunnel.

sudo apt-get install stunnel

Edit /etc/default/stunnel4, change ENABLED=0 to ENABLED=1

The FOR Command

The FOR command is one of those commands that can save you hours of repetitive work. As a sysadmin its important to look for easy ways to get rid of repetitive tasks like renaming files or copying a select number of files. I recently had to retrieve 3,000+ files from a folder containing over 3,000,000 files. Imagine how long it would take to selectively find these files. The benefit of the FOR command is that it is a "looping" command. In other words, it will do a given task over and over until a given condition is met.