This must be a very simple issue to solve, but I am stuck (not a UNIX pro). I need to move a gz to a target directory, but I get a No such file or directory.

NOW=$(date +"%Y-%m-%d-%T")

echo "$SQL_DUMP"

drush sql-dump | gzip -9 > $SQL_DUMP

The sql.gz is created properly, only the last command does not work. How should I use it? Thanks.


The problem is not with your mv command.

Tilde expansion is the name for what the shell does when it replaces the ~ character with the user's home directory, e.g. /home/username. It is possible to tell the shell to not do this by quoting the tilde character. This is exactly what you have done in


You have assigned to DEST the string ~/scripts/backup. This directory does not actually exist. Two solutions:

  • Don't quote the ~ character:

  • Use $HOME instead:


A final debugging tip

Put set -x at the top of your script to turn on the xtrace option. If you had done that you would have seen that the mv command was using the wrong directory, ~/scripts/backup instead of /home/yourname/scripts/backup.


Read mv manual

    mv [SOURCE] [DEST]

And you may want to check if $DEST already exist:

if [ -d ${DEST} ]; then
    do something

If not, use mkdir with -p as parameter to make parent directories.

    mkdir -p ${DEST}
  • I did try those mv source target too, but same issue. I think it has to do with '~'. The directory exists, this is not the issue. – Jérôme Verstrynge Feb 17 '12 at 21:40
  • Then use absolute path: /home/user/scripts/backup, or use $HOME – ramonovski Feb 17 '12 at 21:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.