suggestion: naming temp files

I often want temp files. Putting them in /tmp means that they will automatically be discarded on reboot -- kind of handy. But it means that they are public: they are in a space shared with all other users (if you have other users). I consider it a bad habit for that reason. Lots of people put temp files in the current directory or in their home directory. That's what I do. But then, when you come back a week later, how do you know that this file is garbage? The best way is to have a naming convention. Many people use tmp, tmp2, tmp3 as names. I find those visually too like real filenames and longer to type than I want. The names I use are 0, 1, 2, 3. They are short, distinctive, and unreasonable as permanent filenames. You can find the litter you left behind with: locate -r '/[0-9]$' You will notice that the system does have some files that match too so you cannot blindly delete all matches. To me, it is obvious. But I didn't think of it. I copied this from Chris Sturgess almost 30 years ago.

On 17 April 2018 at 11:43, D. Hugh Redelmeier via talk <talk@gtalug.org> wrote:
Many people use tmp, tmp2, tmp3 as names. I find those visually too like real filenames and longer to type than I want. The names I use are 0, 1, 2, 3. They are short, distinctive, and unreasonable as permanent filenames.
Why not use mktemp? "man mktemp" for information about templates, suffixes etc.

| > Many people use tmp, tmp2, tmp3 as names. I find those visually too like | > real filenames and longer to type than I want. The names I use are 0, 1, | > 2, 3. They are short, distinctive, and unreasonable as permanent | > filenames. | | Why not use mktemp? "man mktemp" for information about templates, suffixes etc. Or in your .cshrc or .bashrc something like mkdir -m 700 -p /tmp/me tmp="/tmp/me" export TMPDIR=/tmp/me I'm far too lazy to want to have to remember to clean up after myself. John

| From: Val Kulkov via talk <talk@gtalug.org> | Why not use mktemp? "man mktemp" for information about templates, suffixes etc. That's what one should do in scripts. It's part of making scripts bullet-proof. It's funny how tricky it is to get this right (race conditions, etc.). I'm sorry that I didn't make it clear that I use my naming convention on the command line (and from my text editor, etc.). Not in scripting.

On 17 April 2018 at 11:43, D. Hugh Redelmeier via talk <talk@gtalug.org> wrote:
I often want temp files.
Putting them in /tmp means that they will automatically be discarded on reboot -- kind of handy. But it means that they are public: they are in a space shared with all other users (if you have other users). I consider it a bad habit for that reason.
Lots of people put temp files in the current directory or in their home directory. That's what I do. But then, when you come back a week later, how do you know that this file is garbage? The best way is to have a naming convention.
Many people use tmp, tmp2, tmp3 as names. I find those visually too like real filenames and longer to type than I want. The names I use are 0, 1, 2, 3. They are short, distinctive, and unreasonable as permanent filenames.
You can find the litter you left behind with: locate -r '/[0-9]$' You will notice that the system does have some files that match too so you cannot blindly delete all matches.
To me, it is obvious. But I didn't think of it. I copied this from Chris Sturgess almost 30 years ago.
If ID-ing the source of the files is an issue (as it would be if they aren't occasionally auto-deleted, such as in /tmp/), I often use mktemp (as has already been suggested) in combination with part of the filename being '$(basename $0)' so you know what script created it. That's a Bashism - there's probably an equivalent in other shells. -- Giles https://www.gilesorr.com/ gilesorr@gmail.com

On Tue, Apr 17, 2018 at 11:43:38AM -0400, D. Hugh Redelmeier via talk wrote:
I often want temp files.
Putting them in /tmp means that they will automatically be discarded on reboot -- kind of handy. But it means that they are public: they are in a space shared with all other users (if you have other users). I consider it a bad habit for that reason.
Lots of people put temp files in the current directory or in their home directory. That's what I do. But then, when you come back a week later, how do you know that this file is garbage? The best way is to have a naming convention.
Many people use tmp, tmp2, tmp3 as names. I find those visually too like real filenames and longer to type than I want. The names I use are 0, 1, 2, 3. They are short, distinctive, and unreasonable as permanent filenames.
You can find the litter you left behind with: locate -r '/[0-9]$' You will notice that the system does have some files that match too so you cannot blindly delete all matches.
To me, it is obvious. But I didn't think of it. I copied this from Chris Sturgess almost 30 years ago.
Well on my current Debian system I see a neat variable that looks like this: XDG_RUNTIME_DIR=/run/user/1000 That is a tmpfs (ram disk) and each user gets their own. mount shows: tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=404280k,mode=700,uid=1000,gid=1000) -- Len Sorensen

On 17 April 2018 at 11:43, D. Hugh Redelmeier via talk <talk@gtalug.org> wrote:
Putting them in /tmp means that they will automatically be discarded on reboot -- kind of handy. But it means that they are public: they are in a space shared with all other users (if you have other users).
What's wrong with putting them in /tmp but making them read/write only by your user account? Or better yet, also put them in a subdirectory that only you have access privileges to. -- Scott
participants (6)
-
D. Hugh Redelmeier
-
Giles Orr
-
John Sellens
-
lsorense@csclub.uwaterloo.ca
-
Scott Allen
-
Val Kulkov