The nice command enables you to run a command with a different nice value than the default. The -n option increments the nice value by the given integer; if you don’t provide an integer, then the command will assume an increment of 10. By running nice without any options, you’ll see the default nice value. You must have the root user authority to run a command at a higher priority. Once lowered, the priority for any process cannot be increased by normal users, even if they own the process.
Syntax
The syntax of the nice command is:
# nice [-n {nice value increment}] [command]
If you encounter the below error while running the nice command:
nice: command not found
you may try installing the below package as per your choice of distribution:
Distribution | Command |
---|---|
OS X | brew install coreutils |
Debian | apt-get install coreutils |
Ubuntu | apt-get install coreutils |
Alpine | apk add coreutils |
Arch Linux | pacman -S coreutils |
Kali Linux | apt-get install coreutils |
CentOS | yum install coreutils |
Fedora | dnf install coreutils |
Raspbian | apt-get install coreutils |
Normally, when a process is started, it gets the default priority value of 0. The nice command is used to start a process with a different priority. Its syntax is as follows:
# nice -n [NICELEVEL] [command]
Here’s an example of setting a big job to run at nice level 7:
# nice −7 sort VeryLargeFile > outfile
If you run nice without a level, 10 is used. Normal processes (run without nice) run at level zero, which you can see by running nice with no arguments:
# nice 0
The superuser can also lower the nice level, increasing a process’s priority:
# nice --10 myprogram
(Yes, that’s “dash negative 10”.) To see the nice levels of your jobs, use ps and look at the “NI” column:
# ps -o pid,user,args,nice