Mktemp: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(3 intermediate revisions by the same user not shown)
Line 5: Line 5:
=Overview=
=Overview=


<code>mktemp</code> takes file name templates and overwrites portions to generate a unique file name, creates the empty file with 0600 permissions (only the current users can read and write) and display the file name at stdout. If no template is given, a unique file name appropriate to the system will be generated. On Mac, <code>mktemp</code> creates something similar to <code>/var/folders/t3/mmn20npx7fs31lwlp2s4_6wm0000gq/T/tmp.hbvowAQL</code>.
<code>mktemp</code> takes file name templates and overwrites portions to generate a unique file name, creates the empty file with 0600 permissions (only the current users can read and write) and displays the file name at stdout. If no template is given, a unique file name appropriate to the system will be generated and the empty file is created. On Mac, <code>mktemp</code> creates something similar to <code>/var/folders/t3/mmn20npx7fs31lwlp2s4_6wm0000gq/T/tmp.hbvowAQL</code>.
Create a uniquely named temporary file or directory and display its name at stdout.
Create a uniquely named temporary file or directory and display its name at stdout.


Line 13: Line 13:
</syntaxhighlight>
</syntaxhighlight>


<font color=darkgray>Who's responsibility is to delete it? It is deleted automatically?</font>
The file such created is NOT removed automatically, it is the user's responsibility to remove it.


=Options=
=Options=
Line 21: Line 21:
  mktemp -d
  mktemp -d
</syntaxhighlight>
</syntaxhighlight>
=Delete Temporary Directory on Exit=
{{Internal|Trap#Delete_Temporary_Directory_on_Exit|Delete Temporary Directory on Exit}}

Latest revision as of 04:51, 4 May 2022

Internal

Overview

mktemp takes file name templates and overwrites portions to generate a unique file name, creates the empty file with 0600 permissions (only the current users can read and write) and displays the file name at stdout. If no template is given, a unique file name appropriate to the system will be generated and the empty file is created. On Mac, mktemp creates something similar to /var/folders/t3/mmn20npx7fs31lwlp2s4_6wm0000gq/T/tmp.hbvowAQL. Create a uniquely named temporary file or directory and display its name at stdout.

local f
f=$(mktemp) || exit 1

The file such created is NOT removed automatically, it is the user's responsibility to remove it.

Options

-d

Create a temporary directory instead of a file.

 mktemp -d

Delete Temporary Directory on Exit

Delete Temporary Directory on Exit