42

I am getting this error while opening /etc/profile file using nano.

Error reading lock file /etc/.profile.swp: Not enough data read

How can I fix this?

Zanna
  • 70,465

6 Answers6

58

Try to remove the hidden file .[yourfilename].swp, which is stored in the same folder as the file that you are trying to open.
In your case try the shell command rm /etc/.profile.swp.

This issue also occurs with nano 2.7.4, and must be something to do with how nano handles a corrupted swapfile.

Hope this helped

storm
  • 4,973
sunwalker
  • 581
6

The problem is linked to a bug in an older version of nano as seen here.

As per the report, the affected version was nano-2.4.2. You should run nano --version to ascertain your current version and update accordingly.

A more detailed report of the actual issue can be found here.

3

Was happening for me because I was out of disk space, I cleared up some space, deleted the swap file and it worked.

Anthony
  • 131
2

Please try this one (run this on the current folder):

find . -name "*.swp" -delete

Keep in mind that as @pbhj commented:

[...] this will find all files below the current root, ending in .swp, and delete them. Which should work to remove temporary nano files, but might have unintended consequences.

  • @TejasLotlikar I faced this same issue, and it got resolved by running this command. – Arunjith R S Sep 27 '22 at 15:30
  • 1
    I mean, this will find all files below the current root, ending in .swp, and delete them. Which should work to remove temporary nano files, but might have unintended consequences. Not the highest quality answer, but a working answer to the question nonetheless. – pbhj Oct 05 '22 at 23:47
1

This happened for me because of a log file that wasn't rotating, it took the entire disk space, I solved it by truncating this log file, then removing the .swp file.

AyuMu
  • 11
0

For me this was because of running docker container logs. Worked fine after deleting them. Logs location: /var/lib/docker/containers/ rm -rf /var/lib/docker/containers/*

Note: this will delete all the log generated till today, you may choose to deleted not required and also take backup to avoid logs data loss.