0

How to change default tmp location in Ubuntu?

I am using Ubuntu for my applications. I have seen that many APIs store their tmp files in /tmp folder.

In my Ubuntu, total space assigned to root is hardly 4 GB. Which is why I have to keep cleaning the /tmp folder to avoid disk space error.

Can I change /tmp to some other partition and allocate more space to it ?


UPDATE:

I have considered resizing partitions, but I can not risk data loss. Also, I can not risk impacting other applications which might have some data in /tmp folder.

As of now, I am using shell script to clean it every 10 minutes.

Learn More
  • 1,535
  • 4
  • 29
  • 51
  • 1
    I think this is what you are looking for: http://unix.stackexchange.com/a/5503 – Xavier Quintana Feb 06 '13 at 09:40
  • *...I am using shell script to clean it every 10 minutes.*: that sounds dangerous. How do you avoid applications misbehaving because of missing temporary files? – thkala Feb 10 '13 at 09:08
  • In this case, I know which files I am cleaning and how they are generated. I also know impact of cleaning these files. So I am doing it safe way. But if I am able to Increase space OR point /tmp to a larger space, it will remove need to clean these files. – Learn More Feb 10 '13 at 17:09

4 Answers4

4

Many applications look at the TMPDIR environment variable for the name of the temporary file directory, before defaulting to using /tmp. A simple partial solution to your problem (and possibly several others) could be to have a per-user temporary directory e.g. /home/$USER/tmp by setting the TMPDIR variable in the profile of each user.

That would move most temporary files to /home, with the added advantage that users would no longer be able to interfere with the temporary files of other users.

thkala
  • 84,049
  • 23
  • 157
  • 201
0

in general, it is possible, but it can be pretty dangerous. Make yourself sure that your data are backed up. There are many tools how it can be done. You need some partition manager like fdisk (it is a command line), or graphical GParted

General advice: for your root \ I'd recommend some 20GB (standard desktop app), for \tmp it depends on what kind of application you will use (resource-demanding, or just open office) some 1-2GB

xhudik
  • 2,414
  • 1
  • 21
  • 39
  • How is that dangerous? And the OP already said, that `/`[sic!] is only 4G, I think (s)he thought about increasing that size already. – filmor Feb 06 '13 at 09:37
  • well, i understood the question like @Learn More found out that his partitions are not very well sized. Therefore I proposed to resize his(er) partitions. Dangerous - partition modification is always dangerous (lost of data). But maybe I didn't get the question correctly ... – xhudik Feb 06 '13 at 09:47
0

I don't think it is possible (at least in an easy way). Even if it would be, I would not advice that, because many programs/scripts use hardcoded "/tmp" so various errors may occur. However, you may try to link /tmp to some other directory, it might do the trick (it's up to you to experiment, I did not try this myself).

KBart
  • 1,580
  • 10
  • 18
0

You can either change /tmp to a symlink or bind-mount it somewhere in your fstab.

filmor
  • 30,840
  • 6
  • 50
  • 48