Display what has been copied by `cp` (using `ksh`)

Like Lawrence has mentioned, you can use

cp -v

to enable "verbose" mode, which displays the files you copy. Something else that might be useful is

cp -v > foo

which will output the list of files to a file called foo. This is useful if you're going to copy a lot of files and you want to be able to review the list later.


cp -v enables verbose mode which displays what's being copied.


Check if your system has the -v option to cp.

If it doesn't, you can make a loop to show the file names and copy them one by one. This is not completely straightforward if you want to keep track of whether some copies failed.

err=0
for x in ./sourceDir/*; do
  echo "$x -> $destinationPath/${x##*/}"
  cp "$x" "$destinationPath/" || err=1
done
return $err

Alternatively, you might use a tool with many options such as rsync.

rsync -av ./sourceDir/ "$destinationPath/"

Going in the other direction, you might find it enough to see the expansion of the wildcard.

echo "Copying files:" ./sourceDir/*
cp ./sourceDir/* "$destinationPath/"

Or you might print a trace of shell commands:

set -x
cp ./sourceDir/* $destinationPath/

Tags:

Ksh

Cp