Showing posts with label Commands. Show all posts
Showing posts with label Commands. Show all posts

Monday, August 26, 2013

Command History:

Any command executed on the machine gets logged. By default on bash the history size is 1000 commands. You can check your current size by

  • $ echo $HISTSIZE
this setting is stored in .bashrc , if you open it up you ll see something like this
  • HISTSIZE=1000 
It a good idea to increase the HISTSIZE to store a large number of commands, which can be rendered for quick execution with reverse-i-search.

There is also an interesting hack/trick around this :) . 
You can override the logging behavior but prefixing every command with a space. Interestingly commands executed in such fashion do not show up in the output of the 'history' command.

Also command history can be disabled by setting

  • HISTFILESIZE=0
in .bashrc

Saturday, August 17, 2013

Grep : recursively search for the occurrence of a word in files.

Lets assume we are trying to search word "this" in all the files in the present directory. Would it be nice if I could see which all files it occurs in along with the line number. Passing some options to grep commands helps to do the exact same task.


Monday, August 12, 2013

Kill a process with ease

Well normally you will have to find the process id in order to kill it
eg. kill - 9 1234

But there are alternatives to it such as
  • kill -9 `pidof processName`
  • kill -9 `pgrep processName`


Tuesday, July 30, 2013

Shutdown / suspend /hibernate your Linux machine with commands

If you are a fast typist you and a terminal addict you might want to shutdown/hibernate/reboot your machine the CLI way. Here are some of the commands that will help you do the same

Shutdown
> sudo poweroff

Hibernate
> sudo pm-hibernate

Suspend
> sudo pm-suspend


Monday, July 29, 2013

Sed file manipulation
Consider you need to replace an occurrence of a word across multiple files , what do you do ?
Now you can open up each file in vim and do a search and replace in each file but that's an inefficient way of doing it.

Sed to the rescue
Sed is a file manipulation tools that can help in such situations. With just one command you will be able to replace all words across multiple files.

here is how you replace "word1" with "word2" in current directory

sed -i "s/word1/word2/g *