Pages

Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts

Friday, January 04, 2008

How to use vi style in Bash

If you are vi fans, probably you want to have vi command style in bash shell.

Simply add the following command in your ~/.profile_bash file:
set -o vi

That's all :)

Thursday, January 03, 2008

How to get yesterday time

Sometimes, we need to create a simple script in linux which involves retrieving system time several days/hours/minutes ago.

Belows are example use of date command:

To get yesterday time:
$ date --date="1 days ago"
or
$ date --date="-1 days"


To get one month ago:
$ date --date="1 months ago"
or
$ date --date="-1 months"


To get one hour ago:
$ date --date="1 hours ago"
or
$ date --date="-1 hours"


To get one minutes in the future:
$ date --date="+1 minutes"


To get one seconds in the future:
$ date --date="+1 seconds"


We can also combine it, example to get one month and two hours ago:
$ date --date="1 month 2 hours ago"
or
$ date --date="-1 month -2 hours"

There are many other ways to express the particular time.

That's all :)

Wednesday, January 02, 2008

Bash keyboard shortcut

Below is list of keyboard shortcut for bash shell.

Why we need keyboard shortcut? The short answer is: to save time!
Especially, when we are accessing bash remotely (eg: by ssh) and the network access pretty slow, we will need a keyboard shortcut such as deleting the entire command line, moving to the beginning of the command, etc to save a lot of time.

Below are some of keyboard shortcuts for bash. Maybe in certain conditions it does not work properly.

  • ALT + b : move the cursor backward one word.

  • ALT + f : move the cursor forward one word.

  • ALT + d : cut one word after the cursor.

  • ALT + u : uppercase one word after the cursor.

  • CTRL + a : go to the first character of the line.

  • CTRL + b : move back one character.

  • CTRL + c : Sending signal SIGINT the current process you run (usually the process will be killed).

  • CTRL + d : Sending EOF, Exit/logout the current shell.

  • CTRL + e : go to the last character of the line.

  • CTRL + f : move forward one character.

  • CTRL + h : clear one character before the cursor. (similar with backspace)

  • CTRL + k : cut all characters after the cursor.

  • CTRL + l : clear screen.

  • CTRL + r : search for previously used commands.

  • CTRL + t : swap the last two characters before the cursor.

  • CTRL + u : cut all characters before the cursor.

  • CTRL + w : delete one word before the cursor.

  • CTRL + y : recall the last cut character by CTRL+u or CTRL+k or ALT+d (just like paste)

  • CTRL + z : put the current process you run into background process. To restore it, use command fg.

  • ESC + t : swap the last two words before the cursor.

  • TAB : autocomplete command/files or folders name.


That's all :)