Go4Expert (http://www.go4expert.com/)
-   Unix (http://www.go4expert.com/articles/unix/)
-   -   Shell Tips & Tricks - Part 2 (http://www.go4expert.com/articles/shell-tips-tricks-part-2-t19106/)

pradeep 20Aug2009 16:51

Shell Tips & Tricks - Part 2
Part I - Shell Tips & Tricks

Clear and Disable Bash History

Use the Bash inbuilt history command:


history -c
To prevent writing of your Bash history to the history when you log out:



Ampersand (Background Jobs)

& is a inbuild operator to fork processes.
"If a command is terminated by the control operator &, the shell executes the command in the background in a subshell"

[root@pradeep test]# sleep 60 &
[1] 32739

The process id is stored in a special variable $!

[root@pradeep test]# echo $!

List all background jobs

[root@pradeep test]# jobs
[1]+  Running                sleep 60 &

Killing any background job

[root@pradeep test]# kill %1
[1]+  Terminated              sleep 60

Search An Replace in vi

Open a text file in vi/vim and goto command mode by pressing ECS and then ':', the search and replace command will be like,


You can also mention which lines should be affected by this, %s means all lines.


5,10 s/oldString/NewString/g
This will tell vi to make do replacing in lines 5 to 10. You may also use regex in your search expression.

asha 26Aug2009 10:48

Re: Shell Tips & Tricks - Part 2
Cool, the history one was really nice, it really helps me ;-)

shabbir 2Sep2009 18:56

Re: Shell Tips & Tricks - Part 2
Nomination for Article of the month - Aug 2009 Started.

shabbir 19Sep2009 11:41

Re: Shell Tips & Tricks - Part 2
Vote for this article for Article of the month - August 2009

All times are GMT +5.5. The time now is 14:28.