Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Sunday, March 20, 2011

Linux Usage: Turn on Bash Smart Completion

Bash shell provides an awesome feature that increase the accessibility in command line. Some files' name are long and you probably won't want to type it or maybe you type it wrong easily. Auto-completion is a good function for you which you just need to type a few characters only. For example, you can type

$ cd Dow [press tab key]

it will help you to complete the command to

$ cd Downloads

Sometime, bash shell can't identify your file name since there are multiple files with same initials. For example, you type
cd Do [press tab key]
You may see
Documents        Downloads
Then now you need to input more key to specify the file name

In fact, bash shell in ubuntu is smarter now, you can find that codes which enable smart completion in the bashrc file.
if [ -f /etc/bash_completion ]; then
  . /etc/bash_completion
fi

If you view /etc/bash_completion, it defines which program to use which file type. For example,
complete -f -X '!*.@(pdf|PDF)' acroread gpdf xpdf
which means for program "acroread", "gpdf" or "xpdf", when you press tab key under bash shell, it will find files with pdf or PDF extension only.

However, you may find that for sqlite3, the default support extension is .sqlite. Sometimes, I use .db as sqlite3 file. Thus I changed it to
complete -f -X '!*.@(sqlite|db)' sqlite3

Monday, February 28, 2011

Linux Usage: solution for installing debian deb in ubuntu

Sometimes, we will download debian deb and installed it under ubuntu. If you are lucky, this will be okay and the installation will go normally. However, it may report errors like:
The package XYZ needs to be reinstalled, but I can’t find an archive for it.

XYX is the name of your deb package.

At that time, you can remove the wrong package using the following command in terminal:
$ sudo dpkg –remove –force-remove-reinstreq XYZ

Thursday, February 24, 2011

Linux Usage: batch unzip all rar files

If you have a bunch of rar files under Linux and you need unrar all of them. This is quite a trouble. First of all, in the past Linux doesn't have rar tools. Fortunately, this is available right now so that we can process rar under Linux.

Now, the problem is how to handle lots of rar files. One way is to using Xwindows environment. You may use your mouse to select all files and right click uncompress. The other way is to use command:
$ for f in `ls --color=none`; do rar x $f; done

It loops through all files under current directory and pass it to rar program to extract the rar file. rar is the program name, x is the parameter meaning that this is a extraction and $f is the file name

Monday, February 21, 2011

Vim Usage: how to press your ``Esc''

In vim, how would you press the Esc key to switch from insert mode to command mode? For sure, it is a key that you need to move your hand out of alphabet keys. Some people would slap the key..haha..it sounds a little bit violence. For me, I use my little finger, huh, some people think I have a very big hand or a very long little finger.

If you have read Vim Tips, you probably know what's going on. In fact, I am pressing cap lock instead of Esc. In Linux, it is convenient to set your key. You can use xmodmap to modify X windows layout. Since I seldom to use Cap lock, and in order to speed up using vim, I swap Esc and Cap lock. To do that, you can create a .Xmodmap with following content under your home directory
remove Lock = Caps_Lock
keysym Escape = Caps_Lock
keysym Caps_Lock = Escape
add Lock = Caps_Lock

Then execute
$ xmodmap ~/.Xmodmap

Then you will realise that your caps lock become Esc key already. For sure, if you like this mapping, you need to start the script on Gnome start up to take the effect.

Friday, February 18, 2011

A quick way to identity which system you are using. 32bits? 64bits?

To check if your computer is using 32bits or 64bits, it is easy job once you use the following commands. There are many ways to check under Linux, I list some which is easy to remember.

Method 1:
$ uname -m 

Output:
  • i386/i686 = 32bits
  • x86_64 = 64bits
Method 2:
$ file /bin/bash

Output:
  • ELF 32-bit LSB executable, Intel 80386 = 32bits
  • ELF 64-bit LSB executable, x86-64 = 64bits

Method 3:
$ getconf LONG_BIT

Output:
  • 32 = 32bits
  • 64 = 64bits

Choose your own command which you are easy to remember! Enjoy!

Saturday, January 1, 2011

Compiz Plugin `Grid'

I used 15" and 17" small monitors before as I have no money :-(. Recently, I bought a 22" wide screen monitor and it makes lots of change for me.

In the past, I maximized all the application as the screen size was not too large. 17" for a browsing application is suitable at all. However, for 22", a web page is too large if I maximized the browser. In fact, good use of wide screen monitor should be view multiple applications at the same time. Thus, I should use half of monitor for browsing and remaining area for other applications.

Fortunately, there is a simple awesome plugin in Compiz named `Grid'. This plugin changes your screen to a 3x3 matrix and you can put one application in one entry by using Alt + Ctrl + (Num pad 1 - 9) [you can change the setting via compiz setting manger]. Hope that this application can help you to organize your application better and have a better feeling of using Linux!

Related Resource:
  1. http://www.webupd8.org/2009/12/linux-w-compiz-tile-position-and-resize.html

Monday, December 20, 2010

Whatweb

What web is it?

When you visit a web, sometimes you just want to obtain information from the web. However, sometimes, you may want to know which server the web uses, which programming language the programmers use, which CMS they use. You may obtain this information from the server response. Here is a simple tool that helps you to find out the answer - Whaweb(http://www.morningstarsecurity.com/research/whatweb).

This is written with Ruby and simply type
$./whatweb url


It will show you the relevant information such as web server.

Sunday, October 3, 2010

[HOWTO] Remove .svn folder under svn repository

When you svn checkout a project via SVN, it will create .svn folder to keep track the changing in this working folder also. However, when you need to give out the source code, this .svn folder may not be good to be distributed to other also. Instead of remove the folder one by one. You can use find command

find PATH -type d -name '.svn' -exec rm -rf {} \;

Thursday, September 30, 2010

[HOWTO] Change order of buttons on the menu bar

In Ubuntu 10.04, the default theme style looks like MacOS. Thus, the button on the menu bar follows the order of MacOS also which is "close", "minimize" and then "maximize" placed on the top right corner.


Some people might not like this arrangement and want to change back to traditional one.

To do so, open a terminal
$ gconftool-2 --set "/apps/metacity/general/button_layout" --type string "menu:minimize,maximize,close"


If you want to switch them back to the left corner
$ gconftool-2 --set "/apps/metacity/general/button_layout" --type string "close,minimize,maximize:"


In fact, you can play around with the order to suit your need. Have Fun!!

Friday, September 24, 2010

Communicate Google with Command

On Linux, we offer need to type command and I think using command is better than by clicking most time. This is because I need to control the mouse precisely to certain location. This is not convenient for me at all. In addition, I don't want to leave my hand out of the keyboard, so I remember some useful command such as using Ctrl+L in Firefox to type URL instead of using the mouse to click on the url field. I can navigate different web without leaving keyboard. If you are vim experienced user, I think you should like this firefox plugin - Vimperator which you can navigate webpage with your keyboard only.

Now, Google provides many web applications such as Gmail, Contact, Google Docs and this blog Blooger, etc. Fortunately, Google provides a command line tool for them also named GoogleCL http://code.google.com/p/googlecl/. This is a command line tools for the Google Data APIs.

You can do many things using this command tools just like

1. Blogger - create a new post
$ google blogger post --title "create post using GoogleCL" "I can create a new post in command line"


2. Picasa - upload new image to Picasa
$ google picasa create --title "GoogleCL Photos" *.jpg


3. YouTube - upload new video to YouTube
$ google youtube post --category Education linux_command.mpg


For more usage, you can visit the GoogleCL official website. You will find it is extremely useful and you can cooperate with Crontab with GoogleCL, you can do more such as creating a Calendar everyday.

Do Programming Quickly??

I think I am still young in programming area. I learnt Pascal in High School and learn C++ and Java in University. Most of the time, implementing a program takes lots of time especially designing Graphic User Interface (GUI).

Ubuntu now provides a solution "Quickly" that helps people to write program QUICKLY.
https://wiki.ubuntu.com/Quickly

Quickly uses Python as programming language, GTK as the GUI. It provides lots of handy commands help you to program. Basically, what you need first is to install Quickly, but it only has Ubuntu version only. I hope it can support more distribution later.

1. To install
$ sudo apt-get install quickly


2. Build a project
$ quickly create ubuntu-application myapps
$ cd !$

(refer to my previous post to know what !$ means if you don't know)

3. Edit the project
$ quickly edit


4. Design the GUI
$ quickly design


5. Run the program
$ quickly run


Which Quickly, it is really easy to build your own application with small amount of time.

Thursday, September 23, 2010

Linux is awesome if you remember the commands??

Recently, my friend had to use Linux to do something. After one day working, he told me a statement and I think it is funny: "Linux is awesome if you can remember all the commands, otherwise, Linux sucks."

Then, I think a little bit. That's may not be true since Linux has many choices of Windows Environments like Gnome, KDE, etc. They are easy to use and very handy. Most daily works, you can do them by a few click just likes M$ Windows.

However, I do agree that the commands in Linux is awesome if you know them. Sometimes, I use "wget" to download files instead of browser. I use vi(vim) as my major text editor. Writing a bash script can do more such as starting some services/programs when the Linux starts.

Here are some commands I think they are useful:

1. Ctrl + E and Ctrl + A
Sometimes, you find that you need to modify the command at the beginning or at the end. You can simply press "Home" or "End" to go the first position or last position. However, it doesn't work such as using SSH. If you really want to go to beginning, the stupid way is to press left arrow. In fact, you can use Ctrl+E to move the end and Ctrl+A to move to the beginning.

2. !$ - A useful variable.
This stores the last argument in the previous command. Here is an example to this variable.
$ mkdir folder
$ cd folder


In fact, you can you use the following commands:
$ mkdir folder
$ cd !$


3. A crazy command, I like this command very much!
$ :(){:|:&};:

It seems that it is an invalid command. In fact, this does work!!
First of all, :(){ ... } defines a function called ":" with no arguments. In side this function, is call ":" again and "|"=pipe the output to itself. The semi-colon end the function definition and the last colon call the function.
To be concluded, this command call a function that recursively creates a process. Then, your system will hang..

Saturday, January 9, 2010

[HOW TO] turn on NumLock when login Linux

Do you think it is convenient to turn on NumLock when you logon the system?

I used MS Windows for a long time and switched to Linux for about two years. In MS Windows, Numlock is already turned on when I logon. While in Linux, Numlock by default is off and I need to press numlock key before using key pad(but I always forget :-))

I searched this problem in Google and found a good program called NumLockX. You can install it through yum or apt-get

To install NumLockX using yum

yum install numlockx


To install NumLockX using apt-get

sudo apt-get install numlockx