Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.
share|improve this question

2 Answers 2

up vote 5 down vote accepted

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/
share|improve this answer
    
@sreeraj also, look into "renice" for commands that are already in progress. –  Sirex Nov 5 '11 at 8:37
    
ionice is likelier to be effective with and I/O bound process like cp. –  BillThor Nov 5 '11 at 17:05

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/
share|improve this answer
    
If you renice the process it implicitly renices IO too. "The priority within the best effort class will be dynamically derived from the cpu nice level of the process: io_priority = (cpu_nice + 20) / 5." –  Matthew Ife Nov 6 '11 at 16:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.