Prevent a directory in /tmp from being deletedParitioning Scheme: Arch Linux server & laptopWhat are...
declaring a variable twice in IIFE
A Journey Through Space and Time
How is this relation reflexive?
Can I make popcorn with any corn?
New order #4: World
How to make payment on the internet without leaving a money trail?
Why is the design of haulage companies so “special”?
What Brexit solution does the DUP want?
Possibly bubble sort algorithm
Why is "Reports" in sentence down without "The"
How to type dʒ symbol (IPA) on Mac?
How does one intimidate enemies without having the capacity for violence?
Patience, young "Padovan"
Japan - Plan around max visa duration
A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?
Is there a familial term for apples and pears?
DOS, create pipe for stdin/stdout of command.com(or 4dos.com) in C or Batch?
"which" command doesn't work / path of Safari?
Why don't electron-positron collisions release infinite energy?
What defenses are there against being summoned by the Gate spell?
Why are only specific transaction types accepted into the mempool?
How long does it take to type this?
Set-theoretical foundations of Mathematics with only bounded quantifiers
How can bays and straits be determined in a procedurally generated map?
Prevent a directory in /tmp from being deleted
Paritioning Scheme: Arch Linux server & laptopWhat are correct permissions for /tmp ? I unintentionally set it all public recursivelyWhat can go wrong if /var/tmp is on a temporary filesystem?Small RAM-based /tmpDo Links to /tmp files get deleted?Moving /tmp folder to different location. Problems with /tmp not being emptiedFolder in /tmp won't delete despite the computer being restartedis /tmp guaranteed to exist?tmp directory for development that gets cleared regularly?When are files from /tmp deleted?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I often use the /tmp
directory on my Linux machine for storing temporary files (e.g. PDFs from a site that wants me to download it first etc.) and I often create a directory with my username. But at every startup it (including all files) gets deleted. Now I know I can put it in /var/tmp
, but I want all its contents to be deleted, but for the directory itself to be kept.
So:
tmp
|- me # this should stay
| |- foo1 # this should be deleted...
| |- bar1 # ...and this as well
|- other stuff...
Is there any way to do this? Maybe with permissions or with a special configuration?
tmp
New contributor
add a comment |
I often use the /tmp
directory on my Linux machine for storing temporary files (e.g. PDFs from a site that wants me to download it first etc.) and I often create a directory with my username. But at every startup it (including all files) gets deleted. Now I know I can put it in /var/tmp
, but I want all its contents to be deleted, but for the directory itself to be kept.
So:
tmp
|- me # this should stay
| |- foo1 # this should be deleted...
| |- bar1 # ...and this as well
|- other stuff...
Is there any way to do this? Maybe with permissions or with a special configuration?
tmp
New contributor
As a workaround, you might put some code into your shell's login files to "test & mkdir" as needed.
– Jeff Schaller♦
12 hours ago
7
If the files are not temporary, don't store them under/tmp
. If you want, create a$HOME/tmp
directory and store them there instead.
– Kusalananda♦
12 hours ago
add a comment |
I often use the /tmp
directory on my Linux machine for storing temporary files (e.g. PDFs from a site that wants me to download it first etc.) and I often create a directory with my username. But at every startup it (including all files) gets deleted. Now I know I can put it in /var/tmp
, but I want all its contents to be deleted, but for the directory itself to be kept.
So:
tmp
|- me # this should stay
| |- foo1 # this should be deleted...
| |- bar1 # ...and this as well
|- other stuff...
Is there any way to do this? Maybe with permissions or with a special configuration?
tmp
New contributor
I often use the /tmp
directory on my Linux machine for storing temporary files (e.g. PDFs from a site that wants me to download it first etc.) and I often create a directory with my username. But at every startup it (including all files) gets deleted. Now I know I can put it in /var/tmp
, but I want all its contents to be deleted, but for the directory itself to be kept.
So:
tmp
|- me # this should stay
| |- foo1 # this should be deleted...
| |- bar1 # ...and this as well
|- other stuff...
Is there any way to do this? Maybe with permissions or with a special configuration?
tmp
tmp
New contributor
New contributor
edited 10 hours ago
ctrl-alt-delor
12.4k52661
12.4k52661
New contributor
asked 12 hours ago
Linux4winLinux4win
362
362
New contributor
New contributor
As a workaround, you might put some code into your shell's login files to "test & mkdir" as needed.
– Jeff Schaller♦
12 hours ago
7
If the files are not temporary, don't store them under/tmp
. If you want, create a$HOME/tmp
directory and store them there instead.
– Kusalananda♦
12 hours ago
add a comment |
As a workaround, you might put some code into your shell's login files to "test & mkdir" as needed.
– Jeff Schaller♦
12 hours ago
7
If the files are not temporary, don't store them under/tmp
. If you want, create a$HOME/tmp
directory and store them there instead.
– Kusalananda♦
12 hours ago
As a workaround, you might put some code into your shell's login files to "test & mkdir" as needed.
– Jeff Schaller♦
12 hours ago
As a workaround, you might put some code into your shell's login files to "test & mkdir" as needed.
– Jeff Schaller♦
12 hours ago
7
7
If the files are not temporary, don't store them under
/tmp
. If you want, create a $HOME/tmp
directory and store them there instead.– Kusalananda♦
12 hours ago
If the files are not temporary, don't store them under
/tmp
. If you want, create a $HOME/tmp
directory and store them there instead.– Kusalananda♦
12 hours ago
add a comment |
4 Answers
4
active
oldest
votes
I use pam-tmpdir
for this: it creates a user-private temporary directory at login. To set it up, add
session optional pam_tmpdir.so
to the appropriate PAM services; on a Debian-based system, installing the libpam-tmpdir
package will offer to do this for you, or you can add the line to /etc/pam.d/common-session
. The next time you log in, you’ll find a directory under /tmp/user
with your user id, and TMP
and TMPDIR
set appropriately.
4
Could you explain what the appropriate PAM services are and how the line can be added to them? What files should be edited?
– terdon♦
11 hours ago
add a comment |
One solution would be to use a @reboot
cron job:
@reboot mkdir -p "/tmp/$USER"
Adding this to your crontab with crontab -e
would make it execute whenever the machine boots up.
Or, use
mkdir -p "/tmp/$USER"
in your shell's startup file.
In either case, you may also want to use
TMPDIR=/tmp/$USER
export TMPDIR
in your shell's startup file if you want to use that directory as the default temporary directory.
add a comment |
As pointed out in the comments, /tmp
is for files that are transient and won't be missed if they're deleted. If you're in the middle of something and the machine reboots, anything you've written there will disappear and you'll have to start over, which means those files might not have been so temporary after all.
I maintained a temporary directory in my home directory for many years starting when a gigabyte was a lot of space and found that it required periodic grooming to get rid of files that had become old and crufty. Most of the time what I had left after that process was less than a couple of weeks old, so I now clean it up with a cron job that runs once daily:
find $HOME/tmp -depth -mtime +30 -print0 | xargs -0 -r rm -rf
Anything I download or create as semi-temporary goes there and the system cleans up anything I leave behind. Anything that needs a permanent home gets one long before the cron job gets rid of it.
mkdir a a/b; touch a/b/c
. Now wait until your 30 days has expired. As you deletec
it'll updateb
, which will mean it has to wait for a further 30 days. Likewise witha
when you deleteb
. Secondly, if you create files inb
but don't toucha
for 30 days, thea
directory will get hit withrm -rf
and wipe out your recent files underb
.
– roaima
6 hours ago
find "$HOME"/tmp -mtime +30 -type f -delete; find "$HOME/tmp" -depth -mmin +60 -type d -exec rmdir {} + 2>/dev/null
works for me
– roaima
6 hours ago
add a comment |
If you're running no a system with systemd and it uses systemd-tmpfiles to manage the cleanup, then you should configure the directory using that system.
Here's a full documentation. You can likely achieve what you want by creating /etc/tmpfiles.d/something.conf
with contents like:
d /tmp/your_username 0750 your_user your_group - -
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Linux4win is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f511029%2fprevent-a-directory-in-tmp-from-being-deleted%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
I use pam-tmpdir
for this: it creates a user-private temporary directory at login. To set it up, add
session optional pam_tmpdir.so
to the appropriate PAM services; on a Debian-based system, installing the libpam-tmpdir
package will offer to do this for you, or you can add the line to /etc/pam.d/common-session
. The next time you log in, you’ll find a directory under /tmp/user
with your user id, and TMP
and TMPDIR
set appropriately.
4
Could you explain what the appropriate PAM services are and how the line can be added to them? What files should be edited?
– terdon♦
11 hours ago
add a comment |
I use pam-tmpdir
for this: it creates a user-private temporary directory at login. To set it up, add
session optional pam_tmpdir.so
to the appropriate PAM services; on a Debian-based system, installing the libpam-tmpdir
package will offer to do this for you, or you can add the line to /etc/pam.d/common-session
. The next time you log in, you’ll find a directory under /tmp/user
with your user id, and TMP
and TMPDIR
set appropriately.
4
Could you explain what the appropriate PAM services are and how the line can be added to them? What files should be edited?
– terdon♦
11 hours ago
add a comment |
I use pam-tmpdir
for this: it creates a user-private temporary directory at login. To set it up, add
session optional pam_tmpdir.so
to the appropriate PAM services; on a Debian-based system, installing the libpam-tmpdir
package will offer to do this for you, or you can add the line to /etc/pam.d/common-session
. The next time you log in, you’ll find a directory under /tmp/user
with your user id, and TMP
and TMPDIR
set appropriately.
I use pam-tmpdir
for this: it creates a user-private temporary directory at login. To set it up, add
session optional pam_tmpdir.so
to the appropriate PAM services; on a Debian-based system, installing the libpam-tmpdir
package will offer to do this for you, or you can add the line to /etc/pam.d/common-session
. The next time you log in, you’ll find a directory under /tmp/user
with your user id, and TMP
and TMPDIR
set appropriately.
edited 8 hours ago
answered 11 hours ago
Stephen KittStephen Kitt
180k25409487
180k25409487
4
Could you explain what the appropriate PAM services are and how the line can be added to them? What files should be edited?
– terdon♦
11 hours ago
add a comment |
4
Could you explain what the appropriate PAM services are and how the line can be added to them? What files should be edited?
– terdon♦
11 hours ago
4
4
Could you explain what the appropriate PAM services are and how the line can be added to them? What files should be edited?
– terdon♦
11 hours ago
Could you explain what the appropriate PAM services are and how the line can be added to them? What files should be edited?
– terdon♦
11 hours ago
add a comment |
One solution would be to use a @reboot
cron job:
@reboot mkdir -p "/tmp/$USER"
Adding this to your crontab with crontab -e
would make it execute whenever the machine boots up.
Or, use
mkdir -p "/tmp/$USER"
in your shell's startup file.
In either case, you may also want to use
TMPDIR=/tmp/$USER
export TMPDIR
in your shell's startup file if you want to use that directory as the default temporary directory.
add a comment |
One solution would be to use a @reboot
cron job:
@reboot mkdir -p "/tmp/$USER"
Adding this to your crontab with crontab -e
would make it execute whenever the machine boots up.
Or, use
mkdir -p "/tmp/$USER"
in your shell's startup file.
In either case, you may also want to use
TMPDIR=/tmp/$USER
export TMPDIR
in your shell's startup file if you want to use that directory as the default temporary directory.
add a comment |
One solution would be to use a @reboot
cron job:
@reboot mkdir -p "/tmp/$USER"
Adding this to your crontab with crontab -e
would make it execute whenever the machine boots up.
Or, use
mkdir -p "/tmp/$USER"
in your shell's startup file.
In either case, you may also want to use
TMPDIR=/tmp/$USER
export TMPDIR
in your shell's startup file if you want to use that directory as the default temporary directory.
One solution would be to use a @reboot
cron job:
@reboot mkdir -p "/tmp/$USER"
Adding this to your crontab with crontab -e
would make it execute whenever the machine boots up.
Or, use
mkdir -p "/tmp/$USER"
in your shell's startup file.
In either case, you may also want to use
TMPDIR=/tmp/$USER
export TMPDIR
in your shell's startup file if you want to use that directory as the default temporary directory.
answered 11 hours ago
Kusalananda♦Kusalananda
140k17261435
140k17261435
add a comment |
add a comment |
As pointed out in the comments, /tmp
is for files that are transient and won't be missed if they're deleted. If you're in the middle of something and the machine reboots, anything you've written there will disappear and you'll have to start over, which means those files might not have been so temporary after all.
I maintained a temporary directory in my home directory for many years starting when a gigabyte was a lot of space and found that it required periodic grooming to get rid of files that had become old and crufty. Most of the time what I had left after that process was less than a couple of weeks old, so I now clean it up with a cron job that runs once daily:
find $HOME/tmp -depth -mtime +30 -print0 | xargs -0 -r rm -rf
Anything I download or create as semi-temporary goes there and the system cleans up anything I leave behind. Anything that needs a permanent home gets one long before the cron job gets rid of it.
mkdir a a/b; touch a/b/c
. Now wait until your 30 days has expired. As you deletec
it'll updateb
, which will mean it has to wait for a further 30 days. Likewise witha
when you deleteb
. Secondly, if you create files inb
but don't toucha
for 30 days, thea
directory will get hit withrm -rf
and wipe out your recent files underb
.
– roaima
6 hours ago
find "$HOME"/tmp -mtime +30 -type f -delete; find "$HOME/tmp" -depth -mmin +60 -type d -exec rmdir {} + 2>/dev/null
works for me
– roaima
6 hours ago
add a comment |
As pointed out in the comments, /tmp
is for files that are transient and won't be missed if they're deleted. If you're in the middle of something and the machine reboots, anything you've written there will disappear and you'll have to start over, which means those files might not have been so temporary after all.
I maintained a temporary directory in my home directory for many years starting when a gigabyte was a lot of space and found that it required periodic grooming to get rid of files that had become old and crufty. Most of the time what I had left after that process was less than a couple of weeks old, so I now clean it up with a cron job that runs once daily:
find $HOME/tmp -depth -mtime +30 -print0 | xargs -0 -r rm -rf
Anything I download or create as semi-temporary goes there and the system cleans up anything I leave behind. Anything that needs a permanent home gets one long before the cron job gets rid of it.
mkdir a a/b; touch a/b/c
. Now wait until your 30 days has expired. As you deletec
it'll updateb
, which will mean it has to wait for a further 30 days. Likewise witha
when you deleteb
. Secondly, if you create files inb
but don't toucha
for 30 days, thea
directory will get hit withrm -rf
and wipe out your recent files underb
.
– roaima
6 hours ago
find "$HOME"/tmp -mtime +30 -type f -delete; find "$HOME/tmp" -depth -mmin +60 -type d -exec rmdir {} + 2>/dev/null
works for me
– roaima
6 hours ago
add a comment |
As pointed out in the comments, /tmp
is for files that are transient and won't be missed if they're deleted. If you're in the middle of something and the machine reboots, anything you've written there will disappear and you'll have to start over, which means those files might not have been so temporary after all.
I maintained a temporary directory in my home directory for many years starting when a gigabyte was a lot of space and found that it required periodic grooming to get rid of files that had become old and crufty. Most of the time what I had left after that process was less than a couple of weeks old, so I now clean it up with a cron job that runs once daily:
find $HOME/tmp -depth -mtime +30 -print0 | xargs -0 -r rm -rf
Anything I download or create as semi-temporary goes there and the system cleans up anything I leave behind. Anything that needs a permanent home gets one long before the cron job gets rid of it.
As pointed out in the comments, /tmp
is for files that are transient and won't be missed if they're deleted. If you're in the middle of something and the machine reboots, anything you've written there will disappear and you'll have to start over, which means those files might not have been so temporary after all.
I maintained a temporary directory in my home directory for many years starting when a gigabyte was a lot of space and found that it required periodic grooming to get rid of files that had become old and crufty. Most of the time what I had left after that process was less than a couple of weeks old, so I now clean it up with a cron job that runs once daily:
find $HOME/tmp -depth -mtime +30 -print0 | xargs -0 -r rm -rf
Anything I download or create as semi-temporary goes there and the system cleans up anything I leave behind. Anything that needs a permanent home gets one long before the cron job gets rid of it.
answered 7 hours ago
BlrflBlrfl
31414
31414
mkdir a a/b; touch a/b/c
. Now wait until your 30 days has expired. As you deletec
it'll updateb
, which will mean it has to wait for a further 30 days. Likewise witha
when you deleteb
. Secondly, if you create files inb
but don't toucha
for 30 days, thea
directory will get hit withrm -rf
and wipe out your recent files underb
.
– roaima
6 hours ago
find "$HOME"/tmp -mtime +30 -type f -delete; find "$HOME/tmp" -depth -mmin +60 -type d -exec rmdir {} + 2>/dev/null
works for me
– roaima
6 hours ago
add a comment |
mkdir a a/b; touch a/b/c
. Now wait until your 30 days has expired. As you deletec
it'll updateb
, which will mean it has to wait for a further 30 days. Likewise witha
when you deleteb
. Secondly, if you create files inb
but don't toucha
for 30 days, thea
directory will get hit withrm -rf
and wipe out your recent files underb
.
– roaima
6 hours ago
find "$HOME"/tmp -mtime +30 -type f -delete; find "$HOME/tmp" -depth -mmin +60 -type d -exec rmdir {} + 2>/dev/null
works for me
– roaima
6 hours ago
mkdir a a/b; touch a/b/c
. Now wait until your 30 days has expired. As you delete c
it'll update b
, which will mean it has to wait for a further 30 days. Likewise with a
when you delete b
. Secondly, if you create files in b
but don't touch a
for 30 days, the a
directory will get hit with rm -rf
and wipe out your recent files under b
.– roaima
6 hours ago
mkdir a a/b; touch a/b/c
. Now wait until your 30 days has expired. As you delete c
it'll update b
, which will mean it has to wait for a further 30 days. Likewise with a
when you delete b
. Secondly, if you create files in b
but don't touch a
for 30 days, the a
directory will get hit with rm -rf
and wipe out your recent files under b
.– roaima
6 hours ago
find "$HOME"/tmp -mtime +30 -type f -delete; find "$HOME/tmp" -depth -mmin +60 -type d -exec rmdir {} + 2>/dev/null
works for me– roaima
6 hours ago
find "$HOME"/tmp -mtime +30 -type f -delete; find "$HOME/tmp" -depth -mmin +60 -type d -exec rmdir {} + 2>/dev/null
works for me– roaima
6 hours ago
add a comment |
If you're running no a system with systemd and it uses systemd-tmpfiles to manage the cleanup, then you should configure the directory using that system.
Here's a full documentation. You can likely achieve what you want by creating /etc/tmpfiles.d/something.conf
with contents like:
d /tmp/your_username 0750 your_user your_group - -
add a comment |
If you're running no a system with systemd and it uses systemd-tmpfiles to manage the cleanup, then you should configure the directory using that system.
Here's a full documentation. You can likely achieve what you want by creating /etc/tmpfiles.d/something.conf
with contents like:
d /tmp/your_username 0750 your_user your_group - -
add a comment |
If you're running no a system with systemd and it uses systemd-tmpfiles to manage the cleanup, then you should configure the directory using that system.
Here's a full documentation. You can likely achieve what you want by creating /etc/tmpfiles.d/something.conf
with contents like:
d /tmp/your_username 0750 your_user your_group - -
If you're running no a system with systemd and it uses systemd-tmpfiles to manage the cleanup, then you should configure the directory using that system.
Here's a full documentation. You can likely achieve what you want by creating /etc/tmpfiles.d/something.conf
with contents like:
d /tmp/your_username 0750 your_user your_group - -
answered 1 hour ago
viraptorviraptor
1927
1927
add a comment |
add a comment |
Linux4win is a new contributor. Be nice, and check out our Code of Conduct.
Linux4win is a new contributor. Be nice, and check out our Code of Conduct.
Linux4win is a new contributor. Be nice, and check out our Code of Conduct.
Linux4win is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f511029%2fprevent-a-directory-in-tmp-from-being-deleted%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
As a workaround, you might put some code into your shell's login files to "test & mkdir" as needed.
– Jeff Schaller♦
12 hours ago
7
If the files are not temporary, don't store them under
/tmp
. If you want, create a$HOME/tmp
directory and store them there instead.– Kusalananda♦
12 hours ago