Wednesday, November 19, 2008

FIND command examples...

Find commands examples:
To use the find command, at the Unix prompt, enter:

find . -name "pattern" -print

Replace "pattern" with a filename or matching expression, such as “*.txt”. (Leave the double quotes in.)
Options:
The general form of the command is:

find (starting directory) (matching criteria and actions)

The find command will begin looking in the starting directory you specify and proceed to search through all accessible subdirectories. You may specify more than one starting directory for searching.

You have several options for matching criteria:
-atime n File was accessed n days ago
-mtime n File was modified n days ago
-size +nM File is larger than n Mbytes
-type c Specifies file type: f=plain text, d=directory
-name nam The filename is nam
-user usr The file's owner is usr
-group grp The file's group owner is grp
-perm p The file's access mode is p (where p is an integer)

You can use + (plus) and - (minus) modifiers with the atime, mtime, and size criteria to increase their usefulness, for example:

-mtime +7 Matches files modified more than seven days ago
-atime -2 Matches files accessed less than two days ago
-size +100M Matches files larger than 100 MB


By default, multiple options are joined by "and". You may specify "or" with the -o flag and the use of grouped parentheses. To match all files modified more than 7 days ago and accessed more than 30 days ago, use:
\( -mtime +7 -o -atime +30 \)

You may specify "not" with an exclamation point. To match all files ending in .txt except the file notme.txt, use:
\! -name notme.txt -name \*.txt

You can specify the following actions for the list of files that the find command locates:
-print Display pathnames of matching files.
-exec cmd Execute command cmd on a file.
-ok cmd Prompt before executing the command cmd on a file.

Executed commands must end with \; (a backslash and semi-colon) and may use {} (curly braces) as a placeholder for each file that the find command locates. For example, for a long listing of each file found, use:
-exec ls -l {} \;

Matching criteria and actions may appear in any order and are evaluated from left to right.

Full examples

  • To find and report all C language source code files starting at the current directory, enter:

$find . -name \*.c -print

  • To report all files starting in the directories /mydir1 and /mydr2 larger than 2 Mbytes and that have not been accessed in over 30 days, enter:

$find /mydir1 /mydir2 -size +2M -atime +30 -print

  • To remove (with prompting) all files starting in the /mydir directory that have not been accessed in over 100 days, enter:

$find /mydir -atime +100 -ok rm {} \;

  • To show a long listing starting in /mydir of files not modified in over 20 days or not accessed in over 40 days, enter:

$find /mydir \(-mtime +20 -o -atime +40\) -exec ls -l {} \;

  • To list and remove all regular files named core starting in the directory /prog that are larger than 500KB, enter:

$find /prog -type f -size +500K -print -name core -exec rm {} \;

  • To search foo file in whole systemby, specifying the root directory (/) to search. If you don't run this command as root, find will display a error message for each directory on which you don't have read permission. This can be a lot of messages, and the matching files that are found may scroll right off your screen. A good way to deal with this problem is to redirect the error messages so you don't have to see them at all:

$find / -name foo 2>/dev/null

Thursday, November 13, 2008

Debug plsql procedure/function in TOAD when executed by external application

Debug plsql procedure/function in TOAD when executed by external application
Step Over: Execute one line of code at a time but does not go into any called procedures or functions.
Trace Into: Execute one line of code at a time and does go to any called procedure or functions and executing its code one line at a time as well.
Trace Out: Returns the execution to calling routine and stopping on next line of code after call statement.
Breakpoint: Stop execution at the line with breakpoint
Add Watch: Watches allow to the contents of specific variables.


For tutorials on google:

Toad for Oracle Tutorials - debug

Step 0:
grant DEBUG CONNECT SESSION to system;

revoke DEBUG CONNECT SESSION from system;

Step 1:

Anonymous Block
-- run this in your client session
-- first block gets the debug session ready
DECLARE
id VARCHAR2(255);
BEGIN
id := DBMS_DEBUG.INITIALIZE('TOAD_EXAMPLE');
DBMS_DEBUG.DEBUG_ON;
END;
/

Step 2:

--this fires off your stored pl/sql object so it can be debugged.
BEGIN
KARAM.LOOP_INSERT;
DBMS_DEBUG.DEBUG_OFF;
END;
/

Step 3:

Now attach session in TOAD