Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Odd behavior with mv - "Directory not empty'

    I have a bash script, listed in crontab that archives my junk drawer.

    THe problem is that for about half a dozen files it gave trying to mv saying
    mv: cannot move `/home/eddie/junk/logs' to `/home/eddie/junk/archive/2009_Feb/logs': Directory not empty
    If I copy the exact paths printed above (which are correct) and manually enter
    mv /home/eddie/junk/logs /home/eddie/junk/archive/2009_Feb/logs
    and it does as you would expect no trouble.

    So why is it different in my script? The obvious different is the IFS, but I am doing this to allow files with spaces, and it works fine if the destination directory doesn't exist.

    #change IFS so we can handle files with spaces
    #IN case we blow, trap for exit so we can restore IFS
    trap `IFS=$RETURNIFS` 0 1 2 6 9
    # copy in place, trap set, change IFS
    IFS=$(echo -en "\v")
    set -- $OLDFILES
    # run thoughm, compare time and move out or in.
    for ITEM in $OLDFILES 
    		mv $ITEM $DPATH
    		if [ $? -ne 0 ]
    			echo "Error while moving last file" | tee -a $LOGFILE
    			exit 2
    			printf "\tSuccess\n" | tee -a $LOGFILE

  2. #2
    If you are 100% sure that the folder you want to move to doesn't exist,
    then add a rm -fr before the mv command?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts