2

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.

1
  • 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
    Commented Feb 5, 2016 at 9:02

1 Answer 1

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
  • +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
    Commented Feb 5, 2016 at 18:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .