Найти отсутствующие имена файлов между 2 каталогами в Linux

Я забыл запустить update-initramfs -u после исправления подкачки в .../resume и и /etc/fstab

3
07.06.2017, 02:58
2 ответа

rsync может сделать то, что вы хотите, быстро и легко:

rsync --dry-run --verbose --recursive --existing --ignore-existing --delete-after A/ B/

Из справки:

 --existing              skip creating new files on receiver
 --ignore-existing       skip updating files that already exist on receiver
 --delete                delete extraneous files from destination dirs

Удалите опцию пробного запуска после того, как вы будете удовлетворены с предложенными результатами, чтобы фактически выполнить удаления.


В справочной странице есть более подробное описание параметров и даже упоминается ваш вариант использования:

   --existing, --ignore-non-existing
      This  tells rsync to skip creating files (including directories)
      that do not exist yet on the destination.   If  this  option  is
      combined  with  the  --ignore-existing  option, no files will be
      updated (which can be useful if all you want to do is to  delete
      extraneous files).


   --ignore-existing
      This  tells  rsync  to skip updating files that already exist on
      the destination (this does not ignore  existing  directores,  or
      nothing would get done).  See also --existing.
8
27.01.2020, 21:10

Для каталогов одного уровня

diff -u <(ls A) <(ls B) | sed -n '4,$s/^+//p' | xargs -I{} ls -l B/{}

ls -l следует изменить на rm -v после тестирования, если он делает то, что вы хотите.

rsync лучше, конечно. Но просто другой вариант.

3
27.01.2020, 21:10

Теги

Похожие вопросы