Nicolas Kovacs
2018-Sep-17 09:05 UTC
[CentOS] Very weird problem with handling symbolic links
Hi everyone, I just discovered something very weird on a vanilla CentOS 7 installation. If I create a link to /tmp as a normal user, it looks like I can't remove this link anymore. Here's what this looks like: $ mkdir test_link $ cd test_link/ $ ln -s /tmp/ link_to_tmp $ ls -l total 0 lrwxrwxrwx. 1 kikinovak kikinovak 5 Sep 17 10:56 link_to_tmp -> /tmp/ $ rm link_to_tmp/ rm: cannot remove ?link_to_tmp/?: Is a directory $ rmdir link_to_tmp/ rmdir: failed to remove ?link_to_tmp/?: Not a directory I tried the same thing on a different box, running Slackware 14.2, and I can remove my symbolic link without any hassle. I sense something is very wrong here. Any suggestions? Niki -- Microlinux - Solutions informatiques durables 7, place de l'?glise - 30730 Montpezat Site : https://www.microlinux.fr Blog : https://blog.microlinux.fr Mail : info at microlinux.fr T?l. : 04 66 63 10 32
Nicolas Kovacs
2018-Sep-17 09:11 UTC
[CentOS] Very weird problem with handling symbolic links
Le 17/09/2018 ? 11:05, Nicolas Kovacs a ?crit?:> $ mkdir test_link > $ cd test_link/ > $ ln -s /tmp/ link_to_tmp > $ ls -l > total 0 > lrwxrwxrwx. 1 kikinovak kikinovak 5 Sep 17 10:56 link_to_tmp -> /tmp/ > $ rm link_to_tmp/ > rm: cannot remove ?link_to_tmp/?: Is a directory > $ rmdir link_to_tmp/ > rmdir: failed to remove ?link_to_tmp/?: Not a directoryI'll answer that myself, since I just found the culprit. The trailing slash in `link_to_tmp/` caused the problem. $ rm link_to_tmp <-- works perfectly This must be one of those rare occasions where tab completion does *not* come in handy. Cheers, Niki -- Microlinux - Solutions informatiques durables 7, place de l'?glise - 30730 Montpezat Site : https://www.microlinux.fr Blog : https://blog.microlinux.fr Mail : info at microlinux.fr T?l. : 04 66 63 10 32
> > $ mkdir test_link > $ cd test_link/ > $ ln -s /tmp/ link_to_tmp > $ ls -l > total 0 > lrwxrwxrwx. 1 kikinovak kikinovak 5 Sep 17 10:56 link_to_tmp -> /tmp/ > $ rm link_to_tmp/ > rm: cannot remove ?link_to_tmp/?: Is a directory > $ rmdir link_to_tmp/ > rmdir: failed to remove ?link_to_tmp/?: Not a directory > > I tried the same thing on a different box, running Slackware 14.2, and I > can remove my symbolic link without any hassle. > > I sense something is very wrong here. Any suggestions? >Yeah, it's just one of the oddities of symlinks. Try doing the rm command without the trailing slash. A symlink isn't a directory, it's an entry that links to a directory - but if you put the trailing slash, rm thinks it is a directory so won't touch it. I think it depends on at what stage the symlink is dereferenced in the rm command. Presumably the rmdir command checks the filetype before doing anything. I came across this when using tab completion - that puts the extra slash on the end when encountering a directory and it caused me to go looking for the answer. P.
Possibly Parallel Threads
- Apache: confusion about virtual hosts and DNS on a local network
- Broadcom wireless card: installation script for Linux-STA driver
- Remote Git vs. GNOME on CentOS 6.6: cannot open display
- Hi again & problem with minimal CentOS and Github
- Facebook CentOS group close to 15.000 members!