File Search and Recursive grep:
//This command will search in the current directory and its sub-directories for a file named FileName.sh.
find * -name "FileName.sh" -print
find . -name "FileName.sh" -print
NOTE: The -print option will print out the path of any file that is found with that name.
//This command will only list file names eG*.sh.
find . -type f -name 'eG*.sh'
//Search file called httpd.conf in all directories:
find / -type f -name httpd.conf
//Search file called httpd.conf in /usr/local directory:
$ find /usr/local -type f -name httpd.conf
-----------------------------grep command--------------------------
grep command is used to search some content in a file or list of files. The input we provide is case sensitive
for grep command. There are options to overcome this.
For Non-Zip files:
grep 'SMS' applicationNonZip.log.txt (CASE-SENSITIVE "SMS")
grep -i 'SMS' applicationNonZip.log.txt (NON CASE-SENSITIVE "SMS")
For Zip files:
zgrep 'SMS' application.log.gz
zgrep -i 'SMS' application.log.gz
For Searching Recursively in current directory and its sub-directories:
grep -r --include=*.sh MAIN_CLUSTER .
Search MAIN_CLUSTER in *.sh files in current directory and sub-directories. It will print file Name and Matched Line Contents.
grep -rl SMS *
Search SMS recursively and print ONLY FILE NAMES containing SMS. It will not print Matched Line Contents.
Search String Forward: /STRING (Press ENTER. Press "n" for next occurance, "N" (SHIFT+n) for back occurance).
SHIFT+g (means G, will take cursor to end of file). Press only g, you will be moved to begining of file.
Search and Replace First occurance: :s/EG3_OLD/EG2_NEW
Search and Replace in one line occurance: :s/EG3_OLD/EG2_NEW/g
Search and Replace in entire File all Occurance: :%s/EG3_OLD/EG2_NEW/g
//Check Running Processes
ps -eaf | cut -c -125 | grep _PROCESSNAME
//Setting Java Home Path in Unix
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_60
export CLASSPATH=$JAVA_HOME/lib/tools.jar:.:
export PATH=$JAVA_HOME/bin:$PATH:
//Search and Replace String in a File without opening
sed -i -- 's/OLD/NEW/g' FileName.sh
//List of Users in ubuntu
compgen -u
//List of User Groups in ubuntu
compgen -g
//Create user in ubuntu
sudo adduser lion (It will ask for password and details, enter those...)
//To know which group current logged in user belongs to:
groups
//To know which group any user belongs to:
groups USERNAME
----------------------Setting Oracle Home in Unix------------------------
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export ORACLE_SID=orcl
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME:$PATH:.
//Login to Oracle System
sqlplus
Enter user-name: USERNAME
Enter password: password
//Login to Oracle System as SYSDBA
sqlplus / as sysdba
SQL> startup (Start Oracle Instance)
SQL> exit
lsnrctl start (Start Oracle Listener)
//Setting Linesize and PageSize in Unix. Run below command in SQL Prompt.
SET linesize 300;
SET pagesize 2000;
//Setting AutoTrace On, this will give detailed plan if we execute any sql query in oracle. Run below command in SQL Prompt.
SET autotrace ON;
//Manual Index Query in Oracle
select /*+ index(TABLE_NAME index_name) */ Count(*) from TABLE_NAME where
time_stamp >='06-NOV-13' and time_stamp <='07-NOV-13' and card_no = 'XXXXX';
----------------------END------------------------
Wednesday, October 15, 2014
File Search and Recursive grep
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment