centos文件锁定解锁_解锁后轻松替换锁定的文件

centos文件锁定解锁

centos文件锁定解锁

If you try to update certain Windows files (such as programs or word documents) while they are in use, you get the the standard “access denied, file is in use” error. While the reasoning behind this is obvious, it can be quite annoying if you need to update a small executable which is currently in use by another user. In these situations, you have, among others, the following choices, all of which take up your valuable time:

如果在使用某些Windows文件(例如程序或Word文档)时尝试对其进行更新,则会出现标准的“访问被拒绝,文件正在使用”错误。 尽管背后的原因很明显,但是如果您需要更新另一个用户当前正在使用的小型可执行文件,可能会很烦人。 在这些情况下,您可以选择以下选项,所有这些都会占用您宝贵的时间:

  • Track down and contact the users who are currently using the file, tell them to close out/save their work, etc. and then apply the update.

    跟踪并联系当前正在使用该文件的用户,告诉他们关闭/保存其工作等,然后应用更新。
  • Don’t apply the update immediately and just remember to do it later when users are not in the system.

    不要立即应用此更新,只是记得当用户不在系统中时稍后再进行更新。
  • Schedule some utility to replace it at the next reboot.

    安排一些实用程序以在下次重新启动时替换它。

Well, we have another solution available for you: a script you invoke via the Send To menu which does the following:

好了,我们还有另一种解决方案供您使用:您通过“发送至”菜单调用的脚本执行以下操作:

  1. Tries to delete the old file.

    尝试删除旧文件。
  2. If the old file is locked, the script waits 20 seconds. Go to step 1.

    如果旧文件被锁定,脚本将等待20秒。 转到步骤1。
  3. If the old file is not locked, the old file is replaced with the new file. Go to step 4.

    如果旧文件未锁定,则将旧文件替换为新文件。 转到步骤4。
  4. Optionally log off once the process is done.

    (可选)完成该过程后注销。

This way, you get just get the replace command in motion and the script takes care of the rest. This can help you avoid tracking down users or having to install unnecessary utilities on your system.

这样,您就可以直接使用replace命令,脚本将处理其余的工作。 这可以帮助您避免追查用户或避免在系统上安装不必要的实用程序。

设置和使用 (Setup and Usage)

The script can be placed anywhere on your system. Then all you need to do is create a shortcut to it in your SendTo folder:

该脚本可以放在系统上的任何位置。 然后,您所需要做的就是在SendTo文件夹中为其创建一个快捷方式:

image

To start the replace process, select the old file and new file and then invoke the Send To option by right clicking on the old file/file to replace.

要开始替换过程,请选择旧文件和新文件,然后通过右键单击要替换旧文件/文件来调用“发送到”选项。

image

The script will display exactly what will happen and present you with the option to be logged off once the replace is completed.

该脚本将准确显示将要发生的情况,并为您提供替换完成后注销的选项。

image

The script will continuously try to delete the old file while waiting several seconds in between tries.

该脚本将在尝试之间等待几秒钟的同时不断尝试删除旧文件。

image

All you have to do is get the process running and whenever all your users are out, the file will be replaced.

您所要做的就是使该流程运行,并且只要您的所有用户都在外,该文件就会被替换。

保障措施 (Safeguards)

The script has a couple of built in safeguards:

该脚本有两个内置的防护措​​施:

  • The old file and new file are clearly presented so you know exactly what will happen.

    清楚地显示了旧文件和新文件,因此您确切知道会发生什么。
  • You can close the command window at any time to stop the action (of course, assuming the replace has not been performed already).

    您可以随时关闭命令窗口以停止操作(当然,假设尚未执行替换操作)。
  • The script will ensure you have selected only two files when you invoke the Send To command. If you select, for example, 1 or 3 files you will receive a notice message and nothing will happen.

    该脚本将确保您在调用“发送到”命令时仅选择了两个文件。 例如,如果您选择1或3个文件,您将收到一条通知消息,什么也不会发生。

剧本 (The Script)

@ECHO OFF
TITLE Replace Locked File
ECHO Replace Locked File
ECHO Written by: Jason Faulkner
ECHO SysadminGeek.com
ECHO.
ECHO.

SETLOCAL EnableExtensions

REM Validation.
SET Error=1
IF {%2}=={} (
   ECHO Two files must be selected to run the replace.
   GOTO End
)
IF NOT {%3}=={} (
   ECHO More than 2 files were selected so I am not sure what to do.
   GOTO End
)

SET Error=0
SET OldFile="%~f1"
SET NewFile="%~f2"
SET LogOffWhenDone=0

REM Show what will happen so you have a chance to cancel out.
ECHO Old File: %OldFile%
ECHO ---------
ECHO New File: %NewFile%
ECHO.
ECHO You can cancel replacing the Old File with the New File by closing now.
ECHO.

REM Log off prompt. If you do not want to see this, you can delete these lines.
ECHO Automatically log off once the replace process has completed?
ECHO Enter 'Y' to automatically log off or enter anything else to not.
SET /P LogOffWhenDone=

:DoReplace
DEL /F /Q %OldFile%
IF NOT EXIST %OldFile% (
   MOVE %NewFile% %OldFile%
   ECHO File replaced successfully.
   GOTO End
)
ECHO.
ECHO The Old File is still locked. Waiting a few moments to try again.
TIMEOUT /T 20
GOTO DoReplace

   
:End
IF {%Error%}=={1} (
   ECHO Instructions for use:
   ECHO 1. Select the two files in Windows Explorer.
   ECHO 2. Right click on the Old File and go Send To - Replace Locked File
   ECHO.
   ECHO The file you right clicked on will be replaced with the other selected file.
   ECHO.
   ECHO Stopping without doing anything. Press any key to close.
   TIMEOUT /T 15
)
IF /I {%LogOffWhenDone%}=={Y} (
   ECHO.
   ECHO Option to Log Off when completed was selected.
   ECHO You will be logged off shortly.
   SHUTDOWN /L
)
ENDLOCAL

链接(Links)

Download ReplaceFile Script from SysadminGeek.com

从SysadminGeek.com下载ReplaceFile脚本

翻译自: https://www.howtogeek.com/51138/easily-replace-a-locked-file-once-it-becomes-unlocked/

centos文件锁定解锁

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值