1

I accidentally made a rsync copy of my root directory, "/" using the -a option, as follows:

user@mycomputer:~$ rsync -a / /backup-dir
user@mycomputer:~$ ls -l /backup-dir/
total 10102784
drwxrwxrwx 1 user nogroup         0 Feb  3 18:18 bin
drwxrwxrwx 1 user nogroup         0 Feb  3 18:21 dev

I am unable to delete /backup-dir/bin and /backup-dir/dev or any of the individual files within due to what I suspect to a problem with being unable to remove symlinks within those directories. (/backup-dir/bin shown below, same for /backup-dir/dev).

user@mycomputer:~$ sudo rm -rf /backup-dir/bin
rm: cannot remove ‘/backup-dir/bin’: Directory not empty
user@mycomputer:~$ ls -l /backup-dir/bin
total 16384
lr-xr-xr-x 1 user root 22 Feb  3 16:11 bzcmp -> bzdiff
lr-xr-xr-x 1 user root 22 Feb  3 16:11 bzegrep -> bzgrep
lr-xr-xr-x 1 user root 22 Feb  3 16:11 bzfgrep -> bzgrep
lr-xr-xr-x 1 user root 22 Feb  3 16:11 bzless -> bzmore
lr-xr-xr-x 1 user root 26 Feb  3 16:11 dnsdomainname -> hostname
lr-xr-xr-x 1 user root 26 Feb  3 16:11 domainname -> hostname
lr-xr-xr-x 1 user root 26 Feb  3 16:11 lessfile -> lesspipe
lr-xr-xr-x 1 user root 18 Feb  3 16:11 lsmod -> kmod
lr-xr-xr-x 1 user root 26 Feb  3 16:11 nisdomainname -> hostname
lr-xr-xr-x 1 user root 22 Feb  3 16:11 open -> openvt
lr-xr-xr-x 1 user root 18 Feb  3 16:11 rbash -> bash
lr-xr-xr-x 1 user root 18 Feb  3 16:11 rnano -> nano
lr-xr-xr-x 1 user root 18 Feb  3 16:11 sh -> dash
lr-xr-xr-x 1 user root 18 Feb  3 16:11 sh.distrib -> dash
lr-xr-xr-x 1 user root 24 Feb  3 16:11 static-sh -> busybox
lr-xr-xr-x 1 user root 26 Feb  3 16:11 ypdomainname -> hostname
user@mycomputer:~$ sudo rm /backup-dir/bin/bzcmp
user@mycomputer:~$ ls -l /backup-dir/bin
total 16384
lr-xr-xr-x 1 user root 22 Feb  3 16:11 bzcmp -> bzdiff
lr-xr-xr-x 1 user root 22 Feb  3 16:11 bzegrep -> bzgrep
lr-xr-xr-x 1 user root 22 Feb  3 16:11 bzfgrep -> bzgrep
lr-xr-xr-x 1 user root 22 Feb  3 16:11 bzless -> bzmore
lr-xr-xr-x 1 user root 26 Feb  3 16:11 dnsdomainname -> hostname
lr-xr-xr-x 1 user root 26 Feb  3 16:11 domainname -> hostname
lr-xr-xr-x 1 user root 26 Feb  3 16:11 lessfile -> lesspipe
lr-xr-xr-x 1 user root 18 Feb  3 16:11 lsmod -> kmod
lr-xr-xr-x 1 user root 26 Feb  3 16:11 nisdomainname -> hostname
lr-xr-xr-x 1 user root 22 Feb  3 16:11 open -> openvt
lr-xr-xr-x 1 user root 18 Feb  3 16:11 rbash -> bash
lr-xr-xr-x 1 user root 18 Feb  3 16:11 rnano -> nano
lr-xr-xr-x 1 user root 18 Feb  3 16:11 sh -> dash
lr-xr-xr-x 1 user root 18 Feb  3 16:11 sh.distrib -> dash
lr-xr-xr-x 1 user root 24 Feb  3 16:11 static-sh -> busybox
lr-xr-xr-x 1 user root 26 Feb  3 16:11 ypdomainname -> hostname

I was also unable to chmod permissions within /backup-dir/bin, in case that matters.

UPDATE: This leads me in the right direction: https://unix.stackexchange.com/a/33594

user@mycomputer:~$ sudo strace rm -f /backup-dir/bin/bzcmp
... (long message, which includes the following)...
unlinkat(AT_FDCWD, "bin/bzcmp", 0)      = 0

The attempts to unlink the files are unsuccessful. The link above suggests deleting by inode. However, I want to preserve the inodes for the original files located in /bin. I only want to remove the symbolic links in order to remove /backup-dir/bin/ and /backup-dir/dev/.

Suggestions for how to remove /backup-dir/bin and /backup-dir/dev are appreciated.

  • Rsync created it, maybe rsync can delete it too: mkdir empty; rsync -a --delete empty/. /backup-dir/bin/. and execute as the same user as the one that created it. – PBI Feb 5 '16 at 9:02
0

If nothing else worked (strange) I suggest you to use again rsync

mkdir empty_dir
sudo rsync -a --delete empty_dir/    /backup-dir/bin/

Source:

  • +1 for the references. Unsuccessful, however. For /backup-dir/bin/, same as OP, symlinks still persist, unable to delete due to directory not empty. For /backup-dir/dev/, cannot delete non-empty directory: snd/by-path cannot delete non-empty directory: <others> <-- emphasis mine – bpg Feb 5 '16 at 18:18

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.