Copy folders on Mac using Finder replaces the folders instead of merging them like in Windows

I didn’t know about that and lost some valuable data by copying using finder. Best way to copy is to switch to terminal and do a copy using ‘cp -R’ command. The cp command does a merge instead of replacing. You can also try ‘ditto’ command.

Disk usage and disk free space on unix

df -h //shows disk free space in mb, gb or bytes
df -k //shows size in kb

du -a /home | sort -n -r | head -n 10//gives the top 10 folders by size

internet connection dies on uploading a file (to Gmail etc.)

I have been having this weird issue where my internet connection dies when I upload a file larger than 5mb. I thought it could be the router so changed the router. Still had the same issue. So this time, I connected my PC directly to modem and tried the upload. With in a minute of the initiating the upload all the lights on modem went off except the power light. So that implied a problem with the modem. Replacing the modem(a Dlink) with a Linksys modem fixed the problem for good.

using find, xargs, grep when the directory or file names contain space

The following command doens’t return any results :

command:
find . -name ‘struts*prop*’|xargs -t grep -si objectFactory
result:
grep -si objectFactory ./jive war/jive-5.0.2.1.war/WEB-INF/classes/struts.properties ./jive war/jive-sbs-employee-4.0.12.war/WEB-INF/classes/struts.properties

As you can see the directory name ‘jive war’ has a space. To overcome this limitation, use the following command:

command:
find . -name ‘struts*prop*’ -print0|xargs -t0 grep -si objectFactory
result:
grep -si objectFactory ./jive war/jive-5.0.2.1.war/WEB-INF/classes/struts.properties ./jive war/jive-sbs-employee-4.0.12.war/WEB-INF/classes/struts.properties
./jive war/jive-5.0.2.1.war/WEB-INF/classes/struts.properties:###       Alternatively, you can provide a com.opensymphony.xwork2.ObjectFactory subclass name here

Note the number zero in -print0 and -t0. That is a way to map end of line to a character in find and then tell xargs to ignore white space and tread character as end of string.

You can also use find with ‘-exec‘ option.

grep recursively, ignoring case, only in specific files like ‘.properites’ files

grep -ir –include ‘*.prop*’ ‘struts.objectfactory’  ~/Downloads/temp/

unix find command

To find files based on name, the syntax is

find [path…] -name filepattern

Examples:

find ~/Downloads/temp -name struts*xml

To use a regular expression:

find ~/Downloads/temp/ -regex .*jar.*/stru.*xml

Find other options here.

A strange thing I have noticed with the command “find ./ -name struts*” is that it only searches for files that match the name struts-tags.tld and ignore files like struts.xml. Later found out that the folder from where I am executing this search has only file that matches the format ‘struts*’, which is struts-tags.tld. So this looks like a feature of OSX to expand the struts* to struts-tags.tld. If there are more than one file that match the pattern, find will throw an error. So the correct way to search is to include the name in quotes as shown below:

find ~/Downloads/temp/ -name ‘sitemesh*’

Unknown builder org.eclipse.ajdt.core.ajbuilder from M2E Maven plugin after importing projects

I noticed that Eclipse wasn’t picking up my latest changes while running jUnit tests. Looking at the builders in project properties showed that org.eclipse.ajdt.core.ajbuilder was marked as an unknown builder. Installing AspjectJ tools for Eclipse fixed the problem.