Thursday, 2 February 2012

Linux command line History help

* showing command line history time format
# export HISTTIMEFORMAT='%F %T '

* controlling total number of lines in the shell history
Add the following  lines to the .bash_profile
HISTSIZE=450
HISTFILESIZE=450

* Changing the history file name from .bash_history from any other
Add the following line to the .bash_profile 
# vi ~/.bash_profile
HISTFILE=/root/.my_command

* Eliminate the continuous repeated entry from history
To check this repeat some commands and after that export the following
# export HISTCONTROL=ignoredups

after giving this if you type any comands repeately it shows only once in commandline.

* Erase duplicates across the whole history
# export HISTCONTROL=erasedups 

previous commands will not go, only commands that come after this will have its effect.

* Force history not to remember a particular command
# export HISTCONTROL=ignorespace 

and when you execute a particular command, put a space before the command and that command will not showing in the history.
 

exp:- #  service mysqld stop 
There is a space at the beginning of service,to ignore this command from history. 

* Disable the usage of history
# export HISTSIZE=0
It will not store anything in history

* Ignore specific commands from the history
# export HISTIGNORE="pwd:ls:ls -ltr:"
 

after this history will not record pwd, ls and ls -ltr, we can specify more commands here so .
 
 


  
 

grep in linux


* Killing all firefox processess in one line
#  ps xa| grep firefox| grep -v grep | awk '{print $1}' | xargs kill -9

grep -v grep ------ will avoid the pid of grep ( --invert-match )

* To select only the uncommented lines from large configuration file use -E / -v

-E ----  for specifying regular expression
-v ----   for inverted selection

# grep -vE '^#|^$' /etc/squid/squid.conf

* Grep a particular string from a file
# grep "this" filename

* Checking for a given string in multiple file 
For that copy the file ctechz_file to ctechz_file1. The grep output will also include the file name in front of the line that matched the specific pattern.

# cp ctechz_file ctechz_file1

# grep "this" demo_*

* Case insensitive search using grep -i
# grep -i "string" file

it will search CTECHZ and ctechz, case insensitively.

* Pattern Search
# cat filename | grep 'pattern'
# command | grep 'pattern/data'
# grep --color 'patern' fileName 
* grep recursive -- checking all files under var for the pattern 
# grep -r "pattern" /var/
* Checking full words, not for sub-strings use grep -w
# grep -iw "is" demo_file
* search two different pattern using egrep
# egrep -w 'word1|word2' /path/to/file
* showing N lines after the pattern match
# grep -A 3 -i "pattern" filename
* shows line when words has been matched
# grep -c 'pattern' filename
* shows the invert match
# grep -v 'pattern' filename
 it matches only lines that do not contain the given word
* Displaying line numbers when showing output using grep -n
#  grep -n "pattern" filename
 
Search the pattern in all files under a directory
# grep -ril "pattern" /directory
 

Wednesday, 1 February 2012

Installing klipper on centos

In ubuntu we can install klipper by

# sudo apt-get install klipper

In centos klipper is getting from another package

# yum install kdebase.i386
# klipper ----- to call the package

 

Rename multiple file in linux


If a directory contains so many files with the extension .txt and if you want to rename it to some other extensions follow the step

# cd /directory/contains/file

shows result before renaming
# rename -n 's/\.txt$/\.bak/' *.txt (file we want to change)

# rename  's/\.txt$/\.html/' *.txt

# rename 's/.txt/.md/i' *

It is useful if the directory contains a lot of files to edit in a single step.

-n, --no-act
 No Action: show what files would have been renamed

* Also we can convert upper case letters to lowercase and  vice versa

# cd /directory/contains/file

# rename 'y/A-Z/a-z/' *

* Renaming file name from:

ctechz.txt0
ctechz.txt1
ctechz.txt2
ctechz.txt3
ctechz.txt4
ctechz.txt5

To file name:

ctechzblog.txt
ctechzblog.txt0
ctechzblog.txt1
ctechzblog.txt2

# rename 's/ctechz/ctechzblog/g' ctechz.txt*




Http file sharing in linux


Let us have a look at Instant http file sharing in linux, no need of any nfs or samba to do the work for you

Go to the directory you want to share
cd ctechz

Run the below command 
# python -m SimpleHTTPServer

Go to another machine and open browser and enter
http://ipadress:8000

You will get all the files inside the directory in which you ran the python command.


Tuesday, 31 January 2012

Doing ftp in different ways

We can execute the following command in a browser

ftp://ftp.freenet.de/pub/filepilot/  ---- ftp to a free ftp site using domain name

ftp://193.43.36.131/Radio/MP3/  ------ ftp using ip address


ftp://195.216.160.175/

ftp://202.118.66.15/pub/books

ftp://clubmusic:clubmusic@217.172.16.3:8778/ ---- using username, password and a specific ftp port.

ftp://psy:psy@ftp.cybersky.ru

Create a login banner for ftp, Each user will see the message before they enter their username and password, even anonymous users.

Edit the vsftpd.conf and place 
ftpd_banner= any message

Another method of creating a Banner Message is to place a .message file in a directory. Create a file with the message and save it as .message in the directory. Be sure to make it read only.

and gives the option in config file

banner_file=/path/to/banner/file




How to release the Linux disk buffer/cache

Inorder to free the disk cache we get an interface /proc/sys/vm/drop_caches has been available to simplify this process.

First we run the sync command before dropping the cache. Doing this will ensure that all memory in the cache is updated and all dirty pages are synchronized before dropping the cache.

You can safely skip this step but if you have any dirty pages in your disk cache the system will refuse to release them.

# sync

next step is echoing “3″ to the /proc/sys/vm/drop_caches file which will signal the OS to release the pagecache, dentries and inodes.

# echo 3 > /proc/sys/vm/drop_caches

# sync

# echo 0 > /proc/sys/vm/drop_caches ----- default value/ after clear the cache make it as 0 by running this command.

# echo 1 > /proc/sys/vm/drop_caches ---- only page cache

# echo 2 > /proc/sys/vm/drop_caches ------ only inode 

# echo 3 > /proc/sys/vm/drop_caches --- inode/page cache/clear all cache