Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 4 down vote accepted

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.

share|improve this answer

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}
share|improve this answer
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. – JVerstry 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 posting your answer, you agree to the privacy policy and terms of service.

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