Wednesday, December 29, 2010

Linux Amazing Keypresses & Commands : Set 5

  • By default in Bash shell pressing Ctrl+D will exit the current shell . To prevent it you can add the following line in ~/.bashrc:
export IGNOREEOF=1
And then source the file to read it again:
source ~/.bashrc



  • sed is a non-interactive command line stream editor, used to perform various forms of text transformations on an input stream. It reads input files line by line and applies the operation specified via the command line. 
For replacing the first occurrence of a string (india) with another string (India) in a file.
#sed -i ‘s/india/India/’ file_name 
For replacing the first occurrence of a string (india) with another string (India) in a file.
#sed -i ‘s/india/India/g’ file_name 
s stands for substitute, g stands for global.
For creating a new file with the above changes.
#sed -e ‘s/india/India/g’ file1 > file2

  • Closing a vulnerable port on your system, you have to install nmap first to check which ports are open:
#nmap localhost 
This will output open ports and the protocol using them. To close port 80 on tcp (for http) , execute the commad as root:
#fuser -k 80/tcp

  • To count no. of lines, words & characters in a file, use this command
#wc -lwc file_name
It is a handy command when we need to customize output.

No comments:

Post a Comment