User Tools

Site Tools


info:mac:rmdir

rmdir for OSX

The Finder on OSX creates .DS_Store files in the directories to store its settings. This makes removing directories from the command line quite complicated:

$ rmdir test
rmdir: test: Directory not empty
$ rm test/.DS_Store 
$ /bin/rmdir test

I wrote a small bash function to remove directories together with the contained .DS_Store file:

rmdir() {
for d in "$@"
do
	f="${d%/}/.DS_Store"
	if [ -f "${f}" ]
	then
		echo "removing ${f}"
	 	rm "${f}"
	fi
	/bin/rmdir "${d}" || ls -al "${d}"
done
}

With this function you can remove the directory at once:

$ rmdir test
removing test/.DS_Store
info/mac/rmdir.txt · Last modified: 2015-11-25 10:43 by andunix