Questions tagged [mktemp]
20 questions
12
votes
6 answers
Suppress warning: the use of `mktemp' is dangerous
How can I suppress following warning from gcc linker:
warning: the use of 'mktemp' is dangerous, better use 'mkstemp'
I do know that it's better to use mkstemp() but for some reason I have to use mktemp() function.

Konstantin
- 6,061
- 8
- 40
- 48
6
votes
1 answer
How do I create a temporary directory using mktemp in my current working directory?
I created a pipeline that strings multiple programs together, unfortunately these programs are creating a huge amount of temporary files in the /tmp folder and when using large datasets my pipeline crashes because the /tmp folder fills up.
How do I…

System
- 295
- 1
- 4
- 13
3
votes
2 answers
mktemp on macOS random file generation fails: file exists
When I create a random file on macOS with mktemp I get:
mktemp /tmp/test.XXXXXXX.json
mktemp: mkstemp failed on /tmp/test.XXXXXXX.json: File exists
It does not replace XXXXXXX with random string. Works fine on Linux but not on macOS.

chingis
- 1,514
- 2
- 19
- 38
2
votes
1 answer
Why mktemp with -u option is stated as unsafe in its manual?
I wanted to create a temporary file and was going through the mktemp manual and found that mktemp with -u option is stated as unsafe, what is the reason behind this ?
mktemp --help
Usage: mktemp [OPTION]... [TEMPLATE]
Create a temporary…

Shamantha Krishna
- 33
- 7
1
vote
1 answer
mktemp -d not creating temp directory
I am trying to create a temporary directory using mktemp -d but it is not creating a directory. When I try to run cd $(mktemp -d) it takes me to my home folder. This behavior is similar to cd .
When I try to run mktemp -d and check the exit code…

physio
- 109
- 1
- 13
1
vote
1 answer
How to create temporary shellscript files and directories through Tcl language?
There are numerous ways to do this and the one I present here is one of them, using the “mktemp” tool that is already installed by default in many Linux distros.
Temporary Files and Directories
The "mktemp" tool comes by default in the "GNU…

Diego Henrique
- 255
- 1
- 16
1
vote
2 answers
mkstemp() implementation for Windows to write temporary files
I want to create temporary files in given temporary directory path in Windows through C++. mktemp() does the required job, but it only creates 26 unique files. mkstemp() is working fine in Linux but it is not there in Windows. So please help me to…

raj
- 11
- 2
1
vote
1 answer
wget on failure returns last command executed code unknown
Here is a small bash code which initially creates a temporary file tmpfile using mktemp followed by a wget operation on success or failure removes the temporary file created.
#!/bin/bash -ex
tmpfile="$(mktemp)"
wget -q $1 -O /tmp/temp.txt
if [ $?…

Sunil Bojanapally
- 12,528
- 4
- 33
- 46
0
votes
0 answers
docker build cannot find file secret file outside home directory
I'm building a docker image as follows:
TEMP_FILE="/home/username/any/directory/temp"
touch $TEMP_FILE
> $TEMP_FILE
export DOCKER_BUILDKIT=1
pushd $PROJECT_ROOT
docker build -t $DOCKER_IMAGE_NAME \
--secret…

sigma1510
- 1,165
- 1
- 11
- 26
0
votes
1 answer
How do you use mktemp to create directory in Makefile?
This is a Makefile piece of code of how someone may use mktemp in a Makefile
TEST=$(shell mktemp -d)
mktemp:
echo $(TEST)
touch $(TEST)/test.txt
ls $(TEST)
cat $(TEST)/test.txt
rm -rf $(TEST)
This is an example output
❯ make…

Tiger Kaovilai
- 31
- 8
0
votes
1 answer
Can't use temp dir
I'm trying to make tmp dir with bash script using that command:
mktemp -d /tmp/foo.XXXXXXXXX\r
So, as an result a have, for example (with common in the end):
/tmp/foo.wGBkCRpYt.
But I can't change dir after that from this bash script:
cd…

user3449619
- 3
- 4
0
votes
1 answer
grep never exiting when it should be searching through a small tempfile
I have a problem with mktemp and grep.
OUT=$(mktemp /tmp/output.XXXXXXXXXX) || { echo "Failed to create temp file"; exit 1; }
awk -F: '{print $7}' /etc/passwd >> $OUT
grep -c $1 $OUT
In grep line, code not exits, not prints value of grep
Please,…

John
- 9
0
votes
2 answers
random file name in perl generated with unusual characters
Using this perl code below, I try to output some names in a random generated file. But the files are created with weird characters like this:
"snp-list-boo.dwjEUq5Wu^J.txt"
And, obviously when my code looks for these files it says not such file.…

DanielSebas
- 135
- 6
0
votes
1 answer
mktemp with extension without specifying file path
Prefacing this with that I found identical questions but none of them have answers that are working for me.
I need to make a temporary .json file (it needs to be json because I'll be working with jq later in the script).
I thought based on the…

Alex
- 2,555
- 6
- 30
- 48
0
votes
2 answers
mktemp vs. umask 066 and touch?
My bash shell requires a temp file. Suppose filename conflict is not an issue, can I say mktemp is not as good as manually touch a temp file after umask 066?
My assumption is:
mktemp is a system function, compared to manually touch a file, it still…

0PT1MU5 PR1ME
- 45
- 1
- 11