Questions tagged [mktemp]
The mktemp tag has no usage guidance.
17
questions
3
votes
0
answers
108
views
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
...
0
votes
1
answer
93
views
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
...
0
votes
1
answer
65
views
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 ...
6
votes
3
answers
730
views
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 ...
2
votes
2
answers
781
views
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 ...
0
votes
1
answer
92
views
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 ...
0
votes
1
answer
622
views
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" ...
20
votes
2
answers
2k
views
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 ...
9
votes
1
answer
2k
views
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 ...
2
votes
1
answer
2k
views
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 ...
0
votes
1
answer
175
views
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
...
1
vote
2
answers
2k
views
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 ...
1
vote
1
answer
243
views
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
...
0
votes
2
answers
97
views
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 ...
1
vote
1
answer
495
views
`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 ...
2
votes
2
answers
2k
views
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 ...
3
votes
3
answers
18k
views
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....