Friday, November 30, 2007

HowTo: Strip directory path and filename suffix

Here's another quick howto on stripping or removing directory folder path and/or filename suffix or filename extensions of a given complete or partial filename using the linux basename command.

Basename strips directory and suffix from filenames by definition. Basename binary is part of coreutils package. This basename command can be useful on handling filename strings or directory path on multiple counts. Instead of issuing a command or combinations of of shell string functions, awk, cut, tr, or sed command and other linux command, stripping leading directory path locations and filename suffixes can easily be done using basename command.

From the complete path location of /var/named/chroot/etc/named.conf , /var/named/chroot/etc/ and .conf can be removed by this basename command.

Basename command is designed to strip and remove those leading directory folder/path and filename extensions.

Here are ways on how to remove or strip leading folder path (directory name) and filename extensions (suffix filenames).

Example 1:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# cd /etc
# basename named.conf .conf
output:
named
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Example 2:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# basename /var/log/messages
output:
messages
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Example 3:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# basename /etc/named.conf
output:
named.conf
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Example 4:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# basename /etc/named.conf .conf
output:
named
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Example 5:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# basename /etc/named.conf conf
output:
named.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Get the pattern, alright.

Try it, basename can be extremely useful on long lines of shell scripts manipulating filenames.

HowTo: Get the Filename Extension Only

From previous post, we have managed to strip the leading folder path and filename extension. Now, this blog entry is here to cover the reverse approach of my previous basename blog post.

How to manipulate a filename string and return only the filename extension of a file from command line using awk parameters.

For filename with single file extension, removing the leading file name and leaving only the file extension name would be done like so:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# printf named.conf | awk -F . '{print $2}'
output:
conf
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

For filename with multiple file extension, stripping the leading filename and leaving only the file extension:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# printf named.conf.bak | awk -F . '{print $NF}'
output:
bak
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Another example of removing the leading directory path and leaving only the suffix filename:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# printf /var/cache/named/etc/backup/named.conf.bak | awk -F . '{print $NF}'
output:
bak
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

or using basename would yield to same resulting string
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# basename /var/cache/named/etc/backup/named.conf.bak | awk -F . '{print $NF}'
output:
bak
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

HTH

Tailf - watch the linux log file grows

Another overused linux command that has been quite around from this linux blog entry and widely used command on monitoring log file tail. Tail binary allows a user to watche the growth of a log file. Watching the log file grows can be done using an additional -f parameter. Alternatively, another approach to watch a log file grows can be done using tailf binary command.

To tailf or to tail -f ? That is the question.

Tailf binary is part of util-linux-ng linux package while tail binary is part of coreutils linux package.

File size difference of tailf and tail binary command:

# ls -la /usr/bin/tailf /usr/bin/tail

-rwxr-xr-x 1 root root 7416 2007-10-16 21:48 /usr/bin/tailf
-rwxr-xr-x 1 root root 43576 2007-10-30 17:52 /usr/bin/tail

Man Tailf
Tailf will print out the last 10 lines of a file and then wait for the file to grow. It is similar to tail -f but does not access the file when it is not growing. This has the side effect of not updating the access time for the file, so a filesystem flush does not occur periodically when no log activity is happening. Tailf requires only a single parameter when watching a growing log file. Tailf follows the following command format

# tailf logfile

Tailf is extremely useful for monitoring log files on a laptop when logging is infrequent and the user desires that the hard disk spin down to conserve battery life.

Tailf Usage Examples

# tailf /var/log/messages
# tailf /var/log/maillog


HTH

Fedora 8 with Enlightenment Window Manager

Linux Window Manager definition:
Wiki defines Window Manager as:
n X window manager is window manager under the X Window System, a windowing system mainly used on Unix-like systems.

Here's the shortest definition of Window Manager I could find, with the help of Google.
Linux window manager is a graphical interface which is commonly know as X11 or more simply as 'X'.

Unlike the Apple Macintosh and Microsoft Windows platforms, which have historically provided a vendor-controlled, fixed set of ways to control how windows and panes display on a screen, and how the user may interact with them, window management for the X Window System was deliberately kept separate from the software providing the graphical display.

This linux blog entry chooses one of those popular and widely used linux window manager, Enlightenment.

Enlightenment is a window manager. Enlightenment is a desktop shell. Enlightenment is the building blocks to create beautiful applications. Enlightenment, or simply e, is a group of people trying to make a new generation of software.

The latest version of Enlightenment is DR17. DR17 of the Enlightenment window manager represents an evolution into the next generation of desktop environments: the desktop shell. DR17 will provide integration between files and your environment in a seamless manner while encompassing a graphically rich and flexible architecture. It will not compete with GNOME or KDE, but be a completely new way of visualizing your desktop, based around the EFL which was built from the ground up for this task.

Still in heavy development, several applications that will be part of the DR17 release and examples of what is possible are already available in CVS, such as Entice, Entrance, and Evidence.

Enlightenment Installation

Here are 3 steps on how to install Enlightenment (E16 version) on Fedora 8.

1. Grab the rpm package for Fedora 6. Click here.

Alternatively, install enlightenment directly using rpm package manager like so

# rpm -ivh http://garr.dl.sourceforge.net/sourceforge/enlightenment/e16-0.16.8.10-1.fc6.i386.rpm

2. Logout from Linux X and login back again using Enlightenment instead of GNOME/KDE window manager or hit Ctrl+Alt+Backspace to restart Linux X window manager.

3. Customize your window layouts, progam menus and desktop behavior using left and right clicks of your mouse from the Enlightenment window manager desktop.

Take note that you can still use GNOME X manager while Enlightenment window manager is enabled by choosing E-GNOME during the login setup.

You can switch back to your original X window manager by logging out and logging back in into your original window manager.

Here are serveral Enlightenment desktop screenshots.




Check out Enlightenment website, click here.
See more of shared enlightenment screenshots from here and here.

Enjoy and happy weekend!

Thursday, November 29, 2007

HowTo: ScreenCasts & Desktop Records via Istanbul

Istanbul is a desktop session recorder for the Free Desktop. Istanbul records your desktop session into an Ogg Theora video file. The video file can then be used for your presentation, demos, tutorials and video works. Istanbul desktop session recorder offers a lot greate screen recording features. Istanbul can record audio sounds, running videos, 3D desktop screens, mouse movements, specific screen area, screen size and desktop application windows.

Istanbul Operations

Istanbul relies on new x display screen capturing support in gstreamer-plugins package. The ximagesrc gstreamer element is under active development upstream yet.

When launched, Istanbul sits down on top of your notification area as a small red button. Then istanbul waits for mouse clicks for further operations. To start desktop session recording, simply click on Istanbul red icon from the notification area and to stop you click its icon again. Use your mouse right click to view and change istanbul's desktop recording options and features. The resulting video file is in OGG video file format which makes it easy for playback. Istanbul works on GNOME, KDE, XFCE and others.

For a clear and smooth desktop session recording and screencasting, it is highly recommended that your screen resolution is set lower or equal to 800x640 screen reso. Istanbul works roughly with my 1024x768 screen reso. The frame rate should also be adjusted to 1.0 frame rate per second to immediately capture every possible screen movements and desktop operations. I am still trying to achieve this, python suggestion?

When recording, the small red button turns into a square gray box still sitting down from the notification area. Click the square gray box from the notification area to stop the desktop recording. From there, Istanbul would then ask you for the filename before saving the video file. Once the saving is done, you can now start viewing the OGG video file.

Istanbul Installation

Istanbul can be installed to Fedora 8 via yum

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# yum -y install istanbul
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Binary Launch:

Alt+F2, istanbul

Sample Recording
The below istanbul screencasting were recorded from my 17" monitor with 1024x768 screen reso. As you can see, the video is turtle-walk and roughly delayed with most screen and mouse movements. I may need to adjust my frame rates. I have tried a lower screen reso but bad screencasting I achieved. Istanbul had done a great start on linux screencasting but there's always a lot of improvement left. I would keep an eye on this.

Here's a recorded session using a terminal window:







And with desktop effects enabled, below is a sample not-so-good screencasting I have done so far:







For further related reading, you may visit Istanbul and Fedora-Wiki.

The above screencasts has been done on Fedora 8. If you like this post, I would be glad if you can share it support of sharing it or hitting some diggs and stumbles.

Would appreciate all your support! Thanks!

HowTo: Record Desktop Session via Byzanz

Byzanz is a new born desktop session recorder for linux. Byzanz records current display sessions and saves them as GIF image files.

Byzanz desktop recorder offers several new features at its early binary age. Byzanz desktop recorder provides support for screen recording with or without cursor movements. Byzanz can also be customized to record desktop session on specific screen size or screen location. This byzanz feature allows a smaller and customized screen size and screen location desktop session recording.

Recorded desktop session file are being saved in GIF file format. GIF files are known to offer and contain framed image animations. Another feature of Byzanz is its capability to generate a looping GIF animation bringing you a non-stop image animation from a single GIF file. The file size of the resulting output GIF file from Byzanz varies widely on session recording time. A 10-second 1280x1024 recorded desktop session can reached a GIF file size of more than 150Kbytes. The resulting GIF file needs no further editing or modification and is ready for image viewing.

Though at its early stage, Byzanz can be a promising desktop session recorder for a frame-by-frame desktop session recorder.

Good job for byzanz though it needs further feature enhancements. One wishful feature can be an GUI-based integrated desktop environment for useful desktop friendliness. More to come and expect from Byzanz developers, so watch out for it soon!

Byzanz Installation

Byzanz though at its early age is available from Fedora Application/Multimedia Project and can be installed using yum.

To install byzan desktop recorder via yum, simply

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# yum -y install byzanz
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Binary Launch:

Alt+F2, byzanz-record

Sample Usage:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# byzanz-record -c -l output.gif
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

My Sample Desktop GIF Session:



Don't see the image animation? Right click on it and open in new browser window or download the file and open it up from your browser.

HTH

Wednesday, November 28, 2007

Linux Scorched 3D Tank Game

Meet Scorched 3D Classic Tank Game.

Scorched 3D is another classic 3D linux tank game that is based on a DOS game polished with more features such as OpenGL supported, multiple player and weapon options, more landscape island war environment spots, LAN-enabled enemies, save and retrieve game levels and more. Scorched 3D tank game can be played by stand-alone or online.

Man Scorched 3D:
Scorched 3D is a game based on the classic DOS game Scorched Earth "The Mother Of All Games". Scorched 3D adds amongst other new features a 3D island environment and LAN and internet play. At its lowest level, Scorched 3D is just an artillery game with two+ tanks taking turns to destroy opponents in an arena. Choose the angle, direction and power of each shot, launch your weapon, and try to blow up other tanks. But Scorched 3D can be a lot more complex than that,
if you want it to be. You can earn money from successful battles and use it to invest in additional weapons and accessories. You can play with up to twenty four other players at a time, mixing computer players with humans. There's a variety of changing environmental conditions and terrains to be dealt with.

Scorched 3D is totally free and is available for both Microsoft Windows and Unix (Linux, FreeBSD, Mac OS X, Solaris etc.) operating systems.

You can pick up the game and begin playing very quickly. Then, when/if you are interested, you can poke in the dimmer recesses of the game and get into the strategy (or just ignore it altogether!).

The main objective of the game is to stand from the rest of the enemy tanks. Last tank standing wins.

Visit Scorched 3D tank game from here.

SCORCHED 3D TANK INSTALLATION MADE EASY

Scorched 3D is available from Fedora Project repos. Thus, the tank game can be installed via yum.
From Fedora 8, simply issue the following yum command for installation.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# yum -y install scorched3d
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


The above command will install the necessary dependencies including non-installed opengl package. Yum would download an approximately 60 MB of package files.

Screenshots:





More wiki documents can be found from here and mods are widely available from here.

Goodluck and enjoy tank-scorching!

113 Amazing Linux Games

Linux Atomic Battle Tank Game

Here's another linux blog entry covering another nice classic game running on Fedora 8.

Atomic Tanks is a game in which you control an overly-powerful tank and attempt to blow up other highly powerful tanks. Players get to select a number of weapons and defensive items and then attack each other in a turn-based manner. The last tank standing is the winner. More info from here.

Game Play and Objective

Atomic tank game operates on fields and mountains. The objective of this tank game is to throw and shoot a missile against your enemies until they fell down to ground. Shooting the enemies with your missiles takes computational efforts on missile direction, thrust and speed, and trigonometrical angles to completely hit your enemy targets. Missiles comes in many various types. Some of them are heavy in weight, a few missiles are fast in speed, the others covers a wider horizontal bomb craters that also affects the tank ground positioning. You can check out these types of missiles here. The ability to withstand and hit the enemy targets makes you far better than the rest of the enemy tanks. Missile thrust, shotting angle, and speed can be increased and decreased by the player.

Atomic tank game has many optional features. This keyboard driven tank game has the ability to save and load game levels. The tank game offers several computer-based target tank enemies which contributes and increases the difficulty level of the game. The battle grounds and mountain stands in a way that makes the tank game more challenging on launching missile weapons on hidden enemy targets.

Installation and Requirements

Atomic Tank game is part of Fedora Game Project. Atomic Tank game requires a minimum hard disk space. A normal dialup connection would do fine on package dependency downloads and installation. This atomic tank game can be installed via yum on Fedora 8. After a successful tank game installation, the tank game binary is available from Applications > Game > Tank Game.



How to install Atomic Tank Game:

~~~~~~~~~~~~~~~~~~~~~~~~~
# yum -y install atanks
~~~~~~~~~~~~~~~~~~~~~~~~~

Launch: Alt+F2, atanks

ScreenShots:




You can view more actual game screenshots here.

All in all, this tank game is a nice classic game to have in a linux desktop. Approved for kids and grandmas for being a user-friendly non-audio toxic easy to play tank game.

Enjoy!

Monday, November 26, 2007

HowTo: Display a Tree of Linux Processes

Everybody knows the benefit of having an overall idea and infrastructure connectivity of your own local network by looking at our own network diagram.

In linux world, being aware and knowing what processes are currently running at all times is one good practice of managing your linux box. This practice involves monitoring of your memory usage on high and low peak hours of one production day. Looking at processes, this gives you a virtual connectivity of daemon services related to other linux process. A virtual map allowing you to be familiarized with other currently running processes.

Here's one linux command to visually display linux process in a tree map.

PSTree shows running processes as a tree. The tree is rooted at either pid or init if pid is omitted. If a user name is specified, all process trees rooted at processes owned by that user are shown.

PSTree can take a user name as an argument and display all running processes of that specific user. PSTree is part of psmisc rpm package and is installed by default on Fedora 8 with X.


PSTree usage:

Basic tree process
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# pstree
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Tree process of specific user
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# pstree root
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Tree process with numerical sorting
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# pstree -n
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Tree process showing ASCII characters to draw the process tree
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# pstree -A
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Tree process displaying PIDS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# pstree -p
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

A sample process tree screenshot:





HTH

Howto: 3 Easy Install Steps of Microsoft Fonts in Fedora 8

There are nice fonts included with the default Fedora 8 X installation. Some people love it, others want more. If you are fond of using Microsoft fonts, here's a quick entry on how to have microsoft fonts installed from your Fedora 8 box.

Three easy steps on how to install Microsoft Fonts in Fedora 8.
===============================================================

1. Install the needed package dependency:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# yum -y install chkfontpath
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

2. Install Microsoft core fonts rpm package for Fedora 8 directly like so:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# rpm -ivh http://vertito.googlepages.com/msttcorefonts-2.0-1.noarch.rpm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

3. Close all your unsaved data and restart or reload your XFS like so
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# service xfs restart
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


If you wish to do the long approach, simply follow the approach taken from my old post here.

HTH

Note: All commercial names, trademarks and company mentioned here are all trademarks managed and owned by their own respective company.

Howto: Convert PDF to HTML/XML/PNG in Linux

Here's a quick howto on converting PDF files into HTML file.

PDFtoHTML linux tool converts PDF files into multiple file formats like HTML, XML, and PNG images. By default usage, the output is written to current working folder. PDFtoHTML linux tool is based on XPDF version 3.00. PDFtoHTML PDF converter tool is part of poppler-utils rpm page.



PDFtoHTML INSTALLATION
======================

Here's how to install PDFtoHTML PDF linux converter tool.

By default, PDFtoHTML converts PDF file into HTML file.

# yum -y install poppler-utils


BINARY LAUNCH:
==============

Alt+F2, pdftohtml


PDFtoHTML Usage:
================

When working with PDFtoHTML PDF file converter, all resulting output files are saved on current working directory folder. Here's the simplest way to use this PDF converter tool

# cd /location/of/pdf/file
# pdftohtml testfile.pdf test.html


HTH

Livna Repository on Fedora 8

Livna repo contains thousand of ready made rpm package and installers for linux. If you find it hard to find extra rpm package for Fedora 8, try to install Livna repo and do the search again.

Here's a quick lines on how install Livna repo into Fedora 8.

Simply issue as root

# rpm -ivh http://rpm.livna.org/livna-release-8.rpm
# rpm --import http://rpm.livna.org/RPM-LIVNA-GPG-KEY

Sunday, November 25, 2007

Linux Action Flight Simulator Game

Wiki defines Flight Simulator:
"A flight simulator is a system that tries to replicate, or simulate, the experience of flying an aircraft as closely and realistically as possible. The different types of flight simulator range from video games up to full-size cockpit replicas mounted on hydraulic (or electromechanical) actuators, controlled by state of the art computer technology.

Flight simulators are extensively used by the aviation industry for design and development and for the training of pilots and other flight deck crew in both civil and military aircraft."

In Linux, while doing some yum search, yum lead me to a linux based action flight simulator. This GL-117 is an action flight simulator and flight game. GL-117 flight simulator allows your to simulate and practice flight simulations, plane dog fights, flight maneuvers, accomplish flight missions over the air and above the ground. GL-117 flight simulator offers different practice and flight simulation difficulty levels, variety of flight missions as well.

With GL-117 mission flights, GL-117 offers a computer based fighter plane enemies which serve users a great mission challenge as you try to shoot them with your powerful air-to-air missiles and guns combined with your flight maneuver talents and tactics flying over the long-running mountains, over the valleys and seas. Your fighter plane is equipped with limited missile power and plane bullets that increases your skills over your ammunition management.

Gl-117 offers you three different types of plane namely fighter plane, bomber plane and a commercial flight plane. Gl-117 gives you ammunition powers with different types of missiles that you can use on different levels of missions. You can have air-to-air missiles for plane fight above the ground, and air-to-ground missiles for enemy targets from the ground. Flight squadron planes are also equipped with plane flares and chaffs for defensive air tactic. Using your radar and plane power, guided by your plane radar and sensors, you can use your long range plane guns on shooting down an enemy plane.

GL-117 is an action flight simulator. Enter the Eagle Squadron and succeed in several challenging missions leading though different landscapes. Five predefined levels of video quality and an amount of viewing ranges let you perfectly adjust the game to the performance of your system. Joystick, mouse, sound effects, music and more.

Linux Action Flight Simulator Game

INSTALLATION
============

GL-117 can be installed via yum. Yum install around GL-117 180 files compressed in single package rpm installer.

How to install GL-117 Flight Simulator

# yum -y install gl-117

LAUNCH:

Alt+F2, gl-117

Here are my several GL-117 screenshots:





Final Note

Even if you are not inline with flight simulations, you should try installing this amazing GL-117 flight simulator game! You'll like it too!

Check out GL-117 site here.

Related Post:

113 Amazing Linux Games

Thursday, November 22, 2007

Splitting and Merging Multiple Linux Files

Considering that you have 50MB of single file. Your friend needs it urgently. The situation shows that the ONLY means of transferring this large file between you and your friend is thru email exchanges. The problem is both your ISP limits the size of email attachments to 5MB file attachments.

How to transfer 50MB large file by email?
How to split and merge large chunks of file by email?
How to send big file by email?
How to split big file and rejoin them later from the other end?

Splitting and Merging Multiple Linux Files

Split linux commands chops file into multiple chunks of file. Split command divides a single file into multiple files regardless of file types. Split command is fantastic on handling and splitting binary files, compressed and archived files, text files and any other file types. Split is part of coreutils package.

Here's how to accomplish our objective of splitting large files into pieces and merging them back.

As an example, I have prepared a binary rpm file named testfile.rpm with 18MB filesize. Our objective is to split tesfile.rpm into multiple file pieces and merge them back into the same binary file state from the other end.

# ls -la testfile.rpm
-rw-r--r-- 1 root root 18835725 2007-11-23 11:07 testfile.rpm


Spliting the file into multiple file chunks with 4MB as maximum filesize

# split -b4000000 testfile.rpm
# ls -la
-rw-r--r-- 1 root root 18835725 2007-11-23 11:07 testfile.rpm
-rw-r--r-- 1 root root 4000000 2007-11-23 12:27 xaa
-rw-r--r-- 1 root root 4000000 2007-11-23 12:27 xab
-rw-r--r-- 1 root root 4000000 2007-11-23 12:27 xac
-rw-r--r-- 1 root root 4000000 2007-11-23 12:27 xad
-rw-r--r-- 1 root root 2835725 2007-11-23 12:27 xae


Notice that the file testfile.rpm as splitted into 5 file chunks, with 4 files having 4MB filesize and 1 file having more than 2MB of filesize. Filename conventions are written alphabetically xaa, xab, xac, xad and xae and so on for larger file.

Since each filesize is less than the 5MB email attachment limit, you can now attach these multiple chunks of file into your email message and send them successfully into the receiving end, bypassing email attachment restrictions of 5MB.

Now, we need to merge them back from the other receiving end. Here's how to do it.

How to merge splitted files into a single big file?

Simply issue these simple commands:

# cat xaa xab xac xad xae > newfile.rpm
# ls -la
-rwxr-xr-x 1 root root 18835725 2007-11-23 12:35 newfile.rpm
-rwxr-xr-x 1 root root 18835725 2007-11-23 11:07 testfile.rpm
-rw-r--r-- 1 root root 4000000 2007-11-23 12:27 xaa
-rw-r--r-- 1 root root 4000000 2007-11-23 12:27 xab
-rw-r--r-- 1 root root 4000000 2007-11-23 12:27 xac
-rw-r--r-- 1 root root 4000000 2007-11-23 12:27 xad
-rw-r--r-- 1 root root 2835725 2007-11-23 12:27 xae


The receiving end now has the actual file with simple file splitting and file merging operations.

Have a nice weekend!

HTH

Sort Nth Position of Nth Column of a File in Linux

How to sort file basically?
How to sort a file from the Nth column?
How to sort a file from Nth position of the Nth column?

A quick draw of achieving the above using the sort linux command.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# cat file.txt
6 4 8123
1 2 3789
4 6 9456
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Let us do a numerical sorting of the file using the basic usage of sort command.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# sort file.txt
1 2 3789
4 6 9456
6 4 8123
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Another file content sorting with columnar basis.

Sort the 3rd column of a text file
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# sort -nk 3 file.txt
1 2 3789
6 4 8123
4 6 9456
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Now, the sorting the Nth position of the Nth column of a file begins.

Sort the 3rd position of the 3rd column of a text file
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# sort -nk 3.3 file.txt
6 4 8123
4 6 9456
1 2 3789
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

How about sorting the 4th position from the 3rd column of a text file?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# sort -nk 3.4 file.txt
6 4 8123
4 6 9456
1 2 3789
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Good, you get the idea. Hope this helps and thanks for the visits!

This sort command was also included from my old blog entry from here and here.

Stop, Pause, and Continue A Linux Process

On most medium to large scale companies, most demanding production servers I know undergo a few minutes of executing batches of scheduled shell scripts or linux commands. These shell scripts and linux commands consume a lot of time and server work load before finishing certain particular job specially for CPU-cycle-eating scripts and linux commands. Thus lessening server performance and response time to normal daily operations of a non-load-balanced production servers.

How to stop, pause, and continue a currently running process job?
How to create a pending linux shell process?
How to temporarily stop a command?

Here's how to achieve the effect of pausing a linux process.

This blog entry would assume, as an example, running a CPU-cycle-eating linux command, then temporarily pause and stop it, and later on continue executing th process without killing the actual PIDs.

Let's start.

Run updatedb into the background forking a process
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# updatedb &
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Determine current process PIDs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ps axuw | grep updatedb | grep -v grep
root 3264 5.2 0.0 3852 800 pts/0 D 12:35 0:00 updatedb
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Noticed from the above lines that the executed updatedb represent a PID of 3264 . Take note of this as we are going to need this when pausing the process.

Next, confirm that the updatedb linux command is still being processing and running
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# jobs
[1]+ Running updatedb &
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Now, let's pause the linux process
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# kill -STOP 3264
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reconfirm if the process is still running
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# jobs
[1]+ Stopped updatedb

# ps axuw | grep update
root 3264 1.4 0.0 3852 800 pts/0 T 12:35 0:00 updatedb
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

From the issued commands above, we have successfully paused a currently running process. The updatedb process with PID 3264 is now a currently frozen process. Eventually, depending on CPU cycles and disk activity needed by your scheduled batch of shell scripts and linux commands, server work load would gradually decreased then and much more response time would be available for others to use.


As a sample of stopping ,pausing and continuing a linux process, we can now continue executing the currently stopped linux process:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# kill -CONT 3264
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Verify that the process is now running
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# jobs
[1]+ Running updatedb &

# ps axuw | grep updatedb
root 3272 0.0 0.0 4044 672 pts/0 S+ 12:37 0:00 grep update
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The line below shows that the background process of updatedb was already finished with its job.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[1]+ Done updatedb
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

As you can see, the updatedb process was stopped, pause and continued using the 'kill' command.

You might be interested with the shown advertisement from those black boxes around.
HTH

Here is kill description from man page:

The command kill sends the specified signal to the specified process or process group. If no signal is specified, the TERM signal is sent. The TERM signal will kill processes which do not catch this signal. For other processes, it may be necessary to use the KILL (9) signal, since this signal cannot be caught.

Wednesday, November 21, 2007

File Creation without File Opening in Linux

How to create new file without opening an editor or executing a copy / move command?
How to create new multiple files simultaneously?
How to create multiple files with the same timestamps?
How to update file date and timestamps?

Another overly used and unexplained command around this blog.

Touch basically touches and changes file timestamps. Touch updates time modifications of each file arguments to current time of the box. Touch command is part of linux coreutils package, part of GNU. Touch command is installed by default.

Here's how to create a file without actually opening an editor to start editing it or without making use of linux copy and move commands.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# touch newfile.txt
# ls -la newfile.txt
-rw-r--r-- 1 root root 0 2007-11-22 10:09 newfile.txt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If a filename is being passed as an argument to touch command, and the file does not exists, the file is then created with the latest time stamp. Now, if a file is already an existing file from current working folder location, the timestamp of th