Interactive rm command

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












When I remove some directories, I often forgot their structure and consequently I don't add the -rf flags when needed. When this happens, rm just returns an error and reminds me that I am trying to delete a directory.



Is there a program that would instead ask whether I want to remove the directory, or remove with root privileges?



rm foo
foo is directory, Want to remove it [Y/n]
foo/bar owned by root, Want to increase privileges [Y/n]






share|improve this question






















  • It doesn't matter who owns foo/bar (as long as foo doesn't have the t bit). To be able to delete it, you only need write access to foo.
    – Stéphane Chazelas
    Oct 30 '17 at 10:29














up vote
0
down vote

favorite












When I remove some directories, I often forgot their structure and consequently I don't add the -rf flags when needed. When this happens, rm just returns an error and reminds me that I am trying to delete a directory.



Is there a program that would instead ask whether I want to remove the directory, or remove with root privileges?



rm foo
foo is directory, Want to remove it [Y/n]
foo/bar owned by root, Want to increase privileges [Y/n]






share|improve this question






















  • It doesn't matter who owns foo/bar (as long as foo doesn't have the t bit). To be able to delete it, you only need write access to foo.
    – Stéphane Chazelas
    Oct 30 '17 at 10:29












up vote
0
down vote

favorite









up vote
0
down vote

favorite











When I remove some directories, I often forgot their structure and consequently I don't add the -rf flags when needed. When this happens, rm just returns an error and reminds me that I am trying to delete a directory.



Is there a program that would instead ask whether I want to remove the directory, or remove with root privileges?



rm foo
foo is directory, Want to remove it [Y/n]
foo/bar owned by root, Want to increase privileges [Y/n]






share|improve this question














When I remove some directories, I often forgot their structure and consequently I don't add the -rf flags when needed. When this happens, rm just returns an error and reminds me that I am trying to delete a directory.



Is there a program that would instead ask whether I want to remove the directory, or remove with root privileges?



rm foo
foo is directory, Want to remove it [Y/n]
foo/bar owned by root, Want to increase privileges [Y/n]








share|improve this question













share|improve this question




share|improve this question








edited Oct 30 '17 at 10:08









kiamlaluno

362220




362220










asked Oct 30 '17 at 9:08









user1685095

282313




282313











  • It doesn't matter who owns foo/bar (as long as foo doesn't have the t bit). To be able to delete it, you only need write access to foo.
    – Stéphane Chazelas
    Oct 30 '17 at 10:29
















  • It doesn't matter who owns foo/bar (as long as foo doesn't have the t bit). To be able to delete it, you only need write access to foo.
    – Stéphane Chazelas
    Oct 30 '17 at 10:29















It doesn't matter who owns foo/bar (as long as foo doesn't have the t bit). To be able to delete it, you only need write access to foo.
– Stéphane Chazelas
Oct 30 '17 at 10:29




It doesn't matter who owns foo/bar (as long as foo doesn't have the t bit). To be able to delete it, you only need write access to foo.
– Stéphane Chazelas
Oct 30 '17 at 10:29










1 Answer
1






active

oldest

votes

















up vote
4
down vote













No, there is not. What you're looking for is the advanced behaviour of a script, which you won't find in UNIX commands as they are designed to do one simple thing and do it well.



You could write a script to automatically tell a file from a directory and hence use the appropriate rm or rmdir (first requirement), but you'd need to run the script with root privileges for it to be able to remove root-owned files (second requirement). In fact, you can't increase privileges in a root script.






share|improve this answer




















  • One could use sudo (or equivalent) in the script (or better, function) to escalate privileges. The issue is dealing with command line flags and command line flag-like file names. You would have to do full processing of the command line to be able to correctly pass on any user-supplied flags to the real rm.
    – Kusalananda
    Oct 30 '17 at 10:13










  • I'm not talking about Unix commands. I'm talking about programs in general. I could easily write one myself even in sh. I just don't want to do that, if someone else already done that.
    – user1685095
    Oct 30 '17 at 12:02











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',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f401371%2finteractive-rm-command%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
4
down vote













No, there is not. What you're looking for is the advanced behaviour of a script, which you won't find in UNIX commands as they are designed to do one simple thing and do it well.



You could write a script to automatically tell a file from a directory and hence use the appropriate rm or rmdir (first requirement), but you'd need to run the script with root privileges for it to be able to remove root-owned files (second requirement). In fact, you can't increase privileges in a root script.






share|improve this answer




















  • One could use sudo (or equivalent) in the script (or better, function) to escalate privileges. The issue is dealing with command line flags and command line flag-like file names. You would have to do full processing of the command line to be able to correctly pass on any user-supplied flags to the real rm.
    – Kusalananda
    Oct 30 '17 at 10:13










  • I'm not talking about Unix commands. I'm talking about programs in general. I could easily write one myself even in sh. I just don't want to do that, if someone else already done that.
    – user1685095
    Oct 30 '17 at 12:02















up vote
4
down vote













No, there is not. What you're looking for is the advanced behaviour of a script, which you won't find in UNIX commands as they are designed to do one simple thing and do it well.



You could write a script to automatically tell a file from a directory and hence use the appropriate rm or rmdir (first requirement), but you'd need to run the script with root privileges for it to be able to remove root-owned files (second requirement). In fact, you can't increase privileges in a root script.






share|improve this answer




















  • One could use sudo (or equivalent) in the script (or better, function) to escalate privileges. The issue is dealing with command line flags and command line flag-like file names. You would have to do full processing of the command line to be able to correctly pass on any user-supplied flags to the real rm.
    – Kusalananda
    Oct 30 '17 at 10:13










  • I'm not talking about Unix commands. I'm talking about programs in general. I could easily write one myself even in sh. I just don't want to do that, if someone else already done that.
    – user1685095
    Oct 30 '17 at 12:02













up vote
4
down vote










up vote
4
down vote









No, there is not. What you're looking for is the advanced behaviour of a script, which you won't find in UNIX commands as they are designed to do one simple thing and do it well.



You could write a script to automatically tell a file from a directory and hence use the appropriate rm or rmdir (first requirement), but you'd need to run the script with root privileges for it to be able to remove root-owned files (second requirement). In fact, you can't increase privileges in a root script.






share|improve this answer












No, there is not. What you're looking for is the advanced behaviour of a script, which you won't find in UNIX commands as they are designed to do one simple thing and do it well.



You could write a script to automatically tell a file from a directory and hence use the appropriate rm or rmdir (first requirement), but you'd need to run the script with root privileges for it to be able to remove root-owned files (second requirement). In fact, you can't increase privileges in a root script.







share|improve this answer












share|improve this answer



share|improve this answer










answered Oct 30 '17 at 9:59









dr01

15.3k114769




15.3k114769











  • One could use sudo (or equivalent) in the script (or better, function) to escalate privileges. The issue is dealing with command line flags and command line flag-like file names. You would have to do full processing of the command line to be able to correctly pass on any user-supplied flags to the real rm.
    – Kusalananda
    Oct 30 '17 at 10:13










  • I'm not talking about Unix commands. I'm talking about programs in general. I could easily write one myself even in sh. I just don't want to do that, if someone else already done that.
    – user1685095
    Oct 30 '17 at 12:02

















  • One could use sudo (or equivalent) in the script (or better, function) to escalate privileges. The issue is dealing with command line flags and command line flag-like file names. You would have to do full processing of the command line to be able to correctly pass on any user-supplied flags to the real rm.
    – Kusalananda
    Oct 30 '17 at 10:13










  • I'm not talking about Unix commands. I'm talking about programs in general. I could easily write one myself even in sh. I just don't want to do that, if someone else already done that.
    – user1685095
    Oct 30 '17 at 12:02
















One could use sudo (or equivalent) in the script (or better, function) to escalate privileges. The issue is dealing with command line flags and command line flag-like file names. You would have to do full processing of the command line to be able to correctly pass on any user-supplied flags to the real rm.
– Kusalananda
Oct 30 '17 at 10:13




One could use sudo (or equivalent) in the script (or better, function) to escalate privileges. The issue is dealing with command line flags and command line flag-like file names. You would have to do full processing of the command line to be able to correctly pass on any user-supplied flags to the real rm.
– Kusalananda
Oct 30 '17 at 10:13












I'm not talking about Unix commands. I'm talking about programs in general. I could easily write one myself even in sh. I just don't want to do that, if someone else already done that.
– user1685095
Oct 30 '17 at 12:02





I'm not talking about Unix commands. I'm talking about programs in general. I could easily write one myself even in sh. I just don't want to do that, if someone else already done that.
– user1685095
Oct 30 '17 at 12:02


















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f401371%2finteractive-rm-command%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Peggy Mitchell

The Forum (Inglewood, California)

Palaiologos