--nice with cp for giving more processor priority on cp?

How can I use --nice=-10 with cp command in linux ?

Following are the example when I tried the option and it gives the error unrecognized option EX- error:

cp --nice=-20 -r dir1 /d/
cp: unrecognized option `--nice=-20'
Try `cp --help' for more information.

Solution 1:

nice is a command on its own, it isn't an option to the cp command.

From man nice:

NAME
       nice - run a program with modified scheduling priority

SYNOPSIS
       nice [OPTION] [COMMAND [ARG]...]

DESCRIPTION
       Run COMMAND with an adjusted niceness, which affects process scheduling.
       With no COMMAND, print the current niceness.  Nicenesses range from -20
       (most favorable scheduling) to 19 (least favorable).

       -n, --adjustment=N
              add integer N to the niceness (default 10)

So for your purposes, you would use this:

nice -n -20 cp -r dir1 /d/

Solution 2:

With cp you may be more I/O-limited than CPU-limited. To adjust the I/O priority, you can use the ionice command - see man ionice. For example, to get 'Best effort' priority with highest preference among all best effort processes, run

ionice -c 2 -n 0 cp -r dir1 /d/

You can also combine it with nice to adjust both CPU and I/O priority:

ionice -c 2 -n 0 nice -n -20 cp -r dir1 /d/