1017Finding and Deleting Files without Content

Finds all empty JPEGs at current directory:

find . -maxdepth 1 -name "*.jpg" -size 0

Finds and deletes all empty JPEGs at current directory:

find . -maxdepth 1 -name "*.jpg" -size 0 -delete

Finds and deletes all empty JPEGs in all sub-directories.

find . -maxdepth 2 -name "*.jpg" -size 0 -delete

Sources: 1, 2

979Batch Rename Files with rename

Batch renaming files on the command line, in this case screenshot to more descriptive names:

brew install rename

Dry run:

rename -n -e 's/Screen Shot/w2_OpenSCAD/' -z  *.jpg

Replace, remove the -n flag:

rename -e 's/Screen Shot/w2_OpenSCAD/' -z  *.jpg

-z does sanitize the file name, replacing empty spaces with _.

805Recursively removing .svn directories

When you'are working with Subversion, the situation might be familiar: You have checked-out some directories and want to check them in at another repository. Subversion is not happy to do that, it complains with a friendly reminder, that 'your directory' is already under version control.

The proper way to do it, would probably be to export a clean directory tree, but sometimes this option is not available.

Here's a simple shell script to recursively remove all the hidden '.svn' directories:

rm -rf `find . -type d -name .svn`

Wether it is better to use backticks or xargs is being discussed elsewhere.