System and processes

The nice command

Runs a command with a different scheduling priority, from -20 to 19.

Syntax

nice [-n N] [COMANDO [ARGUMENTO]...]Try it in the terminal →

Most useful options

-n NAdds N to the shell priority. Without this option, the default addition is 10
--adjustment=NSame as -n N, with the long form
--helpShows the help and exits
--versionShows the version and exits

Copy-ready examples

$ niceshows the current priority of the shell, without running anything.

Example output

0
$ nice -n 15 tar -czf copia.tar.gz Documentoscompresses a large folder while leaving the CPU to other programs.
$ nice -n 19 sleep 300 &starts a background task at the lowest priority.
$ sudo nice -n -5 ./servidora negative value raises the priority. Only root can do it.

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
nice: 'no_existe_xyz_123': No such file or directoryThe program does not exist or is not in PATH. nice tries to start it and fails to find it.Check the name with type or which, or write the full path.

Typical mistakes

  • The number works the other way round than it seems: 19 is the lowest priority and -20 the highest.
  • -n adds to the current value: if the shell is at 5, nice -n 10 leaves the program at 15.
  • The exit status is 125 if nice itself fails, 126 if the program cannot be run, 127 if it does not exist, and the program's own otherwise.

Differences from similar commands

  • renice: changes the priority of a process that is already running. nice only starts something new.
  • ps: its NI column shows the priority of each process, to check the effect.
  • chrt: sets real-time scheduling policies. nice only adjusts the normal priority value.

Related commands

FAQ

What priority does a process get without nice?

The one it inherits from the shell, usually 0. nice only shifts it when it starts.

Can I undo it if I lowered the priority?

Not always without privileges: raising the number is easy, but going back to a lower value depends on the RLIMIT_NICE limit, shown with ulimit -e.

Will I notice anything when the CPU is idle?

Hardly. Priority only decides who wins when the CPU is contended.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course