# Taming files and directories with spaces # # Usage: # # andrea@exnihilo:/tmp/test $ ls # 'a dir with spaces' # # andrea@exnihilo:/tmp/test $ ls a\ dir\ with\ spaces/ # 'a file with spaces and'$'\t''tabs' # # andrea@exnihilo:/tmp/test $ for f in $(find ./ | spacemark); do ls -ld "$(spaceunmark $f)"; done # drwxr-xr-x 3 andrea andrea 4096 lug 29 17:07 ./ # drwxr-xr-x 2 andrea andrea 4096 lug 29 17:09 './a dir with spaces' # -rw-r--r-- 1 andrea andrea 0 lug 29 17:09 './a dir with spaces/a file with spaces and'$'\t''tabs' # # Installation: # Put the following in your .bashrc spacemark() { while read l do l="${l// /__SPACEMARK__}" l="${l//[[:blank:]]/__TABMARK__}" echo "$l" done } spaceunmark() { set -- "${1//__SPACEMARK__/ }" set -- "${1//__TABMARK__/ }" echo "$@" }