Work experience |

 Your Ad Here

Linux Bash script: spaces in file names as one command |


Recently I was writing Bash shell script, which moves files and directories from one server to other. As files and folders are created by end users, there are problems about file names.
Users create folders with spaces e.g. very important and Bash script interprets it as two sepparate folders: very and important when my scrit finds all folders and starts to move them, I get error on folders with spaces. This is the command:
mv -fv `find /mnt/volume/tomove -mtime +14` /path/tomovewhere

This piece of code moves files and folders older than 14 days from /mnt/volume/tomove to /path/tomovewhere
So, if there is folder /mnt/volume/tomove/very important Bash tries to move /mnt/volume/tomove/very and important
To interpret directories as one command you will need to add this variable to your script:
IFS=$'\n'

$IFS is internal field separator, this variable determines how Bash recognizes fields, or word boundaries, when it interprets character strings.
You can find more info with samples here:
http://tldp.org/LDP/abs/html/internalvariables.html

Comments:


Name:
captcha