double check remove on a wildcard
I accidentally removed a bunch of files I wasn't supposed to. I would like to implement some kind of safety net in the future to protect my files.
I was hoping that any time I type rm * into the terminal it would ask me if I'm sure I want to delete all files. Any tips?
wildcards rm
add a comment |
I accidentally removed a bunch of files I wasn't supposed to. I would like to implement some kind of safety net in the future to protect my files.
I was hoping that any time I type rm * into the terminal it would ask me if I'm sure I want to delete all files. Any tips?
wildcards rm
4
Read the man page forrm. You answer lies within.
– glenn jackman
Nov 12 at 18:19
6
Another suggestion: do not create an alias forrmwith the "safety option" -- you'll get used to the safety new, and then get burned when you move to another system that does not have that alias.
– glenn jackman
Nov 12 at 18:21
We just went through something similar with cp; amusingly (to me), the POSIX page for rm says, in part, "CONSEQUENCES OF ERRORS: Default."
– Jeff Schaller
Nov 12 at 18:29
add a comment |
I accidentally removed a bunch of files I wasn't supposed to. I would like to implement some kind of safety net in the future to protect my files.
I was hoping that any time I type rm * into the terminal it would ask me if I'm sure I want to delete all files. Any tips?
wildcards rm
I accidentally removed a bunch of files I wasn't supposed to. I would like to implement some kind of safety net in the future to protect my files.
I was hoping that any time I type rm * into the terminal it would ask me if I'm sure I want to delete all files. Any tips?
wildcards rm
wildcards rm
edited 13 hours ago
Rui F Ribeiro
38.8k1479128
38.8k1479128
asked Nov 12 at 18:14
Ryan Schubert
82
82
4
Read the man page forrm. You answer lies within.
– glenn jackman
Nov 12 at 18:19
6
Another suggestion: do not create an alias forrmwith the "safety option" -- you'll get used to the safety new, and then get burned when you move to another system that does not have that alias.
– glenn jackman
Nov 12 at 18:21
We just went through something similar with cp; amusingly (to me), the POSIX page for rm says, in part, "CONSEQUENCES OF ERRORS: Default."
– Jeff Schaller
Nov 12 at 18:29
add a comment |
4
Read the man page forrm. You answer lies within.
– glenn jackman
Nov 12 at 18:19
6
Another suggestion: do not create an alias forrmwith the "safety option" -- you'll get used to the safety new, and then get burned when you move to another system that does not have that alias.
– glenn jackman
Nov 12 at 18:21
We just went through something similar with cp; amusingly (to me), the POSIX page for rm says, in part, "CONSEQUENCES OF ERRORS: Default."
– Jeff Schaller
Nov 12 at 18:29
4
4
Read the man page for
rm. You answer lies within.– glenn jackman
Nov 12 at 18:19
Read the man page for
rm. You answer lies within.– glenn jackman
Nov 12 at 18:19
6
6
Another suggestion: do not create an alias for
rm with the "safety option" -- you'll get used to the safety new, and then get burned when you move to another system that does not have that alias.– glenn jackman
Nov 12 at 18:21
Another suggestion: do not create an alias for
rm with the "safety option" -- you'll get used to the safety new, and then get burned when you move to another system that does not have that alias.– glenn jackman
Nov 12 at 18:21
We just went through something similar with cp; amusingly (to me), the POSIX page for rm says, in part, "CONSEQUENCES OF ERRORS: Default."
– Jeff Schaller
Nov 12 at 18:29
We just went through something similar with cp; amusingly (to me), the POSIX page for rm says, in part, "CONSEQUENCES OF ERRORS: Default."
– Jeff Schaller
Nov 12 at 18:29
add a comment |
4 Answers
4
active
oldest
votes
Typing
rm *
should, by itself, set off alarm bells. This is a perfectly legal command to want to execute from time to time, but before doing so, you should check that you're in the right directory (maybe make the current directory part of your prompt?), that * will match the filenames of the files that you want to remove (you can check this with echo *), etc. etc.
There is an -i option to rm that you could use, which would ask for confirmation before removing a file. Creating an alias for rm to rm -i has over time proven that people will start to rely on this option to catch stupid mistakes, which would lead to nasty surprises in situations where the alias happens to not be set. It would therefore be better to develop a habit of thinking before pressing Enter, especially when running things that deletes files (or overwrite files, or truncate files).
Either that, or (and!) keep readily available hourly backups of everything that you don't ever want to loose. I recommend restic or borgbackup for off-site backups.
add a comment |
Get in the habit of using 'rm -i' instead.
Avoid using an open * unless you have to.
add a comment |
If using the tcsh shell, you can set the rmstar variable for that:
tcsh> set rmstar
tcsh> touch file
tcsh> rm *
Do you really want to delete all files? [N/y]
That however doesn't apply to
tcsh> rm ./*
tcsh>
Too bad, as rm ./* is really what you should be doing. rm * is unsafe because it doesn't work if there are files whose name starts with -.
zsh adapted and improved that tcsh feature and made it the default:
zsh$ rm ./*
zsh: sure you want to delete the only file in /home/chazelas/. [yn]?
zsh$ rm foo /*
zsh: sure you want to delete all 33 files in / [yn]?
(note that it happens before rm is even involved. Above foo is not deleted until you press y).
You can disable it with
set -o rmstarsilent
There's even a rmstarwait option for the trigger-happy users:
RM_STAR_WAIT:
If querying the user before executing 'rm ' or 'rm path/', first
wait ten seconds and ignore anything typed in that time. This
avoids the problem of reflexively answering 'yes' to the query when
one didn't really mean it. The wait and query can always be
avoided by expanding the '*' in ZLE (with tab).
Another way to bypass that check is to use rm ./**.
add a comment |
Best practice, and what I've been doing for years, is to activate autocompletion in my shell and just pressing tab (or whatever key you map this function to) so you can see the files that * will expand to once you press the key.
Also, I added an rm alias like this:
alias rm='nocorrect rm -Iv'
nocorrect basically takes care of ignoring the sometimes redundant
autocorrection message when typing rm in my shell, Zsh. Let's say you
have a file called rmi in your current directory, or there is a
binary called rmi, nocorrect will take care of this.-I is for a prompt when rm is deleting more than 3 files or when removing recursively, ie. directories.
-v for verbose, is just to see what rm is deleting; I might just want to cancel this operation (Ctrl-c) if for some reason I'm deleting
the wrong files. Rarely used but nice to see the process.
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
});
}
});
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%2f481311%2fdouble-check-remove-on-a-wildcard%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
Typing
rm *
should, by itself, set off alarm bells. This is a perfectly legal command to want to execute from time to time, but before doing so, you should check that you're in the right directory (maybe make the current directory part of your prompt?), that * will match the filenames of the files that you want to remove (you can check this with echo *), etc. etc.
There is an -i option to rm that you could use, which would ask for confirmation before removing a file. Creating an alias for rm to rm -i has over time proven that people will start to rely on this option to catch stupid mistakes, which would lead to nasty surprises in situations where the alias happens to not be set. It would therefore be better to develop a habit of thinking before pressing Enter, especially when running things that deletes files (or overwrite files, or truncate files).
Either that, or (and!) keep readily available hourly backups of everything that you don't ever want to loose. I recommend restic or borgbackup for off-site backups.
add a comment |
Typing
rm *
should, by itself, set off alarm bells. This is a perfectly legal command to want to execute from time to time, but before doing so, you should check that you're in the right directory (maybe make the current directory part of your prompt?), that * will match the filenames of the files that you want to remove (you can check this with echo *), etc. etc.
There is an -i option to rm that you could use, which would ask for confirmation before removing a file. Creating an alias for rm to rm -i has over time proven that people will start to rely on this option to catch stupid mistakes, which would lead to nasty surprises in situations where the alias happens to not be set. It would therefore be better to develop a habit of thinking before pressing Enter, especially when running things that deletes files (or overwrite files, or truncate files).
Either that, or (and!) keep readily available hourly backups of everything that you don't ever want to loose. I recommend restic or borgbackup for off-site backups.
add a comment |
Typing
rm *
should, by itself, set off alarm bells. This is a perfectly legal command to want to execute from time to time, but before doing so, you should check that you're in the right directory (maybe make the current directory part of your prompt?), that * will match the filenames of the files that you want to remove (you can check this with echo *), etc. etc.
There is an -i option to rm that you could use, which would ask for confirmation before removing a file. Creating an alias for rm to rm -i has over time proven that people will start to rely on this option to catch stupid mistakes, which would lead to nasty surprises in situations where the alias happens to not be set. It would therefore be better to develop a habit of thinking before pressing Enter, especially when running things that deletes files (or overwrite files, or truncate files).
Either that, or (and!) keep readily available hourly backups of everything that you don't ever want to loose. I recommend restic or borgbackup for off-site backups.
Typing
rm *
should, by itself, set off alarm bells. This is a perfectly legal command to want to execute from time to time, but before doing so, you should check that you're in the right directory (maybe make the current directory part of your prompt?), that * will match the filenames of the files that you want to remove (you can check this with echo *), etc. etc.
There is an -i option to rm that you could use, which would ask for confirmation before removing a file. Creating an alias for rm to rm -i has over time proven that people will start to rely on this option to catch stupid mistakes, which would lead to nasty surprises in situations where the alias happens to not be set. It would therefore be better to develop a habit of thinking before pressing Enter, especially when running things that deletes files (or overwrite files, or truncate files).
Either that, or (and!) keep readily available hourly backups of everything that you don't ever want to loose. I recommend restic or borgbackup for off-site backups.
edited Nov 12 at 20:36
answered Nov 12 at 18:27
Kusalananda
121k16228372
121k16228372
add a comment |
add a comment |
Get in the habit of using 'rm -i' instead.
Avoid using an open * unless you have to.
add a comment |
Get in the habit of using 'rm -i' instead.
Avoid using an open * unless you have to.
add a comment |
Get in the habit of using 'rm -i' instead.
Avoid using an open * unless you have to.
Get in the habit of using 'rm -i' instead.
Avoid using an open * unless you have to.
answered Nov 12 at 18:20
kevlinux
1642
1642
add a comment |
add a comment |
If using the tcsh shell, you can set the rmstar variable for that:
tcsh> set rmstar
tcsh> touch file
tcsh> rm *
Do you really want to delete all files? [N/y]
That however doesn't apply to
tcsh> rm ./*
tcsh>
Too bad, as rm ./* is really what you should be doing. rm * is unsafe because it doesn't work if there are files whose name starts with -.
zsh adapted and improved that tcsh feature and made it the default:
zsh$ rm ./*
zsh: sure you want to delete the only file in /home/chazelas/. [yn]?
zsh$ rm foo /*
zsh: sure you want to delete all 33 files in / [yn]?
(note that it happens before rm is even involved. Above foo is not deleted until you press y).
You can disable it with
set -o rmstarsilent
There's even a rmstarwait option for the trigger-happy users:
RM_STAR_WAIT:
If querying the user before executing 'rm ' or 'rm path/', first
wait ten seconds and ignore anything typed in that time. This
avoids the problem of reflexively answering 'yes' to the query when
one didn't really mean it. The wait and query can always be
avoided by expanding the '*' in ZLE (with tab).
Another way to bypass that check is to use rm ./**.
add a comment |
If using the tcsh shell, you can set the rmstar variable for that:
tcsh> set rmstar
tcsh> touch file
tcsh> rm *
Do you really want to delete all files? [N/y]
That however doesn't apply to
tcsh> rm ./*
tcsh>
Too bad, as rm ./* is really what you should be doing. rm * is unsafe because it doesn't work if there are files whose name starts with -.
zsh adapted and improved that tcsh feature and made it the default:
zsh$ rm ./*
zsh: sure you want to delete the only file in /home/chazelas/. [yn]?
zsh$ rm foo /*
zsh: sure you want to delete all 33 files in / [yn]?
(note that it happens before rm is even involved. Above foo is not deleted until you press y).
You can disable it with
set -o rmstarsilent
There's even a rmstarwait option for the trigger-happy users:
RM_STAR_WAIT:
If querying the user before executing 'rm ' or 'rm path/', first
wait ten seconds and ignore anything typed in that time. This
avoids the problem of reflexively answering 'yes' to the query when
one didn't really mean it. The wait and query can always be
avoided by expanding the '*' in ZLE (with tab).
Another way to bypass that check is to use rm ./**.
add a comment |
If using the tcsh shell, you can set the rmstar variable for that:
tcsh> set rmstar
tcsh> touch file
tcsh> rm *
Do you really want to delete all files? [N/y]
That however doesn't apply to
tcsh> rm ./*
tcsh>
Too bad, as rm ./* is really what you should be doing. rm * is unsafe because it doesn't work if there are files whose name starts with -.
zsh adapted and improved that tcsh feature and made it the default:
zsh$ rm ./*
zsh: sure you want to delete the only file in /home/chazelas/. [yn]?
zsh$ rm foo /*
zsh: sure you want to delete all 33 files in / [yn]?
(note that it happens before rm is even involved. Above foo is not deleted until you press y).
You can disable it with
set -o rmstarsilent
There's even a rmstarwait option for the trigger-happy users:
RM_STAR_WAIT:
If querying the user before executing 'rm ' or 'rm path/', first
wait ten seconds and ignore anything typed in that time. This
avoids the problem of reflexively answering 'yes' to the query when
one didn't really mean it. The wait and query can always be
avoided by expanding the '*' in ZLE (with tab).
Another way to bypass that check is to use rm ./**.
If using the tcsh shell, you can set the rmstar variable for that:
tcsh> set rmstar
tcsh> touch file
tcsh> rm *
Do you really want to delete all files? [N/y]
That however doesn't apply to
tcsh> rm ./*
tcsh>
Too bad, as rm ./* is really what you should be doing. rm * is unsafe because it doesn't work if there are files whose name starts with -.
zsh adapted and improved that tcsh feature and made it the default:
zsh$ rm ./*
zsh: sure you want to delete the only file in /home/chazelas/. [yn]?
zsh$ rm foo /*
zsh: sure you want to delete all 33 files in / [yn]?
(note that it happens before rm is even involved. Above foo is not deleted until you press y).
You can disable it with
set -o rmstarsilent
There's even a rmstarwait option for the trigger-happy users:
RM_STAR_WAIT:
If querying the user before executing 'rm ' or 'rm path/', first
wait ten seconds and ignore anything typed in that time. This
avoids the problem of reflexively answering 'yes' to the query when
one didn't really mean it. The wait and query can always be
avoided by expanding the '*' in ZLE (with tab).
Another way to bypass that check is to use rm ./**.
answered Nov 12 at 20:17
Stéphane Chazelas
298k54563910
298k54563910
add a comment |
add a comment |
Best practice, and what I've been doing for years, is to activate autocompletion in my shell and just pressing tab (or whatever key you map this function to) so you can see the files that * will expand to once you press the key.
Also, I added an rm alias like this:
alias rm='nocorrect rm -Iv'
nocorrect basically takes care of ignoring the sometimes redundant
autocorrection message when typing rm in my shell, Zsh. Let's say you
have a file called rmi in your current directory, or there is a
binary called rmi, nocorrect will take care of this.-I is for a prompt when rm is deleting more than 3 files or when removing recursively, ie. directories.
-v for verbose, is just to see what rm is deleting; I might just want to cancel this operation (Ctrl-c) if for some reason I'm deleting
the wrong files. Rarely used but nice to see the process.
add a comment |
Best practice, and what I've been doing for years, is to activate autocompletion in my shell and just pressing tab (or whatever key you map this function to) so you can see the files that * will expand to once you press the key.
Also, I added an rm alias like this:
alias rm='nocorrect rm -Iv'
nocorrect basically takes care of ignoring the sometimes redundant
autocorrection message when typing rm in my shell, Zsh. Let's say you
have a file called rmi in your current directory, or there is a
binary called rmi, nocorrect will take care of this.-I is for a prompt when rm is deleting more than 3 files or when removing recursively, ie. directories.
-v for verbose, is just to see what rm is deleting; I might just want to cancel this operation (Ctrl-c) if for some reason I'm deleting
the wrong files. Rarely used but nice to see the process.
add a comment |
Best practice, and what I've been doing for years, is to activate autocompletion in my shell and just pressing tab (or whatever key you map this function to) so you can see the files that * will expand to once you press the key.
Also, I added an rm alias like this:
alias rm='nocorrect rm -Iv'
nocorrect basically takes care of ignoring the sometimes redundant
autocorrection message when typing rm in my shell, Zsh. Let's say you
have a file called rmi in your current directory, or there is a
binary called rmi, nocorrect will take care of this.-I is for a prompt when rm is deleting more than 3 files or when removing recursively, ie. directories.
-v for verbose, is just to see what rm is deleting; I might just want to cancel this operation (Ctrl-c) if for some reason I'm deleting
the wrong files. Rarely used but nice to see the process.
Best practice, and what I've been doing for years, is to activate autocompletion in my shell and just pressing tab (or whatever key you map this function to) so you can see the files that * will expand to once you press the key.
Also, I added an rm alias like this:
alias rm='nocorrect rm -Iv'
nocorrect basically takes care of ignoring the sometimes redundant
autocorrection message when typing rm in my shell, Zsh. Let's say you
have a file called rmi in your current directory, or there is a
binary called rmi, nocorrect will take care of this.-I is for a prompt when rm is deleting more than 3 files or when removing recursively, ie. directories.
-v for verbose, is just to see what rm is deleting; I might just want to cancel this operation (Ctrl-c) if for some reason I'm deleting
the wrong files. Rarely used but nice to see the process.
answered Nov 12 at 19:55
ramonovski
32217
32217
add a comment |
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f481311%2fdouble-check-remove-on-a-wildcard%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
4
Read the man page for
rm. You answer lies within.– glenn jackman
Nov 12 at 18:19
6
Another suggestion: do not create an alias for
rmwith the "safety option" -- you'll get used to the safety new, and then get burned when you move to another system that does not have that alias.– glenn jackman
Nov 12 at 18:21
We just went through something similar with cp; amusingly (to me), the POSIX page for rm says, in part, "CONSEQUENCES OF ERRORS: Default."
– Jeff Schaller
Nov 12 at 18:29