I have a not-quite-folder not-quite-file on my file system. It is an AWS EC2 instance running Ubuntu 18.04.4 LTS.
I have a script that runs nightly that picks up a file (/ebsvol/dead-drop/sync) and moves it to (/ebsvol/dead-drop/sync) using Robo, which in turn is using Symfony’s Filesystem rename() method (https://symfony.com/doc/current/components/filesystem.html#rename).
const CANARY_PATH = '/ebsvol/dead-drop/sync'; const CANARY_WORKING_PATH = '/ebsvol/dead-drop/~sync'; ... $this->taskFilesystemStack() ->rename(self::CANARY_PATH, self::CANARY_WORKING_PATH) ->run();
Something is going awry in the script or with this code, though that’s not really why I’m here. The result and cleanup is why I’m here. 🙂
The result is that the ~sync "file" is created, however it is actually… a hard link to /bin? This is where things get fishy. My
ls -ial looks like this:
3276803 -rw-rw-r-- 1 configbot configbot 125 Jul 4 00:30 '~sync'
So it’s just a text file, so let’s try cat…
$ cat ~sync cat: /bin: Is a directory
$ cd ~sync
…changes my prompt to /bin, and doing an ls, it’s surely bin. Incidentally,
ls -ial on my root volume shows that /bin is iNode 12.
This has happened to me once in the past, and I just did
rm -rf ~sync which hosed my entire server and I had to rebuild. So I’m trying to avoid that.
How do I get rid of this weird ~sync file/folder/symlink/hardlink without trashing /bin?
Some additional info:
/ebsvolis a separate EBS volume than
/(i.e. separate hard drives/partitions!)
- I think if it’s a hard link in some weird way,
rm ~syncmight work. But wouldn’t it show identical iNode numbers?
- I will take a snapshot of both volumes before I attempt anything. 🙂
It’s a very bad idea to name a file beginning with a tilde if you intend to access it with a shell like bash. The reason being that it interprets the tilde as meaning that you want to access a user’s home directory.
Thus, bash (and other shells) expand
~ to the current user’s home directory, and expand
~sync to the home directory of the user named sync.
It turns out that your Ubuntu system has a system user named
sync whose home directory is
/bin. Thus when you try to access
~sync from the shell, it expands this to the user’s home directory, and you start getting odd messages. And when you ran
rm -rf ~sync the effect was
rm -rf /bin, which pretty much trashes the system.
If you want to access the file itself, either quote it, or prefix it with something, such as its path:
$ cat ./~sync
You should also rework your code so that it does not create filenames that start with a tilde. This will save you and future you a lot of headaches later.
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.