Linux: How to find size of the current directory

In linux, the directory is just a pointer to the location. What we really want if the size of all the files that are contained in that directory. To see the individual sizes of all the directories inside the current directory:

du -sh *

the ‘s’ option provides a summary, the ‘h’ option provides the output in a human readable format. There is a ‘c’ option which can combine the sizes and give a total.

du -h --max-depth=1 | sort -hr

provides the size of all sub-folders at the first level. Sort command sorts the output, with the ‘r’ option meaning ‘reverse’, i.e. the largest one first.

 

 

Advertisements

SQL: How to insert new rows that are copies of existing rows

In SQL you can create/insert new rows that are essentially copies of the old rows, without needing to specify every column value.

Let’s say you have a table called “EVENTS” with the following columns:

  • event_name
  • location_name
  • promoter_name
  • event_date
  • promote_address
  • location_address

Now, let’s say you want to create a new row with all the same information except the event_name and event_date.

insert into events (event_name, location_name, promoter_name, event_date, promote_address, location_address) 
select 'new event' as event_name, location_name, promoter_name, 'todays date' as event_date, promote_address, location_address where promoter_name='Test1';

In the above sql, the select statement becomes the input for the insert statement. All the rows returned by the select statement will be inserted as new rows exactly as returned. Which means that instead of the ‘event_name’ as stored in the database, it will insert ‘new event’ as the event_name for each and every row. This is useful if you are trying to create new rows with the same “event_name” value.

 

Documentum: How to recover database password

 

Copy the content of dbpasswd.txt file from the following folder:

$DOCUMENTUM/dba/config/<REPOSITORY NAME>

Content will be in this format:

DM_ENCR_TEXT_V2=AAAAEFpxldCW8pnF4gbWPFV+1jP8TEK9HS8d28MW0HwWw+C3uV/+rshuoJ/3j

Open IAPI, and do the following:

$>iapi
$>Please enter a docbase name (docubase): <REPOSITORY NAME>
Please enter a user (dmadmin):
Please enter password for dmadmin:
$>initcrypto,c
$>decrypttext,c,DM_ENCR_TEXT_V2=AAAAEFpxldCW8pnF4gbWPFV+1jP8TEK9HS8d28MW0HwWw+C3uV/+rshuoJ/3j

 

 

Linux: vi search and replace command

Format

The format of the command is given below:

%s/<string_being_replaced>/<replacement_string>/

Examples

In order to replace the word “hate” with “love”.

  • Open the file in vi
  • Hit [Esc] (Esc in vi lets you type commands instead of typing content)
  • Type : (colon) followed by %s/hate/love/ and hit [Enter] key.
:%s/hate/love/

Above command will replace first occurrence of word hate with love on all lines. The % represents all lines.

To replace all occurrences of word hate with love on all lines, use the g option (g stands for global, indicating all occurrences).

:%s/hate/love/g

You can replace g with a number 1,2,…N to change only the n’th occurrence on each line.
Use find and replace on line ranges (match by line numbers)

You can also make changes on range of lines i.e. replace first occurrence of hate with love on lines 5 through 20 only, enter:

:5,20s/hate/love/

Following command will replace first occurrence of hate with love starting at the current line for the next 100 lines:

:.,+100s/hate/love/

Word Match

You can match by words i.e. find the next line containing a word “test”, then replace all occurrences of hate with love:

:/test/s/hate/love/g

To specify ranges:

:/test/,/guest/s/hate/love/g

Documentum D2: About D2 returns dfc.properties

If you click on the About D2 link, it returns the complete dfc.properties file which may include your servername or ip address. This is a security vulnerability. To resolve this issue, open the D2.war and D2-Config.war files, find the following file:

WEB-INF/lib/D2FS4DCTM-WEB-4.5.0.jar

Open the file above and find the following file:

xml/dialog/AboutDialog.xml
Comment out the lines below:
<tab id="tabDebug" condition_visible="getValue(ctrlKey).notEquals('') &amp;&amp; getValue(altKey).notEquals('')">
                        <memo id="properties" rows="18" wrap="off" condition_enabled="false" assistance_type="java" assistance_java="com.emc.d2fs.dctm.ui.assistances.DebugProperties">

                        </memo>
</tab>