user3019469
user3019469

Reputation: 151

cp: missing destination file operand after

Im trying to do a full back up and copy over all files from one directory into another directory

    #!/bin/bash 

    #getting files from this directory
    PROJECTDIRECTORY=/../../Project3 

    #Copied to this directory 
    FILEBACKUPLOCATION= /../.../FMonday

    for FILENAME in $PROJECTDIRECTORY/*
    do
        cp $FILENAME $FILEBACKUPLOCATION
        done  

But I keep getting this error

./fullbackup: line 6: /../../FMonday: Is a directory
cp: missing destination file operand after

Upvotes: 7

Views: 113899

Answers (5)

newbie
newbie

Reputation: 199

By the way, I was running into the same error myself. Mine turned out to be caused by misspecifying the pattern of files I wanted to be copied from the directory (meaning that the files in the directory didn't match to the pattern I specified previously). Once I fixed the pattern and the files matched the pattern, my problem was gone.

Considering the problem I have had, the error is very misleading, FYI.

Upvotes: -1

nbari
nbari

Reputation: 27005

Has you already found the variable needs to be FILEBACKUPLOCATION=/location with no space, also if possible try to make your script a little more portable by using something like:

FILEBACKUPLOCATION=$HOME/backup/FMonday

In this case, the location is relative to your user $HOME environment variable.

Going further, if you want to keep 2 files in sync probably you could do better with rsync one of the advantages is that it will only copy the files that don't exist or update the ones that have been changed.

You indeed could create an alias to copy/sync files on demand, for example:

alias cpr="rsync --delete --archive --numeric-ids --human-readable --no-compress --whole-file --verbose --info=progress2"

Then if you would like to sync contents of /dir/foo into /dir/bar, could simply do:

$ cpr /dir/foo/ /dir/bar/

Your script also could then be something like:

#!/bin/sh

ORIGIN=/path/to/foo/
DESTINATION=/path/to/bar/

rsync --delete \
--archive \
--numeric-ids \
--human-readable \
--no-compress \
--whole-file \
--verbose \
--info=progress2 \
$ORIGIN $DESTINATION

Notice that in this case the options --no-compress and --whole-file are used, mainly because the files will be copied locally, if this where a remote server options could be different, check this post (The fastest remote directory rsync over ssh archival I can muster (40MB/s over 1gb NICs)

Upvotes: 0

Sabbir Ahmed
Sabbir Ahmed

Reputation: 9

In my case, I just used used space and dot operator after the file name. It worked perfectly.

For Example, darthVader is a file name which is inside F drive. So, I used the command "mv /f/darthVader . "

Upvotes: 0

user3019469
user3019469

Reputation: 151

Variable assignments in bash scripts require no space between the variable name and value or (unless quoted) within the value. Since a space was present in the line FILEBACKUPLOCATION= /../.../FMonday, it attempted to execute /../.../FMonday as a command (which caused the first error) with FILEBACKUPLOCATION assigned to an empty string. The variable was then not assigned when the other command further down tried to use it (accounting for the second error).

Upvotes: 8

slayedbylucifer
slayedbylucifer

Reputation: 23532

I think this is what you need is FILEBACKUPLOCATION=/FMonday/

Upvotes: 2

Related Questions