2009-04-27

How to change the login screen banner

The previous tip was about change the banner after login. This tip, however, was to change the banner of the login prompt aka pre-login message.

How to view a compressed log file in gnuzip format

Log files are generally compressed, to save disk space. But it can be quite a hassle if we are to uncompressed one by one to just browse through them. There is a utility / command that will make our life easier :

2009-04-26

How to encypt file or directory in linux, freebsd & os x

Another short tip. The below demonstrate how to encrypt and decrypt files & folders on Mac OS X, Linux & FreeBSD using GnuPG :

How to find out the type of the file

Some file comes with no extension so we are unable to know what kind of application to associate with. Luckily Linux/Freebsd has a utility that can determine the file type.

2009-04-25

How to force quit or stop a program

After running a job, only to find out later that it is stuck at some point and even Control-C cannot stop it.

e.g. a infinite loop script, X program that stuck in the X window & etc.

How to change the message display upon login

There are some message display after a successful log into the system. e.g. (if your system is running Ubuntu)
"The programs included with the Ubuntu system are free software; the 
exact distribution terms for each program are described in the 
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted 
by applicable law.

To access official Ubuntu documentation, please visit: 
http://help.ubuntu.com/"

2009-04-24

Linux - how to split / break big files in to smaller chunks

Just did a backup and noticed that the backup tar file is more then 2gb, which fail to copy to a fat32 thumb drive. The mysqldump output text file is more then 5gb and needless to try as it cannot fit into any fat32 formatted drive. Or even regular file that is more then 10mb would not be able to email to any Yahoo or Gmail account.

These are the scenarios where the big files are needed to break into smaller chucks in order to transfer it. Below is a good way of doing it :

2009-04-23

how to check who is current log in and what are they doing

Use the command
w
and it would list who is currently logged in, logged in from where, since when and what are they doing.

See ya !!!

How to view file in read only mode

"view" is the editor "vim" or "vi" in read-only mode. The browsing capability is same as vim. It is an alternative to read a file other then using less or more.
e.g.
view some-text-file.txt

Ciao !!!

2009-04-22

GNU find - execute command after find results

Normally we use the "find" command to search for some files and post process it using the pipe ("|"). But do you know find can process the results without using pipe? Here it is :

how to check disk space utilization

Command :
df


Common parameters :
-h = display sizes in human readable format, kb, mb & gb
-i = display inode usage rather then disk usage

e.g.
df -h
df -hi

See Ya !!!

2009-04-21

mysql server - how to reduce disk space by moving mysql-bin.00000

One fine day, the server disk usage report that, the one of the partitions is almost full. After some searching, the database directory at /var/db/mysql/ (FreeBSD) or /var/lib/mysql/ (Linux) is occupying most disk space. Listing the directory only to found out that mysql-bin.0000* are the ones that is occupying the disk space. What are these files? Can it be remove it to reduce disk usage?

These mysql-bin.0000* files are the binary logs for your database. It contains all the statements of updating your database. It another words, it is the archived of your database. Removing it will need some preparations, which is not covered in this post. But the below does suggest a way to move it to another partition or disk :

2009-04-20

ubuntu - video player reported error reading media upon encrypted DVD

After inserting an DVD and started playing, vlc complain that it was unable to read the media. Totem & Kmplayer have the similar error message as well. Playing the same dvd on MAC or dvd player with TV was fine.

No helpful messages was shown in the previous players on Ubuntu. Lastly, mplayer (command line based player) was used to troubleshoot the problem as it runs in the console and would output any error, plainly. It turns out that dvd was a encrypted dvd. Which need additional packages for it to run properly :

2009-04-19

vim - case insensitive search and occurrence or match operations

A short tip. For searching in vim, enter the "Command-line" mode by type a colon (":") in "Normal" mode (Esc twice at any time) and type "set ignorecase" for case-insensitive search.

e.g.
:set ignorecase

Additionally, for "next" occurrence or match, type "n" or "N" for "previous" occurred match.

Ciao !!!

2009-04-18

FreeBSD networking - IP address automatically assign aka DHCP

This is another follow up post on DHCP aka Dynamic Host Configuration Protocol, which posted first in here and then here. FreeBSD are commonly used as a server. One might ask why does it needs to auto assign IP using DHCP ? Should not it running static IP so that the server are contacted by the host always on that particular IP? To answer the question, the server could be in testing mode so any IP will do. Or the DHCP server have statically map the server's MAC address to a particular IP in its table or pool. The DHCP server will only assign that particular IP to that MAC address when the DHCP client (which in this case is the FreeBSD server) sends out a broadcast requesting info to setup the IP assignment.

In short, just follow the below and IP will be assigned, if there is any DHCP server already configure within the network :

2009-04-17

vim - basics of search and replace in substitute command mode

When cleaning up some config file with hundreds of lines, browsing up and down just to find the key word can be eye dazzling, in the pungent way. :)

The good thing about vim is, it is able to find any text you want using the "Search" command (/) in the "Normal" mode (Esc twice any time).

Some of the time, we need to change the search result with a new value. Be it slight change, addition or even removal, vim is definitely up to the job. To quote a few examples :

2009-04-10

bash - how to print or display a new line or tab other then using echo

Printing variables or text within bash script is good for debugging. It can trace which line or variables is having problem. echo is the commonly is used for such debugging purpose. But some times we need it to print tabs, new line & other escape strings in a one liner bash. One way to do it is using printf :

2009-04-09

ubuntu - firefox cannot resolve URL with telnet:// protocol

In Firefox, when clicking on a URL link with "telnet://", firefox browser would pop up an error message "Firefox doesn't know how to open this address, because the protocol (telnet) isn't associated with any program.". It is due to the browser have not register a helper application to run the URL link with "telnet://". Below are some simple steps to prepare firefox in Ubuntu using xterm to open the URL :

2009-04-08

Debian - apt-get and apt-cache common operation or usage

Initially there was tar.gz. Packages are distributed through compressed archive. Users will have to de-compress themself then compile it, finally, install it. The famous "configure; make; make install" 3 step. If the installation break the halfway, due to library dependencies, users will have to figure a way to fulfill it. Cross your finger, no more breaks happen after fulfilling the dependencies. Talking about nightmares.

After a while later, Debian come out with a way to manage all these "nightmares". A package system that manages its library dependencies, Advanced Packaging Tools. Since then, installing packages on linux have never been so easy. It not only make installation of packages a fun, but also made patching hassle free. Below are the commonly used operation on apt :

2009-04-05

Linux networking - edit /etc/network/interfaces for fixed IP assigment

This is a follow up of the previous post, which demonstrate how to configure NIC (Network Interface Card) to obtain IP address automatically using DHCP client. This post, however, attempt to demonstrate how to assign fixed IP assignment onto NIC, using CLI (Command Line Interface). The below is the instructions :

2009-04-04

bash - send email with attachment or empty body with mutt

The mutt is not just an email client, it is also very useful in bash script. mutt's CLI (command line interface) parameter can be called and execute without starting the email client interactively, ideal to run it within bash script to send email. mutt is also able to control from config file, ~/.muttrc, with a rich feature set waiting to harness. Below is one of the possible way to send email with attachment, one or multiple, in a bash script :

2009-04-03

freebsd - convert unix epoch date and time using the date command

Epoch dates are seconds started from 1st January, 1970. It is a common date and time representation, especially in unix and linux world. It provides a way to convert time stamp in a much easier way for programming calculation, an integer. Below are one of the way to convert epoch timestamps to a readable format :

2009-04-02

bash - read a file line by line instead of word by word

bash script read a file word by word rather then line by line. That means if you have a file with the below contents :





<start of file>

The quick brown fox jumps over the lazy dog

<end of file>

and you read & display it using :
for reading in $(cat /some/directory/some-file);
do
echo $reading;
done

The output would be :
<start of output>
The
quick
brown
fox
jumps
over
the
lazy
dog
<end of output>

instead at time we want it to display :
<start of output>The quick brown fox jumps over the lazy dog<end of output>


That sucks. As there is a lot of time we need bash to read the file line by line instead of word by word. Fortunately, we are using open source. Our predecessors have predicted the monkeys would step on this tragedy banana skin. Below are some solutions to let bash read a file line by line rather then word by word :