29

To the best of my knowledge, I can view /var/log/syslog with the command

sudo nano /var/log/syslog

and successfully did so several times during a session; however, I was trying to search the log for keywords and apparently entered some 'unknown commands' by mistake. The terminal froze, so I killed it to try starting over.

Now, when I issue the command above, I get what appears to be a blank file with the prompt at the bottom of the terminal window:

File /var/log/syslog is being edited (by root using Nano 2.4.2) CONT

with options, Yes, No and Cancel.

Why is this happening? Have I screwed up my syslog file? If so, how dire is that?

munr0
  • 291
  • 1
  • 3
  • 5
  • 1
    When the terminal appears frozen, sometimes this happens because `ctrl-s` was pressed which causes the display to stop updating. To recover from that, press `ctrl-q`. Also, if you don't intend on editing a file, consider using something like `less` instead of an editor so you don't inadvertently make changes. – Pooping Feb 05 '16 at 23:06
  • why are you opening a log file with nano? Are you planning to edit the file? – lacostenycoder Feb 14 '23 at 14:14

1 Answers1

35

If the option "vim-style lock-files" is enables (set locking in nanorc), which is the case by default, nano creates a special so called "lock file" while you edit a file to indicate that the file is currently edited.

Normally this file is removed when nano is closed, but that doesn't happen if you kill it by closing the terminal.

Just remove the file

/var/log/.syslog.swp
Florian Diesch
  • 86,013
  • 17
  • 224
  • 214
  • 13
    Also faster hitting Y and CTRL+X; the lock is replaced by the new instance and removed upon CTRL+X. – kos Feb 05 '16 at 20:50
  • Fantastic! This worked perfectly. Thanks, Florian Diesch! – munr0 Feb 05 '16 at 21:03
  • 1
    Can't find that `.syslog.swp` file as of `Ubuntu 16.04.1 LTS`. – Frank N Sep 26 '16 at 07:21
  • 9
    For Ubuntu 16.04 LTS the nano lock file, as explained by Florian Diesch, is located in the path of the file being edited and takes the hidden name of the file with the suffix .swp. > Thus if editing /path/to/file, the corresponding lock file is /path/to/.file.swp. Delete the .file.swp to release the lock – user2972154 Oct 29 '16 at 18:20
  • one method to delete the .swp file is to use 'sudo find /path/to/.filename.swp -type f -delete' – Patrick Oct 18 '17 at 11:44
  • linux sucks, why such problems? I closed all terminal windows, where is it still used? – user25 Mar 17 '18 at 19:47
  • no such file: `sudo rm $HOME/.bashrc.swp`, and can't still access `nano $HOME/.bashrc` **File .../.bashrc is being edited (by root with nano 2.5.3, PID 24112); continue** – user25 Mar 17 '18 at 19:49
  • Also say _"...with nano 2.5.3, **PID 18017**"_. Where did it get that PID? Is not on hidden swp file. Sometimes it doesn't exist. – Pablo Bianchi Sep 19 '18 at 03:32
  • @kos, you should really make your comment an answer! It's the only reasonable thing to do! – Bobort Mar 05 '20 at 20:45
  • @kos I am late to this question but, your comment solved my problem. The file this answer refers to, didn't exist for me. – steveb Dec 14 '20 at 18:14