I was trying to use cp to copy files from one directory to another by globing
for files in index/*
do
file=$(echo $files|cut -d'/' -f2)
cp -r "$files" ".target/file"
done
However, cp will give this warning if the directory is empty. I tried 2>/dev/null to mute this message but it did not work. I wonder how I could fix it.
CodePudding user response:
What about this: (not tested)
find /index -maxdepth 1 -type f -exec cp {} .target/ \;
-maxdepth 1
: only look in this directory-type f
: only take the files-exec cp {} .target/ \;
: execute a "file copy" action