-1

change tmp folder for sudo / root command

in .bashrc file added

export TMP=/new/tmp
export TEMP=/new/tmp
export TMPDIR=/new/tmp

Also created a symlink for /tmp to new location

apps that i am running without sudo they create temp files in the new location. However, none of sudo programs create there their temp files.

permisions 1777 root:root.

What i must do?

I have tried eg. TMP=/NEWTMP sudo app but no success.

1 Answers1

3

By default, sudo performs an "env_reset":

 By default, the env_reset flag is enabled.  This causes commands to be
 executed with a new, minimal environment.

If your local policy permits, you can override this with the -E / --preserve-env option, ex.

$ TMP=/NEWTMP sudo -E sh -c 'echo $TMP'
/NEWTMP

or

$ TMP=/NEWTMP sudo --preserve-env=TMP sh -c 'echo $TMP'
/NEWTMP
steeldriver
  • 136,215
  • 21
  • 243
  • 336
  • I wanted to move swap files to another place cause space was filled in. I bought new memory, and swapping was very reduced. So, this solved my problem. Thanks. I will vote your answer as a solution without trying out actually... – Estatistics Apr 28 '22 at 17:32