What is the difference between the following su commands?

su -m
su -p

I know that both flags are used to preserve the current environment but I don’t know the differences if there are any.


There are no differences, they are just different options for the same behaviour. They probably come from different older versions of su that implemented one of these options with the same behaviour.

From the man page:

 -m, -p, --preserve-environment
     Preserve the current environment, except for:

         reset according to the /etc/login.defs options ENV_PATH or
         ENV_SUPATH (see below);

         reset to “<space><tab><newline>”, if it was set.

     If the target user has a restricted shell, this option has no
     effect (unless su is called by root).
  • Actually I observed some differences using different flags (m or p). I have a script which behaves differently if I use -m than if I use -p.
    – coffeMug
    Jun 11 '13 at 19:31
  • And your man page says it is the same? What version of su? On which system? Does su --help give an difference for the two?
    – Anthon
    Jun 11 '13 at 19:33
  • I don’t have access to the system now. Tomorrow I will check the su version etc.
    – coffeMug
    Jun 11 '13 at 19:35
  • Ok, my information is from Ubuntu 12.04
    – Anthon
    Jun 11 '13 at 19:36
  • @Anthon: There is no man page available in the linux version I am using but according to --help output it says "-m, --preserve-environment do not reset environment variables -p same as -m". And the linux version I am using is: SUSE Linux Enterprise Server 11 SP2.
    – coffeMug
    Jun 12 '13 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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