cp -p /home/* home/exp/*.date not working please help

:frowning:

---------- Post updated at 01:51 AM ---------- Previous update was at 01:50 AM ----------

Not working

---------- Post updated at 02:04 AM ---------- Previous update was at 01:51 AM ----------

cp -p /home/* home/exp/*.`date`

i am using this

I'm not sure what you're even trying to do with multiple wildcard and NO destination directory given. Copy files into multiple destinations or what? cp doesn't do that, it takes one destination.

What files are you trying to copy, from what source, to what destination? Be specific.

trying to copy a list of files from one directory to another with date stamp

---------- Post updated at 02:07 AM ---------- Previous update was at 02:05 AM ----------

source /home :: all files
destination /home/exp

Try this,

ls /home | awk '/^-/{print $NF}' | while read file; do echo cp "$file" /home/exp/"$file.`date '+%d%m%Y'`"; done

I'm still not completely sure I understand what you want. You're copying multiple directories into one destination directory, but need to rename the directories in the process? You can't put a * in the destination like that, this isn't like DOS: The shell splits * for you before cp is even run, so you end up inputting stuff into cp that doesn't make sense if you * for things that don't exist yet.

I think you're going to have to split it into seperate cp calls.

for DIR in /home/*
do
        # Don't copy exp into exp/exp-timestamp!  It'd copy the copied copy copies!
        [ "$DIR" == "/home/exp" ] && continue

        NAME=`basename "$DIR"`
        cp -p "/home/${NAME}" "/home/exp/`date`-${NAME}"
done
1 Like