Questions tagged [mktemp]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer

How many "X"'s should I use to create temporary files safely and portably with `mktemp`?

From time to time, I create temporary files from shell scripts by invoking the command mktemp with 6 or more X's in the argument TEMPLATE. However, I am unsure if that amount will work with other ...
qqqq's user avatar
  • 48
-1 votes
1 answer

bash script explanation [closed]

I have below script which I am unable to understand. Can someone explain the same. #!/bin/sh skip=14 tmpdir=`/bin/mktemp -d ${TMPDIR:-/tmp}/gzexe.XXXXXXXXXX` || exit 1 prog="${tmpdir}/`echo \&...
kcmakwana's user avatar
1 vote
1 answer

Redirect spawned process to tempfile with the pid in its filename

Suppose myprogram is spawned through the terminal (bash) and gets pid of 1234 (different everytime). I want to redirect, both stdout and stderr, to a tempfile named abc-$PID (if the PID is 1234, use ...
sudoer's user avatar
  • 45
0 votes
2 answers

How to design reusable script handling temporary files lifecycle for other scripts

I need to create a reusable ("utility") script handling entire set of operations with temporary files for any of my other ("application") scripts: creation tracking of temporaries ...
wass rubleff's user avatar
3 votes
1 answer

Why creating files in /dev/shm is not faster than creating files in /tmp?

Let's say I have two bash files. The first one is called diskFile.bash: for i in {1..10000} do file=$(mktemp) cat > $file <<- "SIGN" "Hello World" SIGN ...
raylight's user avatar
  • 421
0 votes
1 answer

How to safely create file in bash [duplicate]

I have a script that creates a temporary file as a flag to guard against the script being run simultaneously. Currently it uses tempfile, e.g. if ! tempfile -n /tmp/updating > /dev/null; then ...
Steve Piner's user avatar
0 votes
1 answer

mkstemp failing with RHEL 8 OS non-root user

I have small script which creates a tmp files using mkstemp. My script was created using root user , but if I logged in as someother user other than root then my scripts runs but msktemp fails and ...
cjoshi's user avatar
  • 1
7 votes
3 answers

Is there some interactive analogue of `mktemp` that helps to organize throw-away directories?

I often want a temporary directly where I can unpack some archive (or create a temporary project), see around some files. It is unpredictable in advance for how much time a particular directory may be ...
Vi.'s user avatar
  • 5,678
4 votes
2 answers

How to create a temporary file that has "normal" permissions?

In a build script I want to create a temporary file that has a unique generated name, then write some data to it, and then rename that file to its final name (the reason for this procedure is that I ...
oliver's user avatar
  • 458
1 vote
1 answer

mktemp creates file in pwd rather than in /tmp

Previously mktemp used to create files in /tmp. Today I noticed that mktemp is creating file in $PWD rather than in /tmp? Did I change something inadvertently? Any suggestions to fix this? Note: I ...
Porcupine's user avatar
  • 1,844
0 votes
1 answer

Using mktemp in makefile

I want to create a temporary file and pipe some text into it using a makefile. In bash, I can create a temp file and pipe text into it like so: temp_file=$(mktemp) echo "text goes into file" ...
karpfen's user avatar
  • 155
23 votes
2 answers

Why is there no mktemp command in POSIX?

One of the most common things shell scripts need to do is to create and manipulate temporary files. Doing so safely is a pain, since you need to avoid name clashes, avoid race conditions, make sure ...
Psychonaut's user avatar
12 votes
1 answer

mktemp on macOS not honouring $TMPDIR

I've noticed this before, but it was brought up again as I was answering "How to move directory into a directory with the same name?": The mktemp utility on macOS does not behave the same as the ...
Kusalananda's user avatar
  • 331k
5 votes
1 answer

Why is mktemp -u considered "unsafe"?

I read the --help text for mktemp recently (the man page wasn't available) and came upon this: -u, --dry-run do not create anything; merely print a name (unsafe) Why is this "unsafe"? Is ...
S.S. Anne's user avatar
  • 462
0 votes
1 answer

Deleting temporary direction via trap

I have a script which looks like this: #!/bin/bash set -e tmpdir=$(mktemp -d) pushd $tmpdir trap 'popd && rm -rf $tmpdir' EXIT # Business logic which may succeed or fail... /bin/false ...
Stewart's user avatar
  • 13.6k
1 vote
2 answers

Is there a programmatical difference between directories created with mktemp -d or mkdir?

I try to understand Stephen Kitt's answer to this question where he created a temporary directory with the following code: #!/bin/bash scripttmp=$(mktemp -d) # Create a temporary directory (these ...
user avatar
2 votes
1 answer

Is it OK to overwrite a file created by mktemp?

I'd like to copy a file to a temporary location. I'd like to make sure I'm not overwriting anything important, and that I know the location of the file while the script is running. #!/bin/bash ...
user's user avatar
  • 339
0 votes
2 answers

Can a script unmount the volume containing itself?

I have a computer with a hard drive mounted read-only. I am running a script from a flash drive. I would like the script to be able to unmount the flash drive, but this can't be performed as the ...
sondra.kinsey's user avatar
1 vote
1 answer

`mktemp -d` followed by `pushd` works fine on command line, but not when in a script

If I paste these lines into a command prompt on Debian... DIR=$(mktemp -d -t bbbrtc.XXXXXX) || exit 1 echo "tmpdir = $DIR" cd "$DIR" They make a new temp directory, print the directory name, and ...
bigjosh's user avatar
  • 599
2 votes
2 answers

Improving mktemp

I am wondering how to best improve on mktemp for use with encrypted containers or file systems. The issue that I am dealing with is that I would like my shell scripts to store temporary files inside ...
highsciguy's user avatar
  • 2,574
3 votes
3 answers

How to create multiple files/directories with randomized names?

I'm trying to create some files that has different names and with different extensions. Let say I want to create for example 3 files with following name and extension: File001.000 File002.001 File003....
αғsнιη's user avatar
  • 41.3k