Prevent accidental file overwrite

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








up vote
1
down vote

favorite












Is there a way to prevent files to be overwritten, if the file with the same name already exists?

Either it should ask for root password to confirm or simply save it with a new name, like windows does, adding numbers to names.










share|improve this question





















  • Well, you could set the permissions to 400
    – Android Dev
    Mar 14 at 15:29










  • ... or 444. See serverfault.com/questions/648573/…
    – RoVo
    Mar 14 at 15:29










  • you can prevent file from being overwritten but asking for root password or automatic renaming is not available out-of-the-box.
    – Manoj Sawai
    Mar 14 at 15:32














up vote
1
down vote

favorite












Is there a way to prevent files to be overwritten, if the file with the same name already exists?

Either it should ask for root password to confirm or simply save it with a new name, like windows does, adding numbers to names.










share|improve this question





















  • Well, you could set the permissions to 400
    – Android Dev
    Mar 14 at 15:29










  • ... or 444. See serverfault.com/questions/648573/…
    – RoVo
    Mar 14 at 15:29










  • you can prevent file from being overwritten but asking for root password or automatic renaming is not available out-of-the-box.
    – Manoj Sawai
    Mar 14 at 15:32












up vote
1
down vote

favorite









up vote
1
down vote

favorite











Is there a way to prevent files to be overwritten, if the file with the same name already exists?

Either it should ask for root password to confirm or simply save it with a new name, like windows does, adding numbers to names.










share|improve this question













Is there a way to prevent files to be overwritten, if the file with the same name already exists?

Either it should ask for root password to confirm or simply save it with a new name, like windows does, adding numbers to names.







16.04 permissions files filesystem filemanager






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 14 at 15:23









arjun

207111




207111











  • Well, you could set the permissions to 400
    – Android Dev
    Mar 14 at 15:29










  • ... or 444. See serverfault.com/questions/648573/…
    – RoVo
    Mar 14 at 15:29










  • you can prevent file from being overwritten but asking for root password or automatic renaming is not available out-of-the-box.
    – Manoj Sawai
    Mar 14 at 15:32
















  • Well, you could set the permissions to 400
    – Android Dev
    Mar 14 at 15:29










  • ... or 444. See serverfault.com/questions/648573/…
    – RoVo
    Mar 14 at 15:29










  • you can prevent file from being overwritten but asking for root password or automatic renaming is not available out-of-the-box.
    – Manoj Sawai
    Mar 14 at 15:32















Well, you could set the permissions to 400
– Android Dev
Mar 14 at 15:29




Well, you could set the permissions to 400
– Android Dev
Mar 14 at 15:29












... or 444. See serverfault.com/questions/648573/…
– RoVo
Mar 14 at 15:29




... or 444. See serverfault.com/questions/648573/…
– RoVo
Mar 14 at 15:29












you can prevent file from being overwritten but asking for root password or automatic renaming is not available out-of-the-box.
– Manoj Sawai
Mar 14 at 15:32




you can prevent file from being overwritten but asking for root password or automatic renaming is not available out-of-the-box.
– Manoj Sawai
Mar 14 at 15:32










1 Answer
1






active

oldest

votes

















up vote
1
down vote













The best method would be for you to learn to create a copy yourself before editing a file.



That said ...




Is there a way to prevent files to be overwritten




Yes. From command line set the "immutable" attribute (only the admin can remove that option) and nobody will be able to alter the file (edit, remove, move etc.). You do that with ...



sudo -i
password
chattr +i file


(-i to remove it)




Either it should ask for root password




Ubuntu does not have a use able root password.



You can modify a file (even if it's read-only) if you own it and have write access to the directory. See for instance Why can I modify a read-only file? on how to save from vim. It will then complain that you need to take an extra action before you can save it.



Not exactly what you asked but it is a method to get some sort of notification before you overwrite it.




or simply save it with a new name, like windows does, adding numbers to names.




You will need a script for that when doing that on command line. Here are some examples: https://stackoverflow.com/questions/12187859/create-new-file-but-add-number-if-filename-already-exists-in-bash






share|improve this answer






















  • I find myself saving documents from web. Some times i have accidentally overwritten them, if it was already saved or the name was same. That script assumes only single file would be considered. Is there any other way? Can it be automated?
    – arjun
    Mar 14 at 17:55










  • And the chattr command, is it safe to do it system wide for all user files or specific folder? Can it be done?
    – arjun
    Mar 14 at 17:58










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
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: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2faskubuntu.com%2fquestions%2f1014917%2fprevent-accidental-file-overwrite%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
1
down vote













The best method would be for you to learn to create a copy yourself before editing a file.



That said ...




Is there a way to prevent files to be overwritten




Yes. From command line set the "immutable" attribute (only the admin can remove that option) and nobody will be able to alter the file (edit, remove, move etc.). You do that with ...



sudo -i
password
chattr +i file


(-i to remove it)




Either it should ask for root password




Ubuntu does not have a use able root password.



You can modify a file (even if it's read-only) if you own it and have write access to the directory. See for instance Why can I modify a read-only file? on how to save from vim. It will then complain that you need to take an extra action before you can save it.



Not exactly what you asked but it is a method to get some sort of notification before you overwrite it.




or simply save it with a new name, like windows does, adding numbers to names.




You will need a script for that when doing that on command line. Here are some examples: https://stackoverflow.com/questions/12187859/create-new-file-but-add-number-if-filename-already-exists-in-bash






share|improve this answer






















  • I find myself saving documents from web. Some times i have accidentally overwritten them, if it was already saved or the name was same. That script assumes only single file would be considered. Is there any other way? Can it be automated?
    – arjun
    Mar 14 at 17:55










  • And the chattr command, is it safe to do it system wide for all user files or specific folder? Can it be done?
    – arjun
    Mar 14 at 17:58














up vote
1
down vote













The best method would be for you to learn to create a copy yourself before editing a file.



That said ...




Is there a way to prevent files to be overwritten




Yes. From command line set the "immutable" attribute (only the admin can remove that option) and nobody will be able to alter the file (edit, remove, move etc.). You do that with ...



sudo -i
password
chattr +i file


(-i to remove it)




Either it should ask for root password




Ubuntu does not have a use able root password.



You can modify a file (even if it's read-only) if you own it and have write access to the directory. See for instance Why can I modify a read-only file? on how to save from vim. It will then complain that you need to take an extra action before you can save it.



Not exactly what you asked but it is a method to get some sort of notification before you overwrite it.




or simply save it with a new name, like windows does, adding numbers to names.




You will need a script for that when doing that on command line. Here are some examples: https://stackoverflow.com/questions/12187859/create-new-file-but-add-number-if-filename-already-exists-in-bash






share|improve this answer






















  • I find myself saving documents from web. Some times i have accidentally overwritten them, if it was already saved or the name was same. That script assumes only single file would be considered. Is there any other way? Can it be automated?
    – arjun
    Mar 14 at 17:55










  • And the chattr command, is it safe to do it system wide for all user files or specific folder? Can it be done?
    – arjun
    Mar 14 at 17:58












up vote
1
down vote










up vote
1
down vote









The best method would be for you to learn to create a copy yourself before editing a file.



That said ...




Is there a way to prevent files to be overwritten




Yes. From command line set the "immutable" attribute (only the admin can remove that option) and nobody will be able to alter the file (edit, remove, move etc.). You do that with ...



sudo -i
password
chattr +i file


(-i to remove it)




Either it should ask for root password




Ubuntu does not have a use able root password.



You can modify a file (even if it's read-only) if you own it and have write access to the directory. See for instance Why can I modify a read-only file? on how to save from vim. It will then complain that you need to take an extra action before you can save it.



Not exactly what you asked but it is a method to get some sort of notification before you overwrite it.




or simply save it with a new name, like windows does, adding numbers to names.




You will need a script for that when doing that on command line. Here are some examples: https://stackoverflow.com/questions/12187859/create-new-file-but-add-number-if-filename-already-exists-in-bash






share|improve this answer














The best method would be for you to learn to create a copy yourself before editing a file.



That said ...




Is there a way to prevent files to be overwritten




Yes. From command line set the "immutable" attribute (only the admin can remove that option) and nobody will be able to alter the file (edit, remove, move etc.). You do that with ...



sudo -i
password
chattr +i file


(-i to remove it)




Either it should ask for root password




Ubuntu does not have a use able root password.



You can modify a file (even if it's read-only) if you own it and have write access to the directory. See for instance Why can I modify a read-only file? on how to save from vim. It will then complain that you need to take an extra action before you can save it.



Not exactly what you asked but it is a method to get some sort of notification before you overwrite it.




or simply save it with a new name, like windows does, adding numbers to names.




You will need a script for that when doing that on command line. Here are some examples: https://stackoverflow.com/questions/12187859/create-new-file-but-add-number-if-filename-already-exists-in-bash







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 14 at 15:41

























answered Mar 14 at 15:36









Rinzwind

197k25378510




197k25378510











  • I find myself saving documents from web. Some times i have accidentally overwritten them, if it was already saved or the name was same. That script assumes only single file would be considered. Is there any other way? Can it be automated?
    – arjun
    Mar 14 at 17:55










  • And the chattr command, is it safe to do it system wide for all user files or specific folder? Can it be done?
    – arjun
    Mar 14 at 17:58
















  • I find myself saving documents from web. Some times i have accidentally overwritten them, if it was already saved or the name was same. That script assumes only single file would be considered. Is there any other way? Can it be automated?
    – arjun
    Mar 14 at 17:55










  • And the chattr command, is it safe to do it system wide for all user files or specific folder? Can it be done?
    – arjun
    Mar 14 at 17:58















I find myself saving documents from web. Some times i have accidentally overwritten them, if it was already saved or the name was same. That script assumes only single file would be considered. Is there any other way? Can it be automated?
– arjun
Mar 14 at 17:55




I find myself saving documents from web. Some times i have accidentally overwritten them, if it was already saved or the name was same. That script assumes only single file would be considered. Is there any other way? Can it be automated?
– arjun
Mar 14 at 17:55












And the chattr command, is it safe to do it system wide for all user files or specific folder? Can it be done?
– arjun
Mar 14 at 17:58




And the chattr command, is it safe to do it system wide for all user files or specific folder? Can it be done?
– arjun
Mar 14 at 17:58

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1014917%2fprevent-accidental-file-overwrite%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

pylint3 and pip3 broken

Missing snmpget and snmpwalk

How to enroll fingerprints to Ubuntu 17.10 with VFS491