文件防止误删除_如何防止误删除文件?

文件防止误删除

文件防止误删除

Every system admin horror is deleting files accidentally especially important and not backup ed configuration files. Here is how can we recover deleted files from Linux systems which is next situation if we skipped this step.

每个系统管理员的恐惧都会意外删除文件,这尤其重要,而不是备份的配置文件。 这是我们如何从Linux系统恢复已删除的文件,如果跳过此步骤,则是下一种情况。

删除文件前询问 (Ask Before Deleting Files)

rm is defacto tool to remove files from Linux system. We can set up a mechanism to ask before deleting files with a simple alias setup like below.

rm是事实上的工具,用于从Linux系统中删除文件。 我们可以设置一种机制,以在删除文件之前使用以下简单的别名设置进行询问。

$ echo 'alias rm=rm -i' >> .bashrc

This will add new alias for rm command with <strong>-i  option.

这将使用<strong>-i选项为rm命令添加新的别名。

登录并使用特权较少的用户/不要始终使用根 (Login and Use Less Privileged User /Do Not Use Root Always)

Using root user makes system administrator more powerful and less problematic but as you guess power without control will create problems. Use a less powerful user with sudo capability which is default in Ubuntu.

使用root用户可以使系统管理员更强大,并且问题更少,但是正如您所猜测的那样,没有控制权就会产生问题。 使用功能较弱的用户使用sudo功能,这在Ubuntu中是默认设置。

更改权限和所有者用户组 (Change Permissions and Owner User Group)

Keep permissions strict so do not give 777 to files as far as it is not needed.

保持严格的权限,以便不要在不需要的文件上提供777。

We can change permission like

我们可以像这样更改许可

$ chmod 640 config.cfg

添加受保护的属性 (Add Protected Attribute)

Linux provides read-only attribute which can be given by root. This attribute will make the file read-only.

Linux提供了可由root赋予的只读属性。 此属性将文件设为只读。

$ sudo chattr +i pnggrad8rgb.png
LEARN MORE  How To Allow Normal User Run Commands As Root In Linux with sudo Command?
了解更多信息如何使用sudo命令在Linux中以root用户身份允许普通用户运行命令?

翻译自: https://www.poftut.com/prevent-deleting-files-accidentially/

文件防止误删除

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值