Sunday, August 21, 2011

unix tricks - How to list and sort directories by size in Linux/Unix

How to list and sort directories by size in Linux/Unix
if you have a space problem on Linux - UNIX you may need to check which folders or file are taking more space . i tried this on Solaris it worked just fine .

Use this command to find the directories taking up the most space:

du -k | sort -nr | more


The du command along with the -k switch lists all directories and their respective size in kilobytes.
The sort command sorts the output so that the largest directory is shown first in the list. The -nr switch reverses the list and uses only numbers when sorting.
Here’s an example of the output:

12939451 . 1814892 ./abcdef 1219582 ./abcde 839586 ./abcd 718330 ./abc 695610 ./ab 690380 ./a






how to extract you data in utf8 text encoded file

Usually oracle using utl_file package will export data in ascii encoded text which is not common as data integration encoding between heterogeneous information systems . i was asked to deliver the exported text in utf8 for integration purposes with a Microsoft e-learning system.


To transfer ascii file encoding to utf8 you should put a BOM at the start of the utf8 new file then encode it from ascii to raw to utf8 statement line by line as follows in the example .



CREATE OR REPLACE PROCEDURE SYS.utf8file
IS
bom_raw RAW (3);
text VARCHAR2 (32767);
text_raw RAW (32767);
filehandler UTL_FILE.file_type;
BEGIN
-- write the bom section
bom_raw := HEXTORAW ('EFBBBF');
--prepare the text
text := 'this is a utf8 file encoded ';
--convert it to raw encoded text
text_raw := UTL_I18N.string_to_raw (text, 'UTF8');
-- open the file with the nchar for new encoding in the Directory BBSIS
filehandler := UTL_FILE.fopen_nchar ('BBSIS', 'utf8text.txt', 'w', 32767);
-- write the bom section
UTL_FILE.put_nchar (filehandler, UTL_I18N.raw_to_nchar (bom_raw, 'UTF8'));
-- Now. write out the rest of our text retrieved from Oracle with its UTF8 encoding
UTL_FILE.put_nchar (filehandler, UTL_I18N.raw_to_nchar (text_raw, 'UTF8'));
-- Close the unicode (UTF8) encoded text file
UTL_FILE.fclose (filehandler);
EXCEPTION
WHEN UTL_FILE.invalid_path
THEN
raise_application_error
(-20000,
'ERROR: Invalid path for file or path not in INIT.ORA.'
);
END;

/