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?

5
  • 3
    which version of nano are you using? Please type nano --version
    – Michele
    Jul 25, 2017 at 9:33
  • This might be part of a known (and now resolved) bug in nano - do other text editors work with this file? You may need to upgrade your nano version to resolve depending on a the results of a nano --version. Jul 25, 2017 at 9:37
  • my nano version is 2.5.3 Jul 25, 2017 at 14:43
  • Interesting. Can you run the following to see what/who else is accessing the swap file, and copy the output here please? - vi /etc/.profile.swp. Jul 26, 2017 at 14:37
  • This swap file is only access by me to set the paths of java, hive, hadoop, pig etc. I'm able to open and edit the file using gedit, but not with nano. Jul 28, 2017 at 14:51

6 Answers 6

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

1
  • 1
    Use ls -a to see the hidden file as .[your_file].swp, next, try to remove it. Worked! Mar 23, 2021 at 3:35
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.

2
  • My nano version is 2.5.3 Jul 26, 2017 at 13:13
  • My nano version is 2.9.3 and the problem still occurs. Oct 27, 2020 at 18:53
3

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

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.

2
  • @TejasLotlikar I faced this same issue, and it got resolved by running this command. Sep 27, 2022 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 5, 2022 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.

0
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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .