Score:-1

Working Directory Spontaneously Deleted

jp flag

On Ubuntu 20.04.3 LTS, I was working in nvim in bash. I had multiple terminal tabs open. There was a .git directory in the working directory. At some point, after closing one terminal tab, I noticed that the directory I was working in does not exist any more.

I checked whether I had accidentally moved the directory by running sudo find / -name "some-file.txt" from the home directory, where some-file.txt is a filename I am sure to have been in the missing directory.

I double checked bash history, and after the last git commit and git rebase -i HEAD --root I made, only commands indicating my search for the lost directory are there. I remember in the interactive rebase I renamed the initial commit. If I did something wrong there (as in: drop all commits, for instance), this would still not explain the whole directory to be deleted.

I know, this is a very general question. But it is due to the nature of the problem that I cannot provide more details or reproduce the bug.

What could be the reason for this? (Whenever I try to rm -r a directory with a .git repository that has commits, I am asked to confirm the removal of the commits rm: remove write-protected regular file .... This does not happen when I run this command as sudo, but I am quite sure I didn't enter my password. On top of the bash history, this makes me think that I did not delete all the directory myself accidentally.)

What could I do to restore my data? I hadn't pushed, and I have managed to store the files in the open vim buffers, to answer the most obvious parts myself already.

muru avatar
us flag
It's possible you moved the directory elsewhere accidentally.
guiverc avatar
cn flag
Don't forget if you run a command with `sudo` you won't be asked for a password if you're still within the time limit of the prior *elevated command* at that terminal where a `sudo` command was used... You've not given any OS or release details which would allow a more precise response (ie. your mentioning not giving a password may not have been required for a `sudo` though there are Ubuntu products where the password is required instantly but you weren't specific)
jonathan.scholbach avatar
jp flag
@guiverc Thanks for the comment I have added the Ubunutu release now. Are there more details missing which could be helpful?
muru avatar
us flag
@jonathan.scholbach ``sudo grep "seome-file.txt" \``? Assuming you meant `/`, that searches for the string `seome-file.txt` in the `/` directory, which would still be an error unless you told `grep` to recurse. And even then it would still check the contents, not the filename. It's meaningless as a confirmation of anything.
jonathan.scholbach avatar
jp flag
@muru You are right, sorry, first I had some typos and second I was confusing `grep` and `find`. I didn't find the file with `find` either.
muru avatar
us flag
Your find command also doesn't do what you think it does
Score:0
it flag

FIND THE CAUSE:

nvim also comes with several commands (and pre-installed extensions) that can do this. If you are trying to figure out the cause of the deletion, check your nvim logs as well.

DATA RECOVERY:

You mentioned a .git directory. Did your directory have a git remote? If so, just clone it to local and problem solved.

If not check for a directory named ".trash-{$USER_ID}" if the original was on a mounted external drive, or .local/share/Trash otherwise. It may be in there (unless rm was used to delete. In that case, unless you are backing up your file system, it is probably gone.)

PROTECTING YOUR SYSTEM AGAINST THIS ISSUE:

This is why you will so often see users on here recommending frequent scheduled backups. I personally use a combination of Timeshift and rsync.

Timeshift can be downloaded via apt. It is primarily for backing up your system files and configuration, and lets you set a recurring backup schedule. You can also run manual backups in cases where you are about to do something risky.

rsync comes with Ubuntu. It is just a basic command-line tool for copying files and directories across a network (although it can do so locally as well.)

Rsync is not primarily intended as a stand-alone backup program, at least not in the way that Timeshift or Weresync are. However, it is simple and effective enough at making backups that many of the more comprehensive solutions use it internally for this purpose.

The downside of rsync is that there is no "set it and forget it" method built in. However, the Ubuntu package managers provide many more backup options, each with its own quirks.

It may be cliche at this point to recommend an aggressive backup strategy, but as you can see, it is cliche for a good reason.

jonathan.scholbach avatar
jp flag
Regarding remote repo: As I said, I had not pushed. Regarding backups: I am running backups once a week. I lost the work of a day.
Nate T avatar
it flag
Losing the work of a day still sucks, but it could have been a lot worse. As for the cause, ultimately only you have the resources to figure that out. There are a thousand different ways that data can be deleted. It could have been a rogue bg program running root or a `SIGSEGV`, for all we know. That said, I guarantee that the answer is in a log file somewhere on your system. Btw, did you check your trash-bin yet? As long as it wasn't `rm`ed (as in the system call, not the cli utility), you should be able to find it there
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.