Submitted by on

Home > What Is File Locking?

What Is File Locking?

Share this Page

What Is Locking a File?

File locking is a data management feature that allows only one user or process access to a file at any given time. It restricts other users from changing the file while it is being used by another user or process. This eliminates issues with users or processes making interceding updates on the same files at the same time. IBM introduced the capability for file locking in 1963 as a feature called “exclusive control” for mainframe computers as part of the 360 operating system.

Without file locking, conflicts and overwriting would eliminate the efficiencies gained with online collaboration.

In essence, file locking is a first-come, first-served method for file management in systems with multiple users or processes accessing files. With file locking, when a process or user accesses a file, other users are blocked from being able to access it. After the process or user has finished reviewing or making changes to the file, control is relinquished, and the file is unlocked so it can be accessed again.  

In some cases, multiple users are allowed to access the file and make updates simultaneously. In this case, the changes are selectively merged after the file is not in use, either manually or automatically.

How to Tell If a File Is Locked?

Some applications create a temporary file while the original file is open to prevent others from editing the same file. These temporary files are usually deleted when the user or process finishes with the file and exits the program. However, if an application crashes unexpectedly or is improperly closed, the lock files can remain and prevent the program from opening again. In this case, it is necessary to find the locked file and save it properly. File locking commonly appends .lock or .lck to the file while it is locked. Searching for this can identify locked files. 

When a file is locked, a message is generated. The locked file messages vary, mostly from operating system to operating system, but can also be generated by an application. Commonly seen messages related to file locking include the following.

  • The action can’t be completed because the file is open in another program.
  • The process cannot access the file because another process has locked a portion of the file.
  • The source or destination file may be in use.
  • This virtual machine appears to be in use.
  • You must close the file before proceeding.

How to Lock a File?

Files or folders on a computer can be locked using tools that are built into the application or operating system or using external tools for file locking. The steps that need to be taken for file locking or to lock a folder vary based on the application, operating system, or external tool that is used.

When making a selection for the best tool, it is important to be clear if it is a file or a folder that needs to be locked. While the same tool might be used, how it is used and the implications vary. There are pros and cons to file locking versus locking a folder. A few considerations are as follows.

ProsCons
Lock a FolderSave time by locking multiple files in a folder at one timeUnable to directly view the contents of a locked folder
File LockingQuick to lock a single fileTakes more time because multiple files cannot be locked at one time  

How to Unlock a File?

Sometimes a file is locked without a user’s knowledge. In some cases, the operating system identifies the application or process that is using the file, and it is easy to rectify the issue. Other times, the user gets a message, such as “the folder or a file in it is open in another program,” and is left to figure out which application or process has locked the file. In a case such as this, the user cannot be sure which program it is. Sometimes it can be from a process running in the background, so it does not appear in the list of open applications and processes.

There are a number of ways to identify and unlock files, including the following.

Free programs can be downloaded and used to move, rename, or delete a locked file when it is unclear what application or process is locking it. With most of these tools, unlocking a file is as simple as just right-clicking the locked file or folder to identify the application or process that has locked the file or folder. Once it is found, the file or folder can be easily unlocked by shutting down the application or process that has caused the folder or file to be locked.  

If a file has been locked over a network because another user has it open, the person will have to close the file before it can be accessed by another user on a different computer.  

In the case of a specific error, such as a “virtual machine” error, the issue could be that an LCK file is preventing the user from taking ownership of the VM. To gain access to the VM, the user would need to delete the LCK files associated with the virtual machine in question.

Use the following steps to delete all lock files manually.

From the command line:

1. Navigate to the working directory in the terminal using cd

2. Run ls -latr to show directory listing in long format

3. Sort by timestamp and reverse, so the most recent files are at the top

4. Run rm filename to remove each lock file

5. Some software may also leave lock files in the home directory—if this is the case, the user needs to repeat steps two, three, and four in the home directory

From the file explorer:

1. Navigate to the working directory in the file explorer

2. Sort the folder to show the most recent files at the top

3. Delete all files that start with a dot or hash, or end in a .lck extension

Check all subdirectories to make sure every lock file is gone. 

The Benefit of File Locking

  • Avoid others to access and edit files or folders
  • Avoid data loss 
  • Avoid merge conflicts 
  • Better manage files, folders, and directories  
  • Improve collaboration 
  • Prevent conflicts while editing 
  • Prevent two people from opening and updating the same document or file at the same time 
  • See who is working on a file 

File Locking for Collaboration Without Headaches

File Locking is an important capability for online file access and team collaboration. Without file locking, conflicts and overwriting would eliminate the efficiencies gained with online collaboration. File locking protects the integrity of files and folders and supports the needs of distributed teams and users.   

Egnyte has experts ready to answer your questions. For more than a decade, Egnyte has helped more than 16,000 customers with millions of customers worldwide.

Last Updated: 13th April, 2023

Share this Page

Get started with Egnyte.

Request Demo