Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tmp folder in Windows like /tmp in Linux [closed]

Tags:

windows

tmp

I have created a folder in Windows, C:\tmp\ and I want it to behave like /tmp/ folder in Linux, i.e. its contents are removed every time the system is booted.

I think the commands to run could be (at least on windows 7):

RD C:\tmp /S /Q
MKDIR C:\tmp

A way to execute this commands on every boot? Or, any better way to accomplish this?

like image 906
Diego Herranz Avatar asked Feb 27 '13 11:02

Diego Herranz


People also ask

What is equivalent to tmp on Windows?

You should use the environment variable %TEMP% which points to different locations on different Windows versions, but is the defined location for temporary data in Windows.

Does Windows have a tmp directory?

LAST UPDATED: MAY 24, 2022 On your keyboard, press the Windows + R keys at the same time. In the Open field, type %temp%, then press ENTER. The temp folder will open. You can also access it on your Windows 10 PC via the shortcut button below, then choose Temporary files.

What is the tmp folder in Linux?

Web servers have a directory named /tmp used to store temporary files. Many programs use this /tmp directory for writing temporary data and generally remove the data when it is no longer needed. Otherwise the /tmp directory is cleared when the server restarts.

Does Linux delete tmp files?

By default, all the files and data that gets stored in /var/tmp live for up to 30 days. Whereas in /tmp, the data gets automatically deleted after ten days. Furthermore, any temporary files that are stored in the /tmp directory get removed immediately on system reboot.


2 Answers

You should use the environment variable %TEMP% which points to different locations on different Windows versions, but is the defined location for temporary data in Windows.

Windows doesn't clean it up by itself, but it is fine to delete its contents on shutdown (and as lots of applications don't clean up properly, it is recommended to do so once in a while).

Do not delete the %TEMP% folder, but it's contents using del %TEMP%\* /s /f /q which will delete the contents instead, so you don't need to recreate the folder.

For setting up a shutdown-script, use the answer provided by @Alex K.

like image 194
Jens Erat Avatar answered Nov 06 '22 19:11

Jens Erat


I do it via a shutdown script to clear a directory called c:\null

Run gpedit.msc & see http://technet.microsoft.com/en-us/library/cc770300.aspx for instructions on configuring a script to run.

The bat file I run is

@echo off
@rd c:\null\ /s /q
@md c:\null
like image 45
Alex K. Avatar answered Nov 06 '22 19:11

Alex K.