Tip for File Deletion:
When we try to delete a large amount of file using single linux command, we get error as:
/bin/rm: Argument list too long.
The problem is that when you type something like “rm -rf *”, the “*” is replaced with a list of every matching file, like “rm -rf file1 file2 file3 file4″ and so on. There is a relatively small buffer of memory allocated to storing this list of arguments and if it is filled up, the shell will not execute the program.
To get around this problem, a lot of people will use the find command to find every file and pass them one-by-one to the “rm” command like this:
find . -type f -exec rm -v {} \;
The above command may take too long.
I stumbled upon a much faster way of deleting files – the “find” command has a “-delete” flag built right in! Here’s what I ended up using:
find . -type f -delete
Using this command file deleting rate may be reached at 2000 files/second – much faster!
You can also show the filenames as you’re deleting them:
find . -type d -print -delete
…or even show how many files will be deleted, then time how long it takes to delete them:
root@devel# ls -1 | wc -l && time find . -type f -delete
real 0m3.660s
user 0m0.036s
sys 0m0.552s
Sunday, September 30, 2012
to delete files in linux using command
Labels:
Linux,
Quick Info
Location:
Dhanmondi, Dhaka, Bangladesh
Thursday, September 6, 2012
bin\javaw.exe not found when trying to install Oracle 11g 32 bit in Windows 7
Nothing more to do...
Just follow this steps
1) install JRE-1.7.0
2) add these 2 lines at the file oraparam.ini
JRE_VERSION=1.7.0
JRE_LOCATION=C:\Program Files\Java\jre7
3) comments the line :
1) install JRE-1.7.0
2) add these 2 lines at the file oraparam.ini
JRE_VERSION=1.7.0
JRE_LOCATION=C:\Program Files\Java\jre7
3) comments the line : JRE_VERSION=1.4.2
Just follow this steps
1) install JRE-1.7.0
2) add these 2 lines at the file oraparam.ini
JRE_VERSION=1.7.0
JRE_LOCATION=C:\Program Files\Java\jre7
3) comments the line :
1) install JRE-1.7.0
2) add these 2 lines at the file oraparam.ini
JRE_VERSION=1.7.0
JRE_LOCATION=C:\Program Files\Java\jre7
3) comments the line : JRE_VERSION=1.4.2
Thursday, June 7, 2012
Query to get Table Info of SQL server
Query to get Table info from a SQL server database is as:
select COLUMN_NAME,DATA_TYPE, CHARACTER_MAXIMUM_LENGTH,
NUMERIC_PRECISION, DATETIME_PRECISION,
IS_NULLABLE
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME='table_name'
select COLUMN_NAME,DATA_TYPE, CHARACTER_MAXIMUM_LENGTH,
NUMERIC_PRECISION, DATETIME_PRECISION,
IS_NULLABLE
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME='table_name'
Labels:
Database,
Query,
Quick Info
Location:
DBBL IT Division, Dhaka, Bangladesh
Sunday, May 27, 2012
servlet to export information in excel file
We can use servlet to export information in excel format. The code for this purpose may be as below:
String folder = "/excels/";
Three parameters have been sent using request as per requirement.fileNameToShow contains the value for the name of the file to save in client side
String fileNameToShow=request.getParameter("fileName");String dbName=request.getParameter("dbName");
String query=request.getParameter("query");
String file_name = folder;
System.out.println("Report Name: " + file_name);
try {
ServletOutputStream servletOutputStream = response.getOutputStream();
byte[] bytes = null;
try {
ExcelHelper exlHelper = new ExcelHelper();
bytes = exlHelper.createExcell(getServletConfig().getServletContext().getRealPath(file_name), query, dbName);
response.setHeader("Content-Disposition", "inline;filename="+fileNameToShow+".xls");
response.setContentType("application/vnd.ms-excel");
response.setContentLength(bytes.length);
servletOutputStream.write(bytes, 0, bytes.length);
servletOutputStream.flush();
servletOutputStream.close();
mailMessage = mailMessage + ". REPORT produced successfully";
} catch (Exception e) {
// display stack trace in the browser
logger.error(e);
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
e.printStackTrace(printWriter);
response.setContentType("text/plain");
response.getOutputStream().print("Could not display report temporarily...");
//response.getOutputStream().print(stringWriter.toString());
mailMessage = mailMessage + ".ERROR catched when creating report.";
}
} catch (Exception e) {
System.out.println(e.getMessage());
logger.error(e);
} finally {
logger.info(mailMessage);
}
Expecting your kind suggestion for moderation of the code.
Labels:
Java,
Readymade Code
Location:
DBBL IT Division, Dhaka, Bangladesh
Friday, May 25, 2012
to create excel file using java
Apache POI API has been used for this purpose. This is used for manipulating various microsoft files.
This is a function of a class which generate an excel file after executing query in the database. Executing query in the database is not concerned here. This code insists on the creating file using POI. The function return the file in byte array( i do it as one of my requirement).
public byte[] createExcell(String fileLoc, String query, String dbName) {
try {
String file_name = fileLoc +"/"+ (new Date()).getTime() + ".xls";
FileOutputStream fileOut = new FileOutputStream(file_name);
File file = new File(file_name);
if (file.exists()) {
file.delete();
}
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet worksheet = workbook.createSheet("Candidate List");
byte[] bytes;
GatewayPersonalInfo gwPersonalInfo = new GatewayPersonalInfo();
List lstPerson;
lstPerson = gwPersonalInfo.getAllPersonalInfo(query, dbName);
HSSFCell cellA, cellB, cellC, cellD, cellE;
rowNew = worksheet.createRow(0);
cellA = rowNew.createCell(0);
cellA.setCellValue("Sl. No");
cellB = rowNew.createCell(1);
cellB.setCellValue("App Serial No");
cellC = rowNew.createCell(2);
cellC.setCellValue("Full name");
cellD = rowNew.createCell(3);
cellD.setCellValue("Contact No.");
cellE = rowNew.createCell(4);
cellE.setCellValue("Email ID");
if (!lstPerson.isEmpty()) {
Iterator itr = lstPerson.iterator();
PersonalInfo person;
int rowno = 1;
while (itr.hasNext()) {
person = (PersonalInfo) itr.next();
rowNew = worksheet.createRow(rowno);
cellA = rowNew.createCell(0);
cellA.setCellValue(rowno);
cellB = rowNew.createCell(1);
cellB.setCellValue(person.getSerialNo());
cellC = rowNew.createCell(2);
cellC.setCellValue(person.getFullName());
cellD = rowNew.createCell(3);
cellD.setCellValue(person.getContactNo());
cellE = rowNew.createCell(4);
cellE.setCellValue(person.getEmail());
System.out.println(rowno + " row added.");
rowno = rowno + 1;
}
}
}
workbook.write(fileOut);
fileOut.flush();
fileOut.close();
FileInputStream fin = new FileInputStream(file);
bytes = new byte[(int) file.length()];
fin.read(bytes);
file.delete();
} catch (Exception ex) {
System.out.println(ex);
logger.error(ex);
} finally {
}
return null;
}
Comments:
fileLoc: provide the location where to keep the file after generation.
query: database query on which you want to create excel
dbname: if you work with multiple database in your project
fileLoc: provide the location where to keep the file after generation.
query: database query on which you want to create excel
dbname: if you work with multiple database in your project
try {
String file_name = fileLoc +"/"+ (new Date()).getTime() + ".xls";
FileOutputStream fileOut = new FileOutputStream(file_name);
File file = new File(file_name);
if (file.exists()) {
file.delete();
}
delete file if a file name generated before with same name.
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet worksheet = workbook.createSheet("Candidate List");
byte[] bytes;
GatewayPersonalInfo gwPersonalInfo = new GatewayPersonalInfo();
List
lstPerson = gwPersonalInfo.getAllPersonalInfo(query, dbName);
Above three lines has been used to import data from databases in list.
HSSFRow rowNew;HSSFCell cellA, cellB, cellC, cellD, cellE;
rowNew = worksheet.createRow(0);
cellA = rowNew.createCell(0);
cellA.setCellValue("Sl. No");
cellB = rowNew.createCell(1);
cellB.setCellValue("App Serial No");
cellC = rowNew.createCell(2);
cellC.setCellValue("Full name");
cellD = rowNew.createCell(3);
cellD.setCellValue("Contact No.");
cellE = rowNew.createCell(4);
cellE.setCellValue("Email ID");
Just to create header in the file
if (lstPerson != null) {if (!lstPerson.isEmpty()) {
Iterator itr = lstPerson.iterator();
PersonalInfo person;
int rowno = 1;
while (itr.hasNext()) {
person = (PersonalInfo) itr.next();
rowNew = worksheet.createRow(rowno);
cellA = rowNew.createCell(0);
cellA.setCellValue(rowno);
cellB = rowNew.createCell(1);
cellB.setCellValue(person.getSerialNo());
cellC = rowNew.createCell(2);
cellC.setCellValue(person.getFullName());
cellD = rowNew.createCell(3);
cellD.setCellValue(person.getContactNo());
cellE = rowNew.createCell(4);
cellE.setCellValue(person.getEmail());
System.out.println(rowno + " row added.");
rowno = rowno + 1;
}
}
}
workbook.write(fileOut);
fileOut.flush();
fileOut.close();
FileInputStream fin = new FileInputStream(file);
bytes = new byte[(int) file.length()];
fin.read(bytes);
file.delete();
After taking in the byte array, file is being deleted. But it depends on your requirements. You can keep the file.
return bytes;} catch (Exception ex) {
System.out.println(ex);
logger.error(ex);
} finally {
}
return null;
}
Kindly provide your suggestion for further modification.
Labels:
Java,
Readymade Code
Location:
DBBL IT Division, Dhaka, Bangladesh
Subscribe to:
Posts (Atom)