5/14/10

Import Blogger Beta Posts to WordPress


A lot of people who enter the world of blogging start out using free hosts with the three most popular hosts being Blogger, Wordpress and TypePad. Using such hosts, you can start a blog, your easy-to-use web site, where you can quickly post thoughts, interact with people, and more. All for FREE.

So what happens once your blog becomes very popular because of your original creative and useful content. You can still stay on Blogger, but most publishers want to move to their own website where they have total control.

Google’s Blogger service contines to hold the lion’s share among free blog hosting services. So, you have your blog hosted by Blogger and you decided to move to your own website using WordPress as your publishing platform. So you go to WordPress, and download the exec and upload it to your site. Finally, you decide to import your valuable posts and comments from Blogger to WordPress. Guess what you will see.

Wordpress import options

In the import options you will see

Old Blogger — Import posts, comments, and users from an Old Blogger blog
Blogware — Import posts from Blogware
DotClear — Import categories, users, posts, comments, and links from a DotClear blog
GreyMatter — Import users, posts, and comments from a Greymatter blog
LiveJournal — Import posts from a LiveJournal XML export file
Movable Type and TypePad — Import posts and comments from a Movable Type or Typepad blog
RSS — Import posts from an RSS feed
Textpattern — Import categories, users, posts, comments, and links from a Textpattern blog
WordPress — Import posts, comments, custom fields, pages, and categories from a WordPress export file

If you are using a @gmail.com email address to sign in into your Blogger account, you cannot use the import feature in WordPress. So, how do you move your posts from Blogger Beta or the New Blogger to Wordpress. You have three options

Method # 1: Copy and paste your posts

This is the worst method where you log into your blogger and wordpress account and manually copy and paste your post content from your blogger post to the wordpress post. This can easily become very tedious if you have a large blog. Also, how do you import the valuable comments? You can’t.

Method # 2: Use a Wordpress plugin to import from Blogger Beta to Wordpress

You can use Ady Romantica’s Blogger RSS Import plugin to import from Blogger beta to wordpress. However, this method is not a simple plug and play. There are a lot of issues using this plugin. The author himself provides a link to WordPress suicide to mass delete your wordpress posts in case the import fails and you have to try again. However, if you are looking at the plugin option, this is the best and only option right now.

Method # 3:

Import Blogger Beta Posts to WordPress

This is the best and the easiest method to migrate from Blogger to Wordpress.

In this example we will be moving from student-rant.blogspot.com to studentrant.wordpress.com and finally to studentrant.com.

Step # 1: First, you have to create an account with Wordpress.com. Creating an account takes less than a minute where all you need to provide is your Blog name, admin name and an email address.

Step # 2: After your account is ready, we will now import out Blogger Beta posts. Yes, if you create a WordPress account with wordpress themselves, they provide this option.

import from new blogger to wordpress

To import your blogger beta posts, go to “Manage” tab and then choose “Import“. Choose “Blogger” and after that “Authorize” and grant access to your Blogger Beta account.

Grant access by Blooger to allow import to Wordpress

Step # 3: After that, you just need to press “Import” and magic starts happening. All your Blogger posts, comments and categories are imported to the Wordpress blog you just created. So, after this step, we will have moved from student-rant.blogspot.com to studentrant.wordpress.com

import from blogger account to wordpress

Step # 4: Export from this wordpress.com Wordpress account to your website using WordPress. From your wordpress.com account, go to “Manage” and then export. When you click “Download Export File” , WordPress will create an XML file for you to save to your computer. This format, which we call WordPress eXtended RSS or WXR, will contain your posts, comments, custom fields, and categories. Once you’ve saved the download file, you can use the Import function on your real WordPress blog(in this case www.studentrant.com) to import this blog.

 export from wordpress.com blog to your actual blog

Step # 5: Import the XML file from your computer to your website running Wordpress. Go to Manage, Import on your wordpress dashboard. Browse to where you saved the XML file and then select “upload file and import”. All your blogger posts, comments and categories are now imported to your wordpress blog.

Import wordpress XML file to your website running wordpress

UPDATE (5/16/07)

WordPress 2.2 has been released today. This new version features an import option which allows you to directly import your blogger beta posts and comments without the need for the above mentioned method. Check out this post here

Migrating from New Blogger Beta to WordPress using WordPress 2.2 

UPDATE (4/27/07):

A couple of guys have posted in the comments section that when they try to import from blogger they see a 0/0 posts or 0/0 comments.

Step # 1: In your Blogger account, Click Formatting and change the Timestamp format to be mm/dd/yyyy hh:mm:ss AM/PM which is the first choice in the dropdown menu

Step # 2: Click Archiving and set Archive Frequency to Monthly

Step # 3: Come back to your wordpress.com blog and hit “Clear Account Information” first.

Start importing

(Thanks Jim and RobJKentJr)

Posted via web from bithacker's posterous

5/12/10


Get 250MB of extra space on DropBox - http://ping.fm/HGXRD

5/3/10


The cool Nautilus Elementry http://ping.fm/8820x

Install Nautilus Elementary (2.30) In Ubuntu 10.04 Lucid Lynx


nautilus elementary 2.30 ubuntu lucid


The simplified / elementary Nautilus idea firstly begun with the 100 paper cuts for Ubuntu Karmic and it stated that the menu and columns are too big and take away space for the really important stuff. Unfortunately, a fix was never released. Here is where Nautilus Elementary comes in: a Nautilus patched for simplicity.

About a week ago we were telling you that Nautilus Elementary 2.30 for Ubuntu 10.04 was in progress. Well, now you can finally install it.

What's new in Nautilus Elementary 2.30 for Ubuntu 10.04 Lucid Lynx


You can set the toolbar either vertical or horizontal:

nautilus elementary horizontal toolbar



Nautilus elementary 2.30 vertical toolbar


Nice looking breadcrumbs (needs a special gtkrc theme such as Elementary Mod)

nautilus elementary breadcrumbs


A new gadget: view_switcher mini widget:

nautilus elementary mini view switcher



nautilus elementary view switcher


You can now tweak Nautilus Elementary from within Nautilus: simply go to Edit > Preferences, on the "Tweaks" tab. Note: only new Nautilus windows will have the new settings (which you apply under the "Tweaks" tab), so simply open a new Nautilus window to use the new settings:

nautilus elementary tweaks tab



Nautilus Elementary 2.30 for Ubuntu 10.04 Lucid Lynx also comes with all the tweaks that were in Karmic such as RGBA, "F8" to toggle the menu bar and so on. The one thing missing for now is the ClutterFlow view.


How to install Nautilus Elementary 2.30 in Ubuntu 10.04 Lucid Lynx


nautilus elementary 2.30 ubuntu 10.04 LTS lucid lynx


Nautilus Elementary 2.30 is not yet available in any PPAs, but the compilation process is very easy. Simply paste the following commands in a terminal:

bzr branch lp:nautilus-elementary/2.30
sudo apt-get install build-essential intltool
sudo apt-get build-dep nautilus
cd 2.30/
./configure --prefix=/usr && make && sudo make install

To enable RGBA transparency in Nautilus, please remember that it only works with themes which use the Murrine Engine (Ambiance, Radiance, Elementary, Airlines from the Bisigi themes and so on). Also, you need to enable RGBA in the theme settings. To do this, open nautilus as root:

sudo nautilus
Then navigate to /usr/share/themes and for the theme you want to enable RGBA transparency for, navigate to the gtk-2.0 folder, open the "gtkrc" file with a text editor, search for "rgba" and change it from "false" to "true.


Update: there is now a PPA repository available for Nautilus Elementary 2.30 (for Ubuntu 10.04 Lucid Lynx).

Thanks to ammonkey for the news and 2 of the screenshots in this post.

Posted via web from bithacker's posterous

5/2/10

Restore the Default Gnome Panels in Ubuntu 10.04


Sometimes crazy things happen when you’re using Ubuntu, especially when you’re first getting started. It’s easy to mess things up and sometimes hard to get them back to normal. One problem I often see is that people accidentally delete their top or bottom panels (the bars that go across the top and bottom of your desktop and contain menus and other useful widgets).  It can be especially frustrating when your top panel disappears along with the Application Menu … what’s a person to do?

You might see instructions in a forum or on a blog post that tell you how “easy” it is to restore your default panels with some “simple” Terminal commands. While these commands might be easy for the seasoned Linux geek, they can be confusing for everyone else.  In an attempt to make things as simple as possible, I edited a small program originally found here, and made something that will hopefully get you back to Ubuntu bliss as quickly as possible.

Introducing: PanelRestore

PanelRestore is a small program that will allow you to restore the default Ubuntu panels quickly (it will also allow you to backup and restore your existing panel configurations). Here’s how to use it.

1. Download PanelRestore – Right-click here and choose “Save Link As”. Save the PanelRestore.tar.gz file on your desktop.

2. Find the PanelRestore.tar.gz on your desktop, right-click on it and then click on “Extract Here.”

3. You should now see another file on your desktop called “PanelRestore.sh.”  Double click on this file and you will be presented with a pop-up window asking you what you want to do – click “Run.”

4. Now you will see the main program window. Here you have the choice to save your current panel settings and restore panel settings from a file, or to restore the default panel settings. Choose “Restore Default Panel Settings” and click “OK.”

5. If you’re sure that you want to restore the default Ubuntu panels, click “OK.”

6. Enjoy!

Posted via web from bithacker's posterous

4/30/10


BitHacker: 10 things to do after installing Ubuntu 10.04 Lucid http://ping.fm/VaEMr

10 things to do after installing Ubuntu 10.04 Lucid


imageIf you’re going to be installing a freshly minted copy of Ubuntu 10.04 LTS later today or this weekend then the following list of 10 reader submitted post-install must-do’s will help ensure that you’re off to a flying start with your new OS.

1. Run Update Manager

Just because you’ve installed the latest version of Ubuntu doesn’t mean that there won't be some updates and patches waiting for you. Make sure you run the update manager (if it doesn’t update you first) so that you’re benefitting from the latest fixes and features.

2. Enable graphics card drivers for 3D fun

If you want to use advanced desktop effects such as Compiz (3d Cube, wobbly windows) then you will need to enable the “official” drivers for your graphics card.

Ubuntu should automatically detect and alert you that 3D drivers are available. If so, you will see a ‘circuit board’ icon appear on the top panel. Click this and follow the prompts.

If Ubuntu fails to detect any hardware (do be patient as this isn’t always instant) then you can manually run the hardware configuration tool yourself from the System > Preferences menu.

3. Enable playback of MP3’s, MP4’s & more

It’s a shame this step has to be included at all but sadly Ubuntu aren’t allowed by law to ship certain multimedia codec's out of the box. Installing them yourself, thankfully, is a breeze – just click the button below!image


4. Install more themes

Want a bigger selection of themes to choose between? You’ll find many beautiful and stylish ones in the Community Themes package.

5. Change font and/or font size

I know what you’re thinking: those fonts look huge, huh? Set them to a smaller size via the Appearance menu (Shortcut: Right click on Desktop > Change Background > Fonts).

Most readers find size 9pt works well but if you have a very wide display 8pt may suit you better.
If the default font isn’t to your taste a lot of readers suggested installing DroidSans.image

Many users also recommend you install the Microsoft Core fonts package for better web browsing:
image

6. Set up UbuntuOne file sync

If you don’t already use UbuntuOne now is the perfect time to do so. You'll get 2 GB of free storage, you are able to sync your Firefox bookmarks, Tomboy notes and Evolution contacts between computers – as well as any file or folder you wish.

Head to Applications > Internet > UbuntuOne to get started.

7. Install Ubuntu Tweak and make your life easier

Ubuntu Tweak is a one-stop shop for managing and installing extra applications, tweaking your desktop (such as putting the window controls back on the right and choosing which icons show on the desktop) and allowing you to keep your system in tip-top shape with the built in system cleaning options. (Ubuntu tweak recently won our ‘Best System Cleaners’ poll by a landslide – and for good reason!)
image

8. Visit the Software Centre to find great apps

One size certainly does not fit all so if you’re wanting to add VLC, install Photoshop rival The GIMP or play some awesome games then look no further than the Ubuntu Software Centre which can be launched from the Applications menu.

Everything is one-click install so browse around – make sure you check out the featured applications section, too!

9. Download the Ubuntu Manual

The “Ubuntu Manual” (which is actually called ‘Getting Started with Ubuntu 10.04’ but Manual sounds cooler) is a fantastic source of information for both newcomers and those who consider themselves apt with Ubuntu.

It has a straight-forward and easily accessible style, lots of screenshots and step-by-step instructions how how to get the best out of Ubuntu 10.04 LTS.image

10. Enjoy using it!

Forget about finding new apps or tweaking some part of Lucid for an hour or so and just use Ubuntu like anyone else would: Browse the net, chat on Empathy, type up that letter in Open Office and listen to something awesome in Rhythmbox.

Enjoy the awesomeness of Ubuntu 10.04 LTS as your survey your desktop like you are a king surveying your estate.

Posted via web from bithacker's posterous


Gano.la Energy Saver http://ping.fm/0VnoB

Go Green with Granola Energy saver - Linux & Windows


Granola Scales Your CPU for Energy SavingsGranola Scales Your CPU for Energy SavingsWindows/Linux: Your computer's processor may be able to handle 3D shooters and complex rendering, but most of the time, you probably just need it to render Gmail. System utility Granola scales back your processor at such times to save energy and money.

Like any modern energy-saving utility, Granola offers both to-date cumulative stats on how much energy, money, and CO2 it's saved, and how much you can expect to save over a year's time, given current computer conditions. It needs a processor that's capable of scaling, along with that option to be enabled in the BIOS settings. What kind of savings should the average user expect? From Granola's FAQ page:

If you mostly surf the Internet and check email, the savings will be substantial and probably 30% or more. If you are playing the latest intensive graphic game without a high-end graphics card, the savings will probably be less; perhaps as low as 10%. But most likely, your system has many uses and the load varies with time. Our users typically experience savings of around 25%.

It's only the processor that Granola works on, and it would be a bit more convenient if it offered an easy on/off switch as a keyboard shortcut or from its system tray menu. Still, it's a neat addition to the many ways one can green their PC. It's a free download for Windows and Linux systems.

Posted via web from bithacker's posterous

4/17/10

How To Integrate ClamAV Into PureFTPd For Virus Scanning On Debian Lenny | HowtoForge - Linux Howtos and Tutorials


This tutorial explains how you can integrate ClamAV into PureFTPd for virus scanning on a Debian Lenny system. In the end, whenever a file gets uploaded through PureFTPd, ClamAV will check the file and delete it if it is malware.

I do not issue any guarantee that this will work for you!

 

1 Preliminary Note

You should have a working PureFTPd setup on your Debian Lenny server, e.g. as shown in this tutorial: Virtual Hosting With PureFTPd And MySQL (Incl. Quota And Bandwidth Management) On Debian Lenny.

 

2 Installing ClamAV

ClamAV can be installed as follows:

aptitude install clamav clamav-daemon

 

3 Configuring PureFTPd

First we create the file /etc/pure-ftpd/conf/CallUploadScript which simply contains the string yes:

echo "yes" > /etc/pure-ftpd/conf/CallUploadScript

Next we create the file /etc/pure-ftpd/clamav_check.sh (which will call /usr/bin/clamdscan whenever a file is uploaded through PureFTPd)...

vi /etc/pure-ftpd/clamav_check.sh

#!/bin/sh  /usr/bin/clamdscan --remove --quiet --no-summary "$1"

... and make it executable:

chmod 755 /etc/pure-ftpd/clamav_check.sh

Now we edit /etc/default/pure-ftpd-common...

vi /etc/default/pure-ftpd-common

... and change the UPLOADSCRIPT line as follows:

[...]  # UPLOADSCRIPT: if this is set and the daemon is run in standalone mode,  # pure-uploadscript will also be run to spawn the program given below  # for handling uploads. see /usr/share/doc/pure-ftpd/README.gz or  # pure-uploadscript(8)    # example: UPLOADSCRIPT=/usr/local/sbin/uploadhandler.pl  UPLOADSCRIPT=/etc/pure-ftpd/clamav_check.sh  [...]

Finally we restart PureFTPd:

/etc/init.d/pure-ftpd-mysql restart

That's it! Now whenever someone tries to upload malware to your server through PureFTPd, the "bad" file(s) will be silently deleted.

 

4 Links

Posted via web from bithacker's posterous

Use TeamViewer for remote Linux support now on Linux - Jack Wallen



Have you ever been asked to do any Linux desktop remote support only to find out the client didn’t have secure shell (so no tunneling of X) nor did they have a vnc server setup? In these cases, what would you do? You still need to be able to support that client. Or what if you had a Windows client that needed support and the only operating system you had available was a Linux box? In that case, you need TeamViewer. TeamViewer is an incredibly easy to use remote support tool that allows you to do more than many similar tools.

With TeamViewer you can remote control a session, record a session, do VoIP, switch sides with client, and more. It truly is one of the finest free remote support tools you will find. In this article I will show you how to install and use TeamViewer on a Linux machine.

Getting and Installing

For the purposes of this article, I will show you how to install TeamViewer on a Ubuntu 10.4 installation. This install is simple if you follow these steps:

  1. Open up your web browser and point it to the Download Page.
  2. Download the .deb file that matches your architecture (32 or 64 bit).
  3. Allow GDebi to install the software automatically.

Once installed, you will find TeamViewer in Applications > Internet > TeamViewer.

Using TeamViewer

The use of this software requires it to be installed on both client machines. If you are doing support, that means you will have to walk your client through the installation of TeamViewer on their machines. Once they have the software installed here are the steps to using TeamViewer:

Figure 1

  1. Start up TeamViewer on both ends.
  2. From the Client side (non-support side) record the ID and Password as shown on the Session window (see Figure 1).
  3. On the Support side enter the ID from the client window in the ID section of the Create Session side.
  4. Click Connect to partner.
  5. In the Authentication window enter the password shown and click Log On

Figure 2

Once you connect a new window will open with your connection to your client (see Figure 2).

What is really nice about TeamViewer is that it doesn’t matter if you are using Linux on the client side or support side – it will connect and you will be able to remotely manage the machine. You do not need to install any extra widget sets or anything out of the ordinary. They will simply connect.

Extra features

If you look at the drop-down bar at the top of Figure 2 you will notice a few buttons. These buttons offer a number of extra features such as:

  • Actions: Remote reboot, Send Ctrl-Alt-Del to the client, switch sides
  • View: Change the quality of your remote display
  • Audio/Video: Use VoIP
  • File Transfer: Transfer files between machines.
  • Extras: Record a session, start  VPN connection, do a remote update

When you want to end a session all you have to do is click the red X in the upper toolbar.

Final thoughts

TeamViewer is an outstanding tool to be used for remote support. You will be hard pressed to find a tool that can cross platforms as easily.

Posted via web from bithacker's posterous

Backup And Restore Windows Driver With Double Driver



The driver backup and restoration software Double Driver was recently updated to version 4, reason enough for us to take another look at the software program (see on ghacks Backup and Restore Drivers). Double Driver can scan a system for drivers that can then be backed up by the user to be able to restore them at a later point. This can be handy before installing a new operating system or reinstalling the old one.

Double Driver 4.0 comes with a new interface that makes use of Windows Aero. It will automatically recognize if the program has been started by a user or administrator of the system. The available options differ depending on that.

double driver

The options that the program provides are accessible in the program’s header. Here it is possible to backup and restore drivers or save and print the driver list.

A click on the Backup links opens the driver backup page. The user can start a driver scan on the current system or on another system which is a new feature in Double Driver 4. The screen will then be populated by a list of drivers that the program found on the target computer. Drivers are listed with their name, provider, version, date and class among other information.

Checkboxes are provided to select the drivers to backup. Double Driver seems to automatically select all drivers that are not standard Windows drivers so that these can be backed up with a click on Backup Now. The Select link in the top navigation menu can be used to quickly select all drivers, invert the selection or select none for a fresh start.

The backup now button leads to a new window where the destination directory for the driver backups and the output format can be configured. Supported are structured folders, compressed folders or single self extracting files.

driver backup

The restore button can then be used at a later time to restore a previously created backup. The single self extracting files install the drivers on the target system without Double Driver while the two other options require Double Driver to do so.

Double Driver 4.0 is a portable software program for the Windows operating system that can be used to efficiently backup and restore system drivers. The program is compatible with 32-bit and 64-bit editions of the Windows operating system.

Posted via web from bithacker's posterous

How to encrypt and decrypt a file in Linux, password protected | Linux Operating System - Debian, Ubuntu, Fedora, Gentoo, Arch


Security is important, we all know, and to protect files in Linux Operating System machines is really easy.

The files can be password protected, so you can carry them in a flash memory, and if you loose the flash, you do not have to worry about your info, as it will not be readable.

To encrypt a file in Linux we will use, gpg which is parte of the GnuPG.

Syntax of gpg

gpg -c filename.ext  

Let's imagine we have a file called my-personal-info.txt

I want to encrypt with a password to protect the file, run this command.

gpg -c my-personal-info.txt

The output of the command is:

$ gpg -c my-personal-info.txt   Enter passphrase:   

Enter a good passphrase, be sure to remember it, and do not use an easy one.

Then you will get

Repeat passphrase:   

Now gpg has created an encrypted file called my-personal-info.txt.gpg, the original file is still there, so you may want to erase it, or only transport the encrypted one, or send by email the encrypted one.

To decrypt a file just enter this command.

gpg my-personal-info.txt.gpg

You will be asked for the password or passphrase, and the file will be recreated.

Protect your data.

Posted via web from bithacker's posterous

4/16/10

Universal USB Installer – Easy as 1 2 3


Universal USB Installer is a Live Linux USB Creator that allows you to choose from a selection of Linux Distributions to put on your USB Flash Drive. The Universal USB Installer is easy to use. Simply choose a Live Linux Distribution, the ISO file, your Flash Drive and, Click Install. Other features include; Persistence (if available), and the ability to format the flash drive (recommended) to ensure a clean install. Upon completion, you should have a ready to run bootable USB Flash Drive with your select Linux version installed.

Universal USB Installer Screenshot

Universal USB Installer

Universal USB Installer (Installing)

Download Universal USB Installer

Download Universal USB Installer

Currently USB Installable Live Linux Distributions

  • Ubuntu 9.10 Desktop i386 – Site
  • Xubuntu 9.10 Desktop i386 – Site
  • Kubuntu 9.10 Desktop i386 – Site
  • Ubuntu Rescue Remix Revision 1 – Site
  • Ubuntu NetBook Remix 9.10 – Site
  • Ubuntu Server 9.10 32bit/64bit Installer – Site
  • Linux Mint 8 – Site
  • YlmF OS V1.0 – Site
  • Crunchbang 9.04 – Site
  • KNOPPIX V6.2 – Site
  • gOS 3.1 gadgets – Site
  • Ultimate Boot CD V4.11 – Site
  • Gentoo 10.1 – Site
  • xPUD 0.9.2 – Site
  • Simply MEPIS 8.0.15 – Site
  • RIP Linux 9.3 – Site
  • EEEBuntu 3.0 (Netbook Distro) – Site
  • PartedMagic 4.8 – Site
  • DSL (Damn Small Linux) 4.4.9 – Site
  • EasyPeasy 1.5 (NetBook Distro) – Site
  • DBAN (Hard Disk Nuker) – Site
  • Puppy Linux 4.3.1 – Site
  • Puppy Arcade 7 (Console Game Emulator) – Site
  • Kiwi Linux 9.04 – Site
  • SLAX 6.1.2 – Site
  • SliTaZ Cooking – Site
  • Ophcrack XP – Site
  • Clonezilla – Site
  • Jolicloud (NetBook Distro) – Site
  • Dynebolic 2.5.2 DHORUBA – Site
  • PLoP Linux 4.0.5 (a minimalist Linux Rescue System) – Site

More Live Linux Distributions will be added as time permits.

Notes: If you run Universal USB Installer from the same directory containing an installable ISO, the script will autodetect the ISO and bypass step 2 once the proper Distro has been selected.

Universal USB Installer auto detection of ISO in same folder

Currently this tool does not support installing and booting from multiple Linux Distributions. Only One Distribution can be installed at any given point in time. A multiboot feature may be added in the future.

Posted via web from bithacker's posterous

4/11/10

Confusing joke rug


This picture is driving me mad since all I want to do is pull that rug out from under the wall. Only the rest of it just isn’t there. It’s a nice trick to play on unsuspecting visitors, especially moms.

Perfect for pushing your obsessive girlfriend (or guy) over the edge, especially if you glue it to the floor properly. Just be careful they don’t rip that radiator out from under the window in their rage and crush you with it.

Confusing joke rug

Posted via web from bithacker's posterous

4/10/10

Learning GNU Text Utilities by Joe Zonker


A few weeks ago we looked at some of the GNU utilities that you can use to work with files, check MD5/SHA1 sums and check your disk usage. This time around I want to cover some of the utilities that you'll use for working with text files.

Why text files, specifically? Well, if you're doing much work at the shell on Linux, you'll start encountering a lot of text or files that can behave like text. Log files, configuration files and output from many commands can all be manipulated with the GNU textutils.

At one time, the GNU textutils were broken out into their own package, but a few years ago they were merged into the GNU coreutils. But for convenience sake, I'm going to keep the old moniker because that's a handy way of thinking about those tools.

Assuming you're running any of the major Linux distros and have a default installation, you should have the GNU coreutils package installed already. Some minimalist Linux distros ship Busybox instead. If that's the case, you may have some versions of the tools we're discussing here installed, but they may not have all of the same options as the GNU textutils. Both Busybox and the GNU textutils are actually implementations of tools that were initially developed for proprietary UNIX.

Some of the utilities are more useful than others today, so I'm going to focus on the utilities that are most likely to be useful to you. For instance, the base64 utility for converting in/out of base64 isn't something I've had any call to use in the last 10 years. But fmt, nl and uniq still prove useful on a regular basis.

A few have been covered in the previous GNU tutorial as well. Specifically, md5sum, head and tail, so please go back and check the Getting to Gno GNU Utilities tutorial if you need to brush up on those.

Understanding cat and tac

The cat utility is short for "concatenate." I think we can all agree it was wise to trim that one down a bit. OK, but what does it mean? Basically, cat will take a file or standard input and send it to standard output. If you don't redirect the output from cat it will print to the terminal, or you can use one of the redirectors and send the output to a file or another utility.

You can also use cat to join files to work on them together. For instance, if you want to process a couple of logfiles at once, you could use something like:

 

cat filename1 filename2 | sort  

The tac command is basically just cat backwards. This might be useful if you want to process a logfile from the newest entries to the oldest.

Some purists will note that cat is overused when simple file redirection would do. For example, you'll often see something like this:

 

cat filename | sort  

What's happening there is using cat to pipe (|) to sort. Actually, you can do the same thing by running sort < names and save yourself a bit of typing. However, do whatever works best for you.

Formatting Files

Many of the textutils are dedicated to formatting text for printing. Few folks are dealing with line printers and using CLI tools to send to printers these days (though not an obsolete art, to be sure), but you may still find these tools useful in many situations.

The fmt command will reformat text for writing to standard out or another file. This is primarily used to reflow text to a default column width. Say you want to reflow a text file so each line is only 72 characters: You can do this easily with fmt like so:

 

fmt -w72 filename.txt  

This will only break lines on whitespace characters: It won't break a whole string (word or other non-broken set of characters) unless it's longer than 72 characters.

The cut utility will remove sections from a file. So if you want to deal with only a section of a logfile, for instance, you can use the cut utility to chop out only the bits that you want to work with. The cut utility works on each line. So, given input like this:

 

[Sun Mar 21 16:36:21 2010] [error] [client 69.72.214.138] File does not exist: /var/www/components  [Sun Mar 21 17:24:42 2010] [error] [client 78.110.50.111] File does not exist: /var/www/joomla  [Sun Mar 21 17:37:15 2010] [error] [client 174.36.241.157] script '/var/www/index.php' not found or unable to stat  [Sun Mar 21 18:06:59 2010] [error] [client 38.111.147.83] File does not exist: /var/www/robots.txt  

...you can use cut to separate individual fields. So if you only want to work with, say, the IP address or the error message, you can use cut.

Need to trim a file by lines instead? The split utility will take a logfile or other text file and output it to smaller files. The default is to take the input and spit out files of 1,000 lines each. Unless specified, the files will be named "xaa," "xab" and so on until split finishes the file or runs out of suffixes.

Why would you want to do this? One reason is to make it easier to work with logfiles, break them down into smaller chunks for archiving or processing.

Finding Unique Entries with uniq

When you're wading through logfiles or processing other text files, you'll often have files with a lot of similar entries. If you want to winnow those down to unique entries, uniq is the tool to reach for. Let's start with a simple example, like a text file of 1,000 email addresses. You know you have duplicates but don't feel like sorting through the file by hand and probably wouldn't spot all the duplicates anyway. No problem; just filter the list using uniq:

 

uniq < emails.txt  

The uniq utility will omit duplicates. If you want to see how many times you have duplicate lines, use the -c option to count the number of times a line appears.

But wait. You notice that some lines may be duplicates after all! That's because uniq looks for two (or more) lines together. If you have duplicate lines that are separately listed, they'll be missed. Unless you combine uniq with another GNU textutil: sort.

Sort It Out With sort

The sort utility does just what you'd expect: It takes input and sorts it according to the criteria you give it. The default is to sort by "dictionary" order, but it can also sort by numeric value, in reverse order, etc. See the man page for the full range of options, but rest assured if there's a way you want to sort a file the option probably exists.

Here's how we'd combine sort and uniq to get rid of those pesky duplicates:

 

sort emails.txt | uniq > sorted_emails.txt  

Pretty easy, right? You simply pipe the output from sort to uniq. By chaining the commands, we can start doing some really useful work.

Putting Them Together

Individually, the textutils are useful but you might be wondering what the big deal is. You can't do a lot with cat or uniq individually. But when you start chaining the commands, you can do some pretty powerful stuff.

Let's say you want a report of all the unique IP addresses that have appeared in a log file in the last day or so. We're going to use cut, sort and uniq to get all the unique IP addresses. As an added bonus, we'll throw in nl, a utility that will number lines for you:

 

cut -d ' ' -f 8 error.log | sort -n | uniq | nl  

This takes the file error.log, and runs it through cut first. The options to cut tell the utility to use the space character as a delimiter (-d ' ') and to only spit out the 8th field (-f 8) from the file. So if you look at the file, the IP address is the 8th field if you count the fields separated (delimited) by spaces.

Then it runs that through sort to sort the IP addresses numerically (-n). Then, it removes duplicate IP addresses. Finally, it runs the result through nl to give a count.

That will produce output like this:

 

     1	4.20.98.115]  2	4.79.205.35]  3	12.10.235.174]  4	12.102.9.44]  5	12.106.89.75]  6	12.111.52.254]  7	12.111.74.5]  8	12.132.106.130]  9	12.14.59.66]  10	12.149.50.2]  

Good, but not great just yet. I don't like the trailing bracket. So let's throw in a bonus utility, sed, which is a stream editor:

 

cut -d ' ' -f 8 error.log | sort -n | uniq | sed s/']'// | nl   

Now you'll get the same result, but without the annoying end bracket. The sed command simply uses a search and replace. If you followed the Vim 101 beginner's guide a few months ago, that should look familiar. The s/ starts the search, and then ']' tells sed to look for a closing bracket. Why did I use the single quotes? Because the Bash shell treats ] as a special character. Putting it in single quotes tells the shell to treat it literally (i.e., not to interpret it). Finally, the closing // tell sed to replace the bracket with nothing.

Once again, this really only scrapes the surface of what the GNU utils can do. But I hope it's given you a rough guide to how you can use the GNU textutils and how they can be useful to you. In future tutorials, we'll take a look in more depth at sed if there's interest, let me know in the comments! In the meantime, take a little while to familiarize yourself with the GNU utilities. You'll find that it's very well worth it!

Posted via web from bithacker's posterous

LinuxCommand.org: Learn the Linux command line. Write shell scripts.


The Linux® Command Line

A New Book By William E. Shotts, Jr.

Designed for the new command line user, this 522 page volume covers the same material as LinuxCommand.org but in much greater detail. In addition to the basics of command line use and shell scripting, The Linux Command Line includes chapters on many common programs used on the command line, as well as more advanced topics.

Released under a Creative Commons license, this book is available for free download in PDF format. Download it here.

The book is also available printed, in a large, easy-to-read format. Copies may be purchased at lulu.com. Proceeds help support LinuxCommand.org.

Posted via web from bithacker's posterous