How to Convert doc File to txt File using Mac Terminal

The Mac terminal provides a powerful “textutil” command, which can be used to convert .doc files to .txt files directly from the terminal without opening the .doc file.

Here is the command which can be used for the same :

$ textutil -convert txt yourdocfile.doc

Here, the doc file “yourdocfile.doc” will be converted to txt file and a new file “yourdocfile.txt” will be created in the folder with the contents of the doc file.

Best Way to Edit sudoers File in Linux

In Linux, the sudoers file present in the /etc directory will determine the permissions and other settings  while the sudo command is used. If you edit the file directly using terminal or using an editor, if there is any error in your code, the whole sudo command will break. So it is not the best way to edit the sudoers file.

The best way to edit the sudoers file is to use the following command :

$ sudo visudo

This will open the sudoers file in vi editor and you will be able to edit the file here. Once you try to save, it will check for errors and will let you know the same with options to save, not save or re-edit the file.

So it is the safer option while trying to edit sudoers file.

How to Create Directory Structure using Terminal

In this article, we are going to see how to create a directory structure using terminal.

The “mkdir” command  is used to create a folder or a directory using terminal. Now for creating a folder within another folder (multilevel directory structure), if  you use the “mkdir” command like the following command, you will get one error message like this “mkdir: dir1/dir2: No such file or directory”.

$ mkdir dir1/dir2/dir3

Now if you want the terminal to create the structure itself when you try to create a directory, you will have to use the command like this :

$ mkdir -p dir1/dir2/dir3

This will first create the directory, “dir1”, then inside dir1, it will create the directory “dir2” and finally inside dir2, it will create the directory “dir3”.

Single Line Conditional Statement for Terminal

In terminal, it is possible for you to write single line conditional statements, where you can execute a single line of statement if a condition satisfies or otherwise.

Here is the command which you can use.

$ [ -d yourfolder ] && echo “Directory Exists.” || echo “Directory does not exists.”

This command will first check whether there is a file named “yourfolder” in the current location and based on the result, it will decide which statement to execute.

Here if the folder is there, then it will display the line “Directory Exists.” in the terminal and if the folder is not there, then it will display the line “Directory does not exists.”.

How to Create a Directory if Not Already Created using Terminal

In this article, we are going to see how to check whether a directory is that or not in terminal and create the directory if not already there.

For this, then you can use the following command :

$ [ -d yourdirectory ] || mkdir yourdirectory

This is similar to an if condition. First it will check whether there is a directory name “yourdirectory” in the current path and if the directory is there, then it will do nothing. But if the directory is not there, it will create the directory.

How to Delete a Folder using Terminal

In this article, we are going to see how to delete a folder using terminal.

If you want to delete an empty folder, then you can use the following command :

$ rmdir emptyfoldertodelete

This will delete the folder if it is empty. But if the folder is not empty, then it will display one error message like this.

rmdir: emptyfoldertodelete: Directory not empty

If you want to delete the folder which is not empty, then you can use the following command :

$ rm -r foldertodelete

This will delete the folder even if the folder is not empty.

How to Delete the Contents of a Folder using Terminal

In this article, we are going to see how to delete the contents of a folder using terminal without deleting the folder itself.

For this, you can execute the following command :

$ rm -r “yourfoldernamewithpath/“*

This command will remove all the contents of the folder that you specify without deleting the folder. Please ensure that no space is there between the file name and *

How to Get the Full Action Name in Magento

In Magento, we will be able to get the full action name of an action object with the help of Action object. So the first step in getting the parameter is to get the Action, which triggered it.

$action = Mage::app()->getFrontController()->getAction();

Next step is to get the full name of the action. You can implement the following code.

$acionName = $action->getFullActionName();

How to get product currency short name in WooCommerce

In order to get product currency short name like USD, GBP, etc., you can you the following function: get_option(‘woocommerce_currency’)

In order to print currency symbol, you can you following function:

get_woocommerce_currency_symbol()

Or if you want to print a specific currency symbol, for example, US Dollar, you can use following function:

get_woocommerce_currency_symbol(“USD”)

How to use JHlabs image filter in spring MVC project

First you have to create image filter class like this

public class ImageFilter {
public void applyFilter(MultipartFile multipartFile){
String destination = “/your/file/destination/folder/”;
try {
GaussianFilter filter = new GaussianFilter();
filter.setRadius(8.5f);
BufferedImage imBuff = ImageIO.read(multipartFile.getInputStream());
filter.filter(imBuff, imBuff);

File outputfile = new File(destination+”image.jpg”);
ImageIO.write(imBuff, “jpg”, outputfile);

} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

And then modify the request mapping method for file upload in your controller like this

@RequestMapping(method = RequestMethod.POST)
public String fileUploaded(Model model, @Validated File file,
BindingResult result) {

String returnVal = “successFile”;
if (result.hasErrors()) {
returnVal = “file”;
} else {
MultipartFile multipartFile = file.getFile();
SaveFileToFolder save = new SaveFileToFolder();
save.saveFile(multipartFile);
}
return returnVal;
}

After running the blurred image will be stored in the location you specified.